Commit c42741aa authored by Patrick's avatar Patrick

Add message about opened offers into the home page

parent da328efe
...@@ -162,10 +162,11 @@ class PermanenceInPreparationAdmin(TranslatableAdmin): ...@@ -162,10 +162,11 @@ class PermanenceInPreparationAdmin(TranslatableAdmin):
def get_fields(self, request, permanence=None): def get_fields(self, request, permanence=None):
fields = [ fields = [
'permanence_date', ('permanence_date', 'picture'),
'automatically_closed', 'automatically_closed',
'short_name', 'short_name',
'offer_description', 'offer_description',
'offer_description_on_home_page',
'producers' 'producers'
] ]
if self.get_boxes(): if self.get_boxes():
......
This diff is collapsed.
...@@ -23,49 +23,51 @@ import permanenceboard ...@@ -23,49 +23,51 @@ import permanenceboard
import producer import producer
import purchase import purchase
import repanier.apps import repanier.apps
from repanier.picture.const import SIZE_L
from repanier.picture.fields import AjaxPictureField
from repanier.fields.RepanierMoneyField import ModelMoneyField from repanier.fields.RepanierMoneyField import ModelMoneyField
from repanier.const import * from repanier.const import *
from repanier.tools import get_full_status_display, cap from repanier.tools import get_full_status_display, cap
def verbose_name(): # def verbose_name():
if repanier.apps.DJANGO_IS_MIGRATION_RUNNING: # if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
return EMPTY_STRING # return EMPTY_STRING
return lambda: "%s" % repanier.apps.REPANIER_SETTINGS_PERMANENCE_NAME # return lambda: "%s" % repanier.apps.REPANIER_SETTINGS_PERMANENCE_NAME
#
#
def verbose_name_plural(): # def verbose_name_plural():
if repanier.apps.DJANGO_IS_MIGRATION_RUNNING: # if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
return EMPTY_STRING # return EMPTY_STRING
return lambda: "%s" % repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME # return lambda: "%s" % repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME
#
#
def verbose_name_in_preparation(): # def verbose_name_in_preparation():
if repanier.apps.DJANGO_IS_MIGRATION_RUNNING: # if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
return EMPTY_STRING # return EMPTY_STRING
return lambda: _("%(name)s in preparation list") % {'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME} # return lambda: _("%(name)s in preparation list") % {'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME}
#
#
def verbose_name_plural_in_preparation(): # def verbose_name_plural_in_preparation():
if repanier.apps.DJANGO_IS_MIGRATION_RUNNING: # if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
return EMPTY_STRING # return EMPTY_STRING
return lambda: _("%(name)s in preparation list") % {'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME} # return lambda: _("%(name)s in preparation list") % {'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME}
#
#
def verbose_name_done(): # def verbose_name_done():
if repanier.apps.DJANGO_IS_MIGRATION_RUNNING: # if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
return EMPTY_STRING # return EMPTY_STRING
return lambda: _("%(name)s done list") % { # return lambda: _("%(name)s done list") % {
'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME} if repanier.apps.REPANIER_SETTINGS_INVOICE else "%s" % _( # 'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME} if repanier.apps.REPANIER_SETTINGS_INVOICE else "%s" % _(
"%(name)s archived list") % {'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME} # "%(name)s archived list") % {'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME}
#
#
def verbose_name_plural_done(): # def verbose_name_plural_done():
if repanier.apps.DJANGO_IS_MIGRATION_RUNNING: # if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
return EMPTY_STRING # return EMPTY_STRING
return lambda: _("%(name)s done list") % { # return lambda: _("%(name)s done list") % {
'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME} if repanier.apps.REPANIER_SETTINGS_INVOICE else "%s" % _( # 'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME} if repanier.apps.REPANIER_SETTINGS_INVOICE else "%s" % _(
"%(name)s archived list") % {'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME} # "%(name)s archived list") % {'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME}
@python_2_unicode_compatible @python_2_unicode_compatible
...@@ -128,6 +130,12 @@ class Permanence(TranslatableModel): ...@@ -128,6 +130,12 @@ class Permanence(TranslatableModel):
invoice_sort_order = models.IntegerField( invoice_sort_order = models.IntegerField(
_("invoice sort order"), _("invoice sort order"),
default=None, blank=True, null=True) default=None, blank=True, null=True)
offer_description_on_home_page = models.BooleanField(
_("Publish the offer description on the home page when the permanence is open"), default=True)
picture = AjaxPictureField(
verbose_name=_("picture"),
null=True, blank=True,
upload_to="permanence", size=SIZE_L)
def get_producers(self): def get_producers(self):
if self.status == PERMANENCE_PLANNED: if self.status == PERMANENCE_PLANNED:
...@@ -603,21 +611,21 @@ class Permanence(TranslatableModel): ...@@ -603,21 +611,21 @@ class Permanence(TranslatableModel):
get_permanence_admin_display.short_description = lambda: "%s" % repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME get_permanence_admin_display.short_description = lambda: "%s" % repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME
get_permanence_admin_display.allow_tags = True get_permanence_admin_display.allow_tags = True
def get_permanence_order_display(self): # def get_permanence_order_display(self):
if self.with_delivery_point: # if self.with_delivery_point:
if self.status == PERMANENCE_OPENED: # if self.status == PERMANENCE_OPENED:
deliveries_count = 0 # deliveries_count = 0
else: # else:
deliveries_qs = deliveryboard.DeliveryBoard.objects.filter( # deliveries_qs = deliveryboard.DeliveryBoard.objects.filter(
permanence_id=self.id, # permanence_id=self.id,
status=PERMANENCE_OPENED # status=PERMANENCE_OPENED
).order_by('?') # ).order_by('?')
deliveries_count = deliveries_qs.count() # deliveries_count = deliveries_qs.count()
else: # else:
deliveries_count = 0 # deliveries_count = 0
if deliveries_count == 0: # if deliveries_count == 0:
return "%s - %s" % (self.get_permanence_display(), self.get_status_display()) # return "%s - %s" % (self.get_permanence_display(), self.get_status_display())
return self.get_permanence_display() # return self.get_permanence_display()
def get_permanence_customer_display(self, with_status=True): def get_permanence_customer_display(self, with_status=True):
if with_status: if with_status:
...@@ -643,8 +651,8 @@ class Permanence(TranslatableModel): ...@@ -643,8 +651,8 @@ class Permanence(TranslatableModel):
return self.get_permanence_display() return self.get_permanence_display()
class Meta: class Meta:
verbose_name = verbose_name() verbose_name = _('order')
verbose_name_plural = verbose_name_plural() verbose_name_plural = _('orders')
index_together = [ index_together = [
["permanence_date"], ["permanence_date"],
...@@ -654,13 +662,13 @@ class Permanence(TranslatableModel): ...@@ -654,13 +662,13 @@ class Permanence(TranslatableModel):
class PermanenceInPreparation(Permanence): class PermanenceInPreparation(Permanence):
class Meta: class Meta:
proxy = True proxy = True
verbose_name = verbose_name_in_preparation() verbose_name = _('In preparation')
verbose_name_plural = verbose_name_plural_in_preparation() verbose_name_plural = _('In preparation')
class PermanenceDone(Permanence): class PermanenceDone(Permanence):
class Meta: class Meta:
proxy = True proxy = True
verbose_name = verbose_name_done() verbose_name = _('In billing')
verbose_name_plural = verbose_name_plural_done() verbose_name_plural = _('In billing')
...@@ -4,3 +4,4 @@ from __future__ import unicode_literals ...@@ -4,3 +4,4 @@ from __future__ import unicode_literals
SIZE_XS = 48 SIZE_XS = 48
SIZE_S = 110 SIZE_S = 110
SIZE_M = 225 SIZE_M = 225
SIZE_L = 450
# -*- coding: utf-8 # -*- coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
from const import SIZE_XS, SIZE_M, SIZE_S from const import SIZE_XS, SIZE_S, SIZE_M, SIZE_L
from repanier.tools import sint from repanier.tools import sint
try: try:
...@@ -28,7 +28,7 @@ def ajax_picture(request, upload_to=None, form_class=FileForm, size=SIZE_XS): ...@@ -28,7 +28,7 @@ def ajax_picture(request, upload_to=None, form_class=FileForm, size=SIZE_XS):
form = form_class(request.POST, request.FILES) form = form_class(request.POST, request.FILES)
if form.is_valid(): if form.is_valid():
size = sint(size) size = sint(size)
if size not in [SIZE_XS, SIZE_S, SIZE_M]: if size not in [SIZE_XS, SIZE_S, SIZE_M, SIZE_L]:
data = json.dumps({'error': _not_lazy('Wrong size.')}) data = json.dumps({'error': _not_lazy('Wrong size.')})
return HttpResponse(data, content_type="application/json", status=403) return HttpResponse(data, content_type="application/json", status=403)
......
...@@ -113,7 +113,11 @@ a.skip_link{ ...@@ -113,7 +113,11 @@ a.skip_link{
margin-top: 65px; margin-top: 65px;
} }
.container-repanier { .container-repanier {
margin: 75px 15px 0; margin: 75px 0 0;
padding: 15px 15px 0;
}
.container-info {
margin: 75px 0 -75px 0;
padding: 15px 15px 0; padding: 15px 15px 0;
} }
.container-menu { .container-menu {
......
...@@ -95,6 +95,34 @@ ...@@ -95,6 +95,34 @@
</div> </div>
</div> </div>
<a name="content"></a><section> <a name="content"></a><section>
{% if current_page.is_home %}
<div class="container-info" id="containerInfo" style="display: none">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default" id="homeInfo">
</div>
</div>
</div>
</div>
</div>
{% addtoblock "lastjs" %}{% spaceless %}
<script type="text/javascript">
$(document).ready(function () {
lien = '{% url 'home_info' %}';
$.ajax({
url: lien,
cache: false,
async: false,
success: function (result) {
$("#homeInfo").html(result);
$("#containerInfo").show();
}
});
});
</script>
{% endspaceless %}{% endaddtoblock %}
{% endif %}
{% block base_content%}{% endblock %} {% block base_content%}{% endblock %}
</section> </section>
<div class="footer"> <div class="footer">
......
...@@ -138,7 +138,7 @@ ...@@ -138,7 +138,7 @@
{% endif %} {% endif %}
{% if next_customer_invoice_id %} {% if next_customer_invoice_id %}
<a href="{% url 'customer_invoice_view' next_customer_invoice_id %}" <a href="{% url 'customer_invoice_view' next_customer_invoice_id %}"
class="btn btn-success btn-disabled">&nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-arrow-right"></span>&nbsp;&nbsp;&nbsp;&nbsp;</a> class="btn btn-success btn-disabled"><span class="glyphicon glyphicon-arrow-right"></span></a>
<a href="{% url 'customer_invoice_view' 0 %}?customer={{ object.customer.id }}" <a href="{% url 'customer_invoice_view' 0 %}?customer={{ object.customer.id }}"
class="btn btn-success btn-disabled"> <span class="glyphicon glyphicon-arrow-right"></span> class="btn btn-success btn-disabled"> <span class="glyphicon glyphicon-arrow-right"></span>
<span class="glyphicon glyphicon-arrow-right"></span> </a> <span class="glyphicon glyphicon-arrow-right"></span> </a>
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
<div class="panel panel-default"> <div class="panel panel-default">
{% if permanence.offer_description and permanence.offer_description.strip %} {% if permanence.offer_description and permanence.offer_description.strip %}
<div class="panel-heading accordion-toggle collapsed" data-toggle="collapse" data-target="#collapse-offer-description"> <div class="panel-heading accordion-toggle collapsed" data-toggle="collapse" data-target="#collapse-offer-description">
<h4 class="panel-title">{{ permanence.get_permanence_order_display }}</h4> <h4 class="panel-title">{{ permanence.get_permanence_customer_display }}</h4>
</div> </div>
<div id="collapse-offer-description" class="panel-collapse collapse"> <div id="collapse-offer-description" class="panel-collapse collapse">
<div class="panel-body bg-primary"> <div class="panel-body bg-primary">
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
</div> </div>
{% else %} {% else %}
<div class="panel-heading"> <div class="panel-heading">
<h4 class="panel-title">{{ permanence.get_permanence_order_display }}</h4> <h4 class="panel-title">{{ permanence.get_permanence_customer_display }}</h4>
</div> </div>
{% endif %} {% endif %}
</div> </div>
......
...@@ -119,10 +119,10 @@ ...@@ -119,10 +119,10 @@
async: false, async: false,
success: function (result) { success: function (result) {
$("#my_name").html(result); $("#my_name").html(result);
if (result == '{% trans "Anonymous" %}') { {# if (result === '{% trans "Anonymous" %}') {#}
$("#connected").show(); {# $("#connected").show();#}
$("#not_connected").hide(); {# $("#not_connected").hide();#}
} {# }#}
}, },
error: function (result) { error: function (result) {
$("#my_name").html("{% trans "Retry5" %}"); $("#my_name").html("{% trans "Retry5" %}");
......
...@@ -163,10 +163,10 @@ ...@@ -163,10 +163,10 @@
async: false, async: false,
success: function (result) { success: function (result) {
$("#my_name").html(result); $("#my_name").html(result);
if(result === '{% trans "Anonymous" %}') { {# if(result === '{% trans "Anonymous" %}') {#}
$("#connected").show(); {# $("#connected").show();#}
$("#not_connected").hide(); {# $("#not_connected").hide();#}
} {# }#}
}, },
error: function (result) { error: function (result) {
$("#my_name").html("{% trans "Retry5" %}"); $("#my_name").html("{% trans "Retry5" %}");
......
...@@ -42,6 +42,7 @@ from repanier.views.who_is_who_view import who_is_who_view ...@@ -42,6 +42,7 @@ from repanier.views.who_is_who_view import who_is_who_view
from repanier.views.display_status_ajax import display_status from repanier.views.display_status_ajax import display_status
from repanier.views.is_into_offer_ajax import is_into_offer from repanier.views.is_into_offer_ajax import is_into_offer
from repanier.views.download_customer_invoice import download_customer_invoice from repanier.views.download_customer_invoice import download_customer_invoice
from repanier.views.home_info_ajax import home_info_ajax
urlpatterns = [ urlpatterns = [
url(r'^go_repanier/$', login_view, name='login_form'), url(r'^go_repanier/$', login_view, name='login_form'),
...@@ -91,6 +92,7 @@ urlpatterns = [ ...@@ -91,6 +92,7 @@ urlpatterns = [
url(r'^ajax/delivery/$', delivery_ajax, name='delivery_ajax'), url(r'^ajax/delivery/$', delivery_ajax, name='delivery_ajax'),
url(r'^ajax/my-balance/$', my_balance_ajax, name='my_balance'), url(r'^ajax/my-balance/$', my_balance_ajax, name='my_balance'),
url(r'^ajax/order-name/$', customer_name_ajax, name='order_name'), url(r'^ajax/order-name/$', customer_name_ajax, name='order_name'),
url(r'^ajax/home-info/$', home_info_ajax, name='home_info'),
url(r'^ajax/pre-order-name/(?P<offer_uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/$', url(r'^ajax/pre-order-name/(?P<offer_uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/$',
producer_name_ajax, name='pre_order_name_ajax'), producer_name_ajax, name='pre_order_name_ajax'),
url(r'^ajax/order-init/$', order_init_ajax, name='order_init_ajax'), url(r'^ajax/order-init/$', order_init_ajax, name='order_init_ajax'),
...@@ -98,7 +100,8 @@ urlpatterns = [ ...@@ -98,7 +100,8 @@ urlpatterns = [
url(r'^ajax/delivery-select/$', delivery_select_ajax, name='delivery_select_ajax'), url(r'^ajax/delivery-select/$', delivery_select_ajax, name='delivery_select_ajax'),
url(r'^ajax/permanence/$', permanence_form_ajax, name='permanence_form_ajax'), url(r'^ajax/permanence/$', permanence_form_ajax, name='permanence_form_ajax'),
url(r'^ajax/customer-basket-message/(?P<pk>\d+)/$', customer_basket_message_form_ajax, name='customer_basket_message_form_ajax'), url(r'^ajax/customer-basket-message/(?P<pk>\d+)/$', customer_basket_message_form_ajax, name='customer_basket_message_form_ajax'),
url(r'^ajax/producer-basket-message/(?P<pk>\d+)/(?P<uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/$', producer_basket_message_form_ajax, name='producer_basket_message_form_ajax'), url(r'^ajax/producer-basket-message/(?P<pk>\d+)/(?P<uuid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/$',
producer_basket_message_form_ajax, name='producer_basket_message_form_ajax'),
url(r'^ajax/customer-product-description/$', customer_product_description_ajax, url(r'^ajax/customer-product-description/$', customer_product_description_ajax,
name='customer_product_description_ajax'), name='customer_product_description_ajax'),
url( url(
......
# -*- coding: utf-8
from __future__ import unicode_literals
from django.conf import settings
from django.http import Http404
from django.http import HttpResponse
from django.urls import reverse
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.views.decorators.cache import never_cache
from django.views.decorators.http import require_GET
from repanier.const import PERMANENCE_OPENED
from repanier.models import Permanence
@never_cache
@require_GET
def home_info_ajax(request):
if request.is_ajax():
result = []
for permanence in Permanence.objects.filter(
status=PERMANENCE_OPENED) \
.only("id", "permanence_date", "with_delivery_point") \
.order_by('permanence_date'):
result.append(
format_html(
'<div class="panel-heading"><h4 class="panel-title"><a href="{}">{}</a></h4></div>',
reverse('order_view', args=(permanence.id,)),
permanence.get_permanence_customer_display()
)
)
if permanence.offer_description_on_home_page and permanence.offer_description:
if permanence.picture:
result.append(
format_html(
'<div class="panel-body"><div class="col-xs-12"><img class="img-rounded" style="float: left; margin: 5px;" alt="{} title="{}" src="{}{}"/>{}</div></div>',
permanence.get_permanence_customer_display(),
permanence.get_permanence_customer_display(),
settings.MEDIA_URL,
permanence.picture,
mark_safe(permanence.offer_description)
)
)
else:
result.append(
format_html(
'<div class="panel-body"><div class="col-xs-12">{}</div></div>',
mark_safe(permanence.offer_description)
)
)
if len(result) > 0:
return HttpResponse("".join(result))
raise Http404
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