Commit da328efe authored by Patrick's avatar Patrick

Work in progress

parent c2f38c51
......@@ -56,7 +56,8 @@ class ConfigurationAdmin(TranslatableAdmin):
'display_producer_on_order_form',
'customers_must_confirm_orders',
('bank_account', 'max_week_wo_participation'),
('membership_fee', 'membership_fee_duration')),
('membership_fee', 'membership_fee_duration'),
'how_to_register'),
}),
]
if Producer.objects.filter(producer_pre_opening=True).order_by('?').only('id').exists():
......
This diff is collapsed.
......@@ -101,6 +101,14 @@ class Configuration(TranslatableModel):
max_length=100,
default=EMPTY_STRING,
blank=True),
how_to_register=HTMLField(_("how to register"),
help_text=EMPTY_STRING,
configuration='CKEDITOR_SETTINGS_MODEL2',
default=
"""
Pour créer un compte et passer commande, veuillez contacter ....
""",
blank=False),
offer_customer_mail=HTMLField(_("offer customer mail"),
help_text=EMPTY_STRING,
configuration='CKEDITOR_SETTINGS_MODEL2',
......
......@@ -116,19 +116,13 @@ class Customer(models.Model):
get_admin_date_balance.allow_tags = False
def get_admin_date_joined(self):
if self.user is not None:
return self.user.date_joined.strftime(settings.DJANGO_SETTINGS_DATE)
else:
return EMPTY_STRING
return self.user.date_joined.strftime(settings.DJANGO_SETTINGS_DATE)
get_admin_date_joined.short_description = _("date joined")
get_admin_date_joined.allow_tags = False
def get_admin_balance(self):
if self.id is not None:
return self.balance + self.get_bank_not_invoiced() - self.get_order_not_invoiced()
else:
return REPANIER_MONEY_ZERO
return self.balance + self.get_bank_not_invoiced() - self.get_order_not_invoiced()
get_admin_balance.short_description = (_("balance"))
get_admin_balance.allow_tags = False
......@@ -196,27 +190,23 @@ class Customer(models.Model):
get_balance.admin_order_field = 'balance'
def get_last_membership_fee(self):
if self.id is not None:
last_membership_fee = purchase.Purchase.objects.filter(
customer_id=self.id,
offer_item__order_unit=PRODUCT_ORDER_UNIT_MEMBERSHIP_FEE
).order_by("-id")
if last_membership_fee.exists():
return last_membership_fee.first().selling_price
return REPANIER_MONEY_ZERO
last_membership_fee = purchase.Purchase.objects.filter(
customer_id=self.id,
offer_item__order_unit=PRODUCT_ORDER_UNIT_MEMBERSHIP_FEE
).order_by("-id")
if last_membership_fee.exists():
return last_membership_fee.first().selling_price
get_last_membership_fee.short_description = _("last membership fee")
get_last_membership_fee.allow_tags = False
def last_membership_fee_date(self):
if self.id is not None:
last_membership_fee = purchase.Purchase.objects.filter(
customer_id=self.id,
offer_item__order_unit=PRODUCT_ORDER_UNIT_MEMBERSHIP_FEE
).order_by("-id").prefetch_related("customer_invoice")
if last_membership_fee.exists():
return last_membership_fee.first().customer_invoice.date_balance
return
last_membership_fee = purchase.Purchase.objects.filter(
customer_id=self.id,
offer_item__order_unit=PRODUCT_ORDER_UNIT_MEMBERSHIP_FEE
).order_by("-id").prefetch_related("customer_invoice")
if last_membership_fee.exists():
return last_membership_fee.first().customer_invoice.date_balance
last_membership_fee_date.short_description = _("last membership fee date")
last_membership_fee_date.allow_tags = False
......@@ -227,35 +217,31 @@ class Customer(models.Model):
last_membership_fee_date = self.last_membership_fee_date()
if last_membership_fee_date is not None:
return last_membership_fee_date.strftime(settings.DJANGO_SETTINGS_DATE)
return
return EMPTY_STRING
get_last_membership_fee_date.short_description = _("last membership fee date")
get_last_membership_fee_date.allow_tags = False
def get_participation(self):
if self.id is not None:
now = timezone.now()
return permanenceboard.PermanenceBoard.objects.filter(
customer_id=self.id,
permanence_date__gte=now - datetime.timedelta(
days=365),
permanence_date__lt=now,
permanence_role__is_counted_as_participation=True
).order_by('?').count()
return DECIMAL_ZERO
now = timezone.now()
return permanenceboard.PermanenceBoard.objects.filter(
customer_id=self.id,
permanence_date__gte=now - datetime.timedelta(
days=365),
permanence_date__lt=now,
permanence_role__is_counted_as_participation=True
).order_by('?').count()
get_participation.short_description = _("participation")
get_participation.allow_tags = False
def get_purchase(self):
if self.id is not None:
now = timezone.now()
return invoice.CustomerInvoice.objects.filter(
customer_id=self.id,
total_price_with_tax__gt=DECIMAL_ZERO,
date_balance__gte=now - datetime.timedelta(365)
).count()
return DECIMAL_ZERO
now = timezone.now()
return invoice.CustomerInvoice.objects.filter(
customer_id=self.id,
total_price_with_tax__gt=DECIMAL_ZERO,
date_balance__gte=now - datetime.timedelta(365)
).count()
get_purchase.short_description = _("purchase")
get_purchase.allow_tags = False
......
{% extends 'cms_page.html' %}
{% load cms_tags sekizai_tags i18n l10n thumbnail filer_tags filer_image_tags %}
{% block sub_content %}
{#<div class="container-repanier">#}
{#<div class="container">#}
{% if is_anonymous %}
{% if is_anonymous %}
<div class="row">
<div class="panel panel-danger">
<div class="panel-heading">
<a href="{% url "login_form" %}?next={% url 'order_delivery_view' permanence.id delivery_id %}" class="btn btn-primary">{% trans "Login me" %}</a>
<div class="panel-group">
<div class="panel panel-primary">
<div class="panel-body">
<div class="col-xs-3">
<a href="{% url "login_form" %}?next={% url 'order_delivery_view' permanence.id delivery_id %}" class="btn btn-primary">{% trans "Login me" %}</a>
</div>
<div class="col-xs-9">
<div class="accordion-toggle collapsed" data-toggle="collapse" data-target="#collapse">
<span class="btn btn-primary">{% trans "Create an account" %}</span>
</div>
<div id="collapse" class="panel-collapse collapse">
{{ how_to_register }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% elif not may_order%}
{% elif not may_order%}
<div class="row">
<div class="panel panel-danger">
<div class="panel-heading">
......@@ -19,7 +29,7 @@
</div>
</div>
</div>
{% else %} {# not is_anonymous and may_order#}
{% else %} {# not is_anonymous and may_order#}
<div class="row">
<div class="panel panel-default">
{% if permanence.offer_description and permanence.offer_description.strip %}
......@@ -60,7 +70,7 @@
<span id="span_btn_confirm_order"></span>
{% endif %}
{% endif %}
{% endif %} {# not is_anonymous and may_order#}
{% endif %} {# not is_anonymous and may_order#}
{% if not is_anonymous or display_anonymous_order_form %}
<div class="row">
<nav class="col-xs-12 col-sm-3 hidden-xs bs-docs-sidebar">
......@@ -154,7 +164,7 @@
{{ offer.cache_part_a | safe }}
</div>
<div class="col-sm-6 col-lg-3" data-id="{{ offer.id|unlocalize }}" data-product="{{ offer.get_long_name }}">
{% if offer.may_order %}<select name="offer_item{{ offer.id|unlocalize }}" id="offer_item{{ offer.id|unlocalize }}" onchange="order_ajax({{ offer.id|unlocalize }})" class="form-control"></select>{% endif %}
{% if offer.may_order %}<select name="offer_item{{ offer.id|unlocalize }}" id="offer_item{{ offer.id|unlocalize }}" {% if is_anonymous %}disabled{% else %}onchange="order_ajax({{ offer.id|unlocalize }})"{% endif %} class="form-control"></select>{% endif %}
<span id="box_offer_item{{ offer.id|unlocalize }}"></span>
{{ offer.cache_part_b | safe }}
{% if not offer.is_box %}<br/><span class="btn_like{{ offer.id|unlocalize }}" style="cursor: pointer;"></span>{% endif %}
......@@ -275,8 +285,6 @@
</div>
</div>
{% endif %} {# not is_anonymous or display_anonymous_order_form #}
{#</div>#}
{#</div>#}
{% endblock %}
{% block footer %}
<div class="visible-xs">
......@@ -466,6 +474,7 @@
});
}
$(document).ready(function () {
{% if not is_anonymous %}
var lien = '{% url 'order_init_ajax' %}?{% for offer in offeritem_list %}oi={{ offer.id|unlocalize }}&{% endfor %}pe={{ permanence.id|unlocalize }}{% if delivery_id > 0 %}&de={{ delivery_id|unlocalize }}{% endif %}{% if communication %}&co={{ communication }}{% endif %}{% if basket %}&ba={{ basket }}{% endif %}';
$.ajax({
url: lien,
......@@ -529,6 +538,7 @@
});
}
});
{% endif %}
$('#orderModal').modal({
keyboard: true,
backdrop: false,
......
......@@ -7,43 +7,59 @@
<div class="modal-header">
<h4 class="modal-title" id="loginModalLabel">{% trans "Login" %}</h4>
</div>
<div class="modal-body">
{# <div class="modal-body">#}
<form role="form" action="{{ app_path }}" method="post" accept-charset="UTF-8" id="login-form">{% csrf_token %}
<div class="modal-body">
{#<div class="row">#}
<div class="form-group">
{% if form.non_field_errors %}
<p class="bg-danger">
{% for error in form.non_field_errors %}
{{ error }}
{% endfor %}
</p>
{% endif %}
<label for="id_username">{% trans "Username" %}</label>
{% if form.username.errors %}
<p class="bg-danger">
{% for error in form.username.errors %}
{{ error }}
{% endfor %}
</p>
{% endif %}
<input type="text" class="form-control" id="id_username" placeholder="{% trans "Username" %}" name="username">
<br/>
<label for="id_password">{% trans "Password" %}</label>
{% if form.password.errors %}
<p class="bg-danger">
{% for error in form.password.errors %}
{{ error }}
{% endfor %}
</p>
{% endif %}
<input type="password" class="form-control" id="id_password" placeholder="{% trans "Password" %}" name="password">
<input type="hidden" name="this_is_the_login_form" value="1" />
<input type="hidden" name="next" value="{{ next }}" />
{% if form.non_field_errors %}
<p class="bg-danger">
{% for error in form.non_field_errors %}
{{ error }}
{% endfor %}
</p>
{% endif %}
<label for="id_username">{% trans "Username" %}</label>
{% if form.username.errors %}
<p class="bg-danger">
{% for error in form.username.errors %}
{{ error }}
{% endfor %}
</p>
{% endif %}
<input type="text" class="form-control" id="id_username" placeholder="{% trans "Username" %}" name="username">
<br/>
<label for="id_password">{% trans "Password" %}</label>
{% if form.password.errors %}
<p class="bg-danger">
{% for error in form.password.errors %}
{{ error }}
{% endfor %}
</p>
{% endif %}
<input type="password" class="form-control" id="id_password" placeholder="{% trans "Password" %}" name="password">
<input type="hidden" name="this_is_the_login_form" value="1" />
<input type="hidden" name="next" value="{{ next }}" />
</div>
<button class="btn btn-primary" type="submit">{% trans "Login" %}</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="{% url "admin_password_reset" %}" style="color : inherit;">{% trans "Password reset" %}</a>
<p></p>
<div class="form-group">
<div class="accordion-toggle collapsed" data-toggle="collapse" data-target="#collapse">
<span class="btn btn-primary">{% trans "Create an account" %}</span>
</div>
<div id="collapse" class="panel-collapse collapse">
{{ how_to_register }}
</div>
</div>
</div>
<div class="modal-footer">
<div class="form-group">
<button class="btn btn-primary" type="submit">{% trans "Login" %}</button>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="{% url "admin_password_reset" %}" class="btn btn-primary">{% trans "Password reset" %}</a>
</div>
</div>
</form>
</div><!-- /form -->
{# </div><!-- /form -->#}
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
<script type="text/javascript">
......
......@@ -30,7 +30,7 @@
<br/>
{% endfor %}
<br/>
<p>{% trans "If you want to show information about you, then" %} <a href="{% url 'me_view' %}">{% trans "update your profil" %}</a>.</p>
<p>{% trans "If you want to show information about you, then" %} <a href="{% url 'my_profile_view' %}">{% trans "update your profil" %}</a>.</p>
<div class="panel-group" id="accordion">
{% if coordinator %}
<div class="bg-danger">
......
......@@ -1083,7 +1083,7 @@ def my_basket(is_order_confirm_send, order_amount, to_json):
msg_html = '<span class="glyphicon glyphicon-shopping-cart"></span> %s&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-exclamation-sign"></span>&nbsp;<span class="glyphicon glyphicon-floppy-remove"></span></a>' % (
order_amount,)
else:
msg_html = '<span class="glyphicon glyphicon-shopping-cart"></span> %s&nbsp;&nbsp;&nbsp;<font color="#32CD32"><span class="glyphicon glyphicon-floppy-saved"></span></font></a>' % (
msg_html = '<span class="glyphicon glyphicon-shopping-cart"></span> %s&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-ok"></span></a>' % (
order_amount,)
option_dict = {'id': "#my_basket", 'html': msg_html}
to_json.append(option_dict)
......
......@@ -23,7 +23,7 @@ from repanier.views.forms import AuthRepanierSetPasswordForm, AuthRepanierPasswo
from repanier.views.like_ajax import like_ajax
from repanier.views.login_view import login_view
from repanier.views.logout_view import logout_view
from repanier.views.me_view import me_view
from repanier.views.my_profile_view import my_profile_view
from repanier.views.my_balance_ajax import my_balance_ajax
from repanier.views.order_ajax import order_ajax
from repanier.views.order_class import OrderView
......@@ -128,7 +128,7 @@ urlpatterns = [
url(r'^coordinators/$', send_mail_to_coordinators_view, name='send_mail_to_coordinators_view'),
url(r'^members/$', send_mail_to_all_members_view, name='send_mail_to_all_members_view'),
url(r'^who/$', who_is_who_view, name='who_is_who_view'),
url(r'^me/$', me_view, name='my_profile_view'),
url(r'^me/$', my_profile_view, name='my_profile_view'),
# url(r'^jsi18n/$', JavaScriptCatalog.as_view(), name='javascript-catalog'),
url(r'^rest/permanences/$', permanences_rest, name='permanences_rest'),
url(r'^rest/permanence/(?P<permanence_id>\d+)/(?P<producer_name>.*)/(?P<reference>.*)/$',
......
......@@ -26,6 +26,7 @@ def login_view(request, template_name='repanier/registration/login.html',
"""
Displays the login form and handles the login action.
"""
from repanier.apps import REPANIER_SETTINGS_CONFIG
redirect_to = request.POST.get(redirect_field_name,
request.GET.get(redirect_field_name, EMPTY_STRING))
......@@ -51,6 +52,7 @@ def login_view(request, template_name='repanier/registration/login.html',
redirect_field_name: redirect_to,
'site' : current_site,
'site_name' : current_site.name,
'how_to_register' : REPANIER_SETTINGS_CONFIG.how_to_register
}
if extra_context is not None:
context.update(extra_context)
......
......@@ -70,7 +70,7 @@ class CustomerValidationForm(NgFormValidationMixin, CustomerForm):
@login_required()
@csrf_protect
@never_cache
def me_view(request):
def my_profile_view(request):
if request.user.is_staff or request.user.is_superuser:
raise Http404
else:
......@@ -110,9 +110,9 @@ def me_view(request):
data["email1"] = customer.user.email
data["email2"] = customer.email2
form = CustomerValidationForm(data, request=request)
return render(request, "repanier/me_form.html",
return render(request, "repanier/my_profile_form.html",
{'form': form, 'membership_fee_valid_until': membership_fee_valid_until, 'update': 'Ok'})
return render(request, "repanier/me_form.html",
return render(request, "repanier/my_profile_form.html",
{'form': form, 'membership_fee_valid_until': membership_fee_valid_until, 'update': 'Nok'})
else:
form = CustomerValidationForm() # An unbound form
......@@ -141,5 +141,5 @@ def me_view(request):
field = form.fields["about_me"]
field.initial = customer.about_me
return render(request, "repanier/me_form.html",
return render(request, "repanier/my_profile_form.html",
{'form': form, 'membership_fee_valid_until': membership_fee_valid_until, 'update': None})
......@@ -88,7 +88,8 @@ class OrderView(ListView):
context = super(OrderView, self).get_context_data(**kwargs)
context['permanence'] = self.permanence
context['delivery_id'] = self.delivery_id
from repanier.apps import REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM, REPANIER_SETTINGS_DISPLAY_ANONYMOUS_ORDER_FORM
from repanier.apps import REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM, \
REPANIER_SETTINGS_DISPLAY_ANONYMOUS_ORDER_FORM, REPANIER_SETTINGS_CONFIG
if REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM:
producer_set = Producer.objects.filter(permanence=self.permanence.id).only("id", "short_profile_name")
else:
......@@ -141,6 +142,10 @@ class OrderView(ListView):
context['communication'] = self.communication
context['q'] = self.q
context['is_anonymous'] = self.is_anonymous
if self.is_anonymous:
context['how_to_register'] = REPANIER_SETTINGS_CONFIG.how_to_register
else:
context['how_to_register'] = EMPTY_STRING
context['may_order'] = self.may_order
context['display_anonymous_order_form'] = REPANIER_SETTINGS_DISPLAY_ANONYMOUS_ORDER_FORM
return context
......
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