Commit 5bd29cf5 authored by Patrick's avatar Patrick

Use of django-angular==0.8.4

parent 2355f475
This diff is collapsed.
......@@ -3,13 +3,12 @@
{% block sub_content %}
{% if update == "Ok" %}<p class="bg-success" style="color: #cec7c7"><strong>{% trans "Update done." %}</strong></p>{% endif %}
{% if update == "Nok" %}<div class="has-error"><span class="help-block"><strong>{% trans "Update not done." %}</strong></span></div>{% endif %}
<p>{% trans "All informations bellow are visible to all members except your phone and email. You have the choice to specify if your phone and/or mail are visible to others members." %}</p>
<p>{% if membership_fee_valid_until %}<i>{% trans "Your membership fee is valid until" %} : <u>{{ membership_fee_valid_until }}</u></i>{% endif %}</p>
<form name="{{ form.form_name }}" method="post" action="." validate>
{% csrf_token %}
<div class="form-group"><button type="submit" ng-disabled="{{ form.form_name }}.$invalid" class="btn btn-primary pull-right">{% trans "Update" %}</button></div>
{% trans "All informations bellow are visible to all members except your phone and email. You have the choice to specify if your phone and/or mail are visible to others members." %}
<p>{% if membership_fee_valid_until %}<i>{% trans "Your membership fee is valid until" %} : <u>{{ membership_fee_valid_until }}</u></i>{% endif %}</p>
{{ form.as_div }}
<div class="form-group"><label class="control-label">&nbsp;</label></div>
<div class="form-group"><button type="submit" ng-disabled="{{ form.form_name }}.$invalid" class="btn btn-primary">{% trans "Update" %}</button></div>
</form>
{% addtoblock "css" %}{{ form.media.css }}{% endaddtoblock %}
{% addtoblock "jshead" %}{{ form.media.js }}{% endaddtoblock %}
......
{% extends 'cms_subpage.html' %}
{% load cms_tags sekizai_tags i18n l10n %}
{% block sub_content %}
{% if coordinator %}
<div class="bg-danger">
<blockquote><small>
{% trans "This message will be send to all members as coordinator." %}
</small></blockquote>
</div>
{% else %}
{% trans "This message will be send only to members who accept to show they email." %}
{% endif %}
{% if update == '2' %}<p class="bg-success">{% trans "The mail has been send" %}</p>{% endif %}
<form name="{{ form.form_name }}" method="post" action="." validate>
{% csrf_token %}
{% if update != '2' %}
<div class="form-group"><button type="submit" ng-disabled="{{ form.form_name }}.$invalid" class="btn btn-primary pull-right">{% trans "Send e-mail" %}</button></div>
{% endif %}
{% if coordinator %}
<div class="bg-danger">
<blockquote><small>
{% trans "This message will be send to all members as coordinator." %}
</small></blockquote>
</div>
{% else %}
{% trans "This message will be send only to members who accept to show they email." %}
{% endif %}
{{ form.as_div }}
<div class="form-group"><button type="submit" ng-disabled="{{ form.form_name }}.$invalid" class="btn btn-primary">{% trans "Send e-mail" %}</button></div>
</form>
{% addtoblock "css" %}{{ form.media.css }}{% endaddtoblock %}
{% addtoblock "jshead" %}{{ form.media.js }}{% endaddtoblock %}
......
{% extends 'cms_subpage.html' %}
{% load cms_tags sekizai_tags i18n l10n %}
{% block sub_content %}
{% if update %}<p class="bg-danger">{% trans "Which coordinator(s) have you selected ?" %}</p>{% endif %}
<p><b>{% trans "This message will be send only to coordinators you have selected." %}</b></p>
{% if update == '1' %}<p class="bg-danger">{% trans "Which coordinator(s) have you selected ?" %}</p>{% endif %}
{% if update == '2' %}<p class="bg-success">{% trans "The mail has been send" %}</p>{% endif %}
<form name="{{ form.form_name }}" method="post" action="." validate>
{% csrf_token %}
{% if update != '2' %}
<div class="form-group"><button type="submit" ng-disabled="{{ form.form_name }}.$invalid" class="btn btn-primary pull-right">{% trans "Send e-mail" %}</button></div>
{% endif %}
<b>{% trans "This message will be send only to coordinators you have selected." %}</b><p></p>
{{ form.as_div }}
<div class="form-group"><button type="submit" ng-disabled="{{ form.form_name }}.$invalid" class="btn btn-primary">{% trans "Send e-mail" %}</button></div>
</form>
{% addtoblock "css" %}{{ form.media.css }}{% endaddtoblock %}
{% addtoblock "jshead" %}{{ form.media.js }}{% endaddtoblock %}
......
......@@ -11,7 +11,6 @@ from django.contrib.auth.models import User
from django.contrib.sites.shortcuts import get_current_site
from django.core.mail import EmailMultiAlternatives
from django.db.models import Q, F
from django.forms import Textarea
from django.template import loader
from django.utils import timezone
from django.utils import translation
......@@ -152,6 +151,7 @@ class AuthRepanierSetPasswordForm(SetPasswordForm):
class RepanierForm(Bootstrap3Form):
form_name = 'repanier_form'
required_css_class = 'djng-field-required'
class Media:
......
......@@ -67,7 +67,9 @@ def send_mail_to_all_members_view(request):
bcc=to_email_customer
)
send_email(email=email)
return HttpResponseRedirect('/') # Redirect after POST
# return HttpResponseRedirect('/') # Redirect after POST
return render(request, "repanier/send_mail_to_all_members.html",
{'form': form, 'update': '2'})
else:
form = MembersContactValidationForm() # An unbound form
email = form.fields["your_email"]
......
......@@ -8,7 +8,9 @@ from django.core.mail import EmailMessage
from django.http import Http404
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.utils import translation
from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
......@@ -23,7 +25,7 @@ from repanier.models import Staff
from repanier.tools import send_email
from repanier.views.forms import RepanierForm
from repanier.widget.checkbox_select_multiple import CheckboxSelectMultipleWidget
from repanier.widget.checkbox import CheckboxWidget
# from repanier.widget.checkbox import CheckboxWidget
class DjngBooleanField(BooleanFieldMixin, forms.BooleanField):
......@@ -43,37 +45,40 @@ class DjngMultipleChoiceField(MultipleChoiceFieldMixin, forms.MultipleChoiceFiel
class CoordinatorsContactForm(RepanierForm):
# team1 = forms.MultipleChoiceField(
# label=_("Management team"),
# choices=(('1', 'un'), ('2', 'deux'), ('3', 'trois')),
# widget=CheckboxSelectMultiple()
# )
staff = DjngMultipleChoiceField(
label=EMPTY_STRING,
choices=[],
widget=CheckboxSelectMultipleWidget()
)
your_email = DjngEmailField(label=_('Your Email'))
subject = DjngCharField(label=_('Subject'), max_length=100)
message = DjngCharField(label=_('Message'), widget=forms.Textarea)
def __init__(self, *args, **kwargs):
super(CoordinatorsContactForm, self).__init__(*args, **kwargs)
choices = []
for staff in Staff.objects.filter(is_active=True, is_contributor=False):
for staff in Staff.objects.filter(
is_active=True, is_contributor=False,
translations__language_code=translation.get_language()
).order_by(
'translations__long_name',
'customer_responsible__long_basket_name'
):
r = staff.customer_responsible
if r is not None:
try:
sender_function = staff.long_name
except TranslationDoesNotExist:
sender_function = EMPTY_STRING
if r.long_basket_name is not None:
signature = "%s : %s" % (sender_function, r.long_basket_name)
else:
signature = "%s :%s" % (sender_function, r.short_basket_name)
self.fields["staff_%d" % staff.id] = DjngBooleanField(label=EMPTY_STRING, required=False)
self.fields["staff_%d" % staff.id].widget = CheckboxWidget(label=signature)
# choices.append(("staff_%d" % staff.id, signature))
# self.fields["staff"] = DjngMultipleChoiceField(
# label=_("This message will be send only to coordinators you have selected."),
# choices=choices,
# widget=CheckboxSelectMultipleWidget()
# )
self.fields["your_email"] = DjngEmailField(label=_('Your Email'))
self.fields["subject"] = DjngCharField(label=_('Subject'), max_length=100)
self.fields["message"] = DjngCharField(label=_('Message'), widget=forms.Textarea)
phone = " (%s)" % r.phone1 if r.phone1 else EMPTY_STRING
name = r.long_basket_name if r.long_basket_name else r.short_basket_name
signature = "<b>%s</b> : %s%s" % (sender_function, name, phone)
choices.append(("%d" % staff.id, mark_safe(signature)))
self.fields["staff"] = DjngMultipleChoiceField(
label=EMPTY_STRING,
choices=choices,
widget=CheckboxSelectMultipleWidget()
)
class CoordinatorsContactValidationForm(NgFormValidationMixin, CoordinatorsContactForm):
......@@ -87,17 +92,14 @@ def send_mail_to_coordinators_view(request):
if request.user.is_staff:
raise Http404
if request.method == 'POST':
print('---------------')
print(request.POST)
form = CoordinatorsContactValidationForm(request.POST)
# request.POST = form.data
if form.is_valid():
print('valide')
to_email_staff = []
for staff in Staff.objects.filter(is_active=True, is_contributor=False).order_by('?'):
if form.cleaned_data.get('staff_%d' % staff.id):
to_email_staff.append(staff.user.email)
selected_staff_members = form.cleaned_data.get('staff')
for staff in Staff.objects.filter(is_active=True, is_contributor=False, id__in=selected_staff_members).order_by('?'):
to_email_staff.append(staff.user.email)
print(to_email_staff)
if len(to_email_staff) > 0:
to_email_customer = [request.user.email]
email = EmailMessage(
......@@ -107,8 +109,10 @@ def send_mail_to_coordinators_view(request):
to=to_email_customer,
cc=to_email_staff
)
# send_email(email=email)
return HttpResponseRedirect('/')
send_email(email=email)
# return HttpResponseRedirect('/')
return render(request, "repanier/send_mail_to_coordinators.html",
{'form': form, 'update': '2'})
else:
return render(request, "repanier/send_mail_to_coordinators.html",
{'form': form, 'update': '1'})
......
......@@ -4,6 +4,7 @@ from __future__ import unicode_literals
from django.contrib.auth.decorators import login_required
from django.db.models import Q
from django.shortcuts import render
from django.utils import translation
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
......@@ -19,8 +20,13 @@ def who_is_who_view(request):
"long_basket_name")
if q is not None:
customer_list = customer_list.filter(Q(long_basket_name__icontains=q) | Q(city__icontains=q))
staff_list = Staff.objects.filter(is_active=True, is_contributor=False).order_by(
"customer_responsible__long_basket_name")
staff_list = Staff.objects.filter(
is_active=True, is_contributor=False,
translations__language_code=translation.get_language()
).order_by(
'translations__long_name',
'customer_responsible__long_basket_name'
)
is_coordinator = request.user.is_superuser or request.user.is_staff or Staff.objects.filter(
customer_responsible_id=request.user.customer.id, is_coordinator=True, is_active=True
).order_by('?').first() is not None
......
# -*- coding: utf-8
from __future__ import unicode_literals
import json
from django.utils.encoding import force_text
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from djng.forms.widgets import (
ChoiceFieldRenderer as DjngChoiceFieldRenderer, CheckboxChoiceInput as DjngCheckboxChoiceInput,
CheckboxFieldRendererMixin, CheckboxSelectMultiple as DjngCheckboxSelectMultiple)
CheckboxSelectMultiple as DjngCheckboxSelectMultiple)
class ChoiceFieldRenderer(DjngChoiceFieldRenderer):
......@@ -22,6 +23,16 @@ class ChoiceFieldRenderer(DjngChoiceFieldRenderer):
return mark_safe('\n'.join(output))
class CheckboxFieldRendererMixin(object):
def __init__(self, name, value, attrs, choices):
attrs.pop('djng-error', None)
self.field_attrs = [format_html('ng-form="{0}"', name)]
if attrs.pop('multiple_checkbox_required', False):
field_names = [format_html('{0}.{1}', name, choice) for choice, dummy in choices]
self.field_attrs.append(format_html('validate-multiple-fields="{0}"', json.dumps(field_names)))
super(CheckboxFieldRendererMixin, self).__init__(name, value, attrs, choices)
class CheckboxInlineChoiceInput(DjngCheckboxChoiceInput):
def render(self, name=None, value=None, attrs=None, choices=()):
label_attrs = ['class="checkbox-inline"']
......@@ -43,6 +54,7 @@ class CheckboxInlineChoiceInput(DjngCheckboxChoiceInput):
)
return mark_safe(output)
class CheckboxInlineFieldRenderer(CheckboxFieldRendererMixin, ChoiceFieldRenderer):
choice_input_class = CheckboxInlineChoiceInput
......@@ -50,6 +62,13 @@ class CheckboxInlineFieldRenderer(CheckboxFieldRendererMixin, ChoiceFieldRendere
class CheckboxSelectMultipleWidget(DjngCheckboxSelectMultiple):
renderer = CheckboxInlineFieldRenderer
def value_from_datadict(self, data, files, name):
"""
Given a dictionary of data and this widget's name, returns the value
of this widget. Returns None if it's not provided.
"""
return dict(data.iterlists())[name]
class Media:
css = {
'all': ('css/checkbox_widget.css',)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment