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):
def get_fields(self, request, permanence=None):
fields = [
'permanence_date',
('permanence_date', 'picture'),
'automatically_closed',
'short_name',
'offer_description',
'offer_description_on_home_page',
'producers'
]
if self.get_boxes():
......
This diff is collapsed.
......@@ -23,49 +23,51 @@ import permanenceboard
import producer
import purchase
import repanier.apps
from repanier.picture.const import SIZE_L
from repanier.picture.fields import AjaxPictureField
from repanier.fields.RepanierMoneyField import ModelMoneyField
from repanier.const import *
from repanier.tools import get_full_status_display, cap
def verbose_name():
if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
return EMPTY_STRING
return lambda: "%s" % repanier.apps.REPANIER_SETTINGS_PERMANENCE_NAME
def verbose_name_plural():
if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
return EMPTY_STRING
return lambda: "%s" % repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME
def verbose_name_in_preparation():
if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
return EMPTY_STRING
return lambda: _("%(name)s in preparation list") % {'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME}
def verbose_name_plural_in_preparation():
if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
return EMPTY_STRING
return lambda: _("%(name)s in preparation list") % {'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME}
def verbose_name_done():
if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
return EMPTY_STRING
return lambda: _("%(name)s done list") % {
'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}
def verbose_name_plural_done():
if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
return EMPTY_STRING
return lambda: _("%(name)s done list") % {
'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}
# def verbose_name():
# if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
# return EMPTY_STRING
# return lambda: "%s" % repanier.apps.REPANIER_SETTINGS_PERMANENCE_NAME
#
#
# def verbose_name_plural():
# if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
# return EMPTY_STRING
# return lambda: "%s" % repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME
#
#
# def verbose_name_in_preparation():
# if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
# return EMPTY_STRING
# return lambda: _("%(name)s in preparation list") % {'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME}
#
#
# def verbose_name_plural_in_preparation():
# if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
# return EMPTY_STRING
# return lambda: _("%(name)s in preparation list") % {'name': repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME}
#
#
# def verbose_name_done():
# if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
# return EMPTY_STRING
# return lambda: _("%(name)s done list") % {
# '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}
#
#
# def verbose_name_plural_done():
# if repanier.apps.DJANGO_IS_MIGRATION_RUNNING:
# return EMPTY_STRING
# return lambda: _("%(name)s done list") % {
# '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}
@python_2_unicode_compatible
......@@ -128,6 +130,12 @@ class Permanence(TranslatableModel):
invoice_sort_order = models.IntegerField(
_("invoice sort order"),
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):
if self.status == PERMANENCE_PLANNED:
......@@ -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.allow_tags = True
def get_permanence_order_display(self):
if self.with_delivery_point:
if self.status == PERMANENCE_OPENED:
deliveries_count = 0
else:
deliveries_qs = deliveryboard.DeliveryBoard.objects.filter(
permanence_id=self.id,
status=PERMANENCE_OPENED
).order_by('?')
deliveries_count = deliveries_qs.count()
else:
deliveries_count = 0
if deliveries_count == 0:
return "%s - %s" % (self.get_permanence_display(), self.get_status_display())
return self.get_permanence_display()
# def get_permanence_order_display(self):
# if self.with_delivery_point:
# if self.status == PERMANENCE_OPENED:
# deliveries_count = 0
# else:
# deliveries_qs = deliveryboard.DeliveryBoard.objects.filter(
# permanence_id=self.id,
# status=PERMANENCE_OPENED
# ).order_by('?')
# deliveries_count = deliveries_qs.count()
# else:
# deliveries_count = 0
# if deliveries_count == 0:
# return "%s - %s" % (self.get_permanence_display(), self.get_status_display())
# return self.get_permanence_display()
def get_permanence_customer_display(self, with_status=True):
if with_status:
......@@ -643,8 +651,8 @@ class Permanence(TranslatableModel):
return self.get_permanence_display()
class Meta:
verbose_name = verbose_name()
verbose_name_plural = verbose_name_plural()
verbose_name = _('order')
verbose_name_plural = _('orders')
index_together = [
["permanence_date"],
......@@ -654,13 +662,13 @@ class Permanence(TranslatableModel):
class PermanenceInPreparation(Permanence):
class Meta:
proxy = True
verbose_name = verbose_name_in_preparation()
verbose_name_plural = verbose_name_plural_in_preparation()
verbose_name = _('In preparation')
verbose_name_plural = _('In preparation')
class PermanenceDone(Permanence):
class Meta:
proxy = True
verbose_name = verbose_name_done()
verbose_name_plural = verbose_name_plural_done()
verbose_name = _('In billing')
verbose_name_plural = _('In billing')
......@@ -4,3 +4,4 @@ from __future__ import unicode_literals
SIZE_XS = 48
SIZE_S = 110
SIZE_M = 225
SIZE_L = 450
# -*- coding: utf-8
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
try:
......@@ -28,7 +28,7 @@ def ajax_picture(request, upload_to=None, form_class=FileForm, size=SIZE_XS):
form = form_class(request.POST, request.FILES)
if form.is_valid():
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.')})
return HttpResponse(data, content_type="application/json", status=403)
......
......@@ -113,7 +113,11 @@ a.skip_link{
margin-top: 65px;
}
.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;
}
.container-menu {
......
......@@ -95,6 +95,34 @@
</div>
</div>
<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 %}
</section>
<div class="footer">
......
......@@ -138,7 +138,7 @@
{% endif %}
{% if 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 }}"
class="btn btn-success btn-disabled"> <span class="glyphicon glyphicon-arrow-right"></span>
<span class="glyphicon glyphicon-arrow-right"></span> </a>
......
......@@ -34,7 +34,7 @@
<div class="panel panel-default">
{% if permanence.offer_description and permanence.offer_description.strip %}
<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 id="collapse-offer-description" class="panel-collapse collapse">
<div class="panel-body bg-primary">
......@@ -45,7 +45,7 @@
</div>
{% else %}
<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>
{% endif %}
</div>
......
......@@ -119,10 +119,10 @@
async: false,
success: function (result) {
$("#my_name").html(result);
if (result == '{% trans "Anonymous" %}') {
$("#connected").show();
$("#not_connected").hide();
}
{# if (result === '{% trans "Anonymous" %}') {#}
{# $("#connected").show();#}
{# $("#not_connected").hide();#}
{# }#}
},
error: function (result) {
$("#my_name").html("{% trans "Retry5" %}");
......
......@@ -163,10 +163,10 @@
async: false,
success: function (result) {
$("#my_name").html(result);
if(result === '{% trans "Anonymous" %}') {
$("#connected").show();
$("#not_connected").hide();
}
{# if(result === '{% trans "Anonymous" %}') {#}
{# $("#connected").show();#}
{# $("#not_connected").hide();#}
{# }#}
},
error: function (result) {
$("#my_name").html("{% trans "Retry5" %}");
......
......@@ -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.is_into_offer_ajax import is_into_offer
from repanier.views.download_customer_invoice import download_customer_invoice
from repanier.views.home_info_ajax import home_info_ajax
urlpatterns = [
url(r'^go_repanier/$', login_view, name='login_form'),
......@@ -91,6 +92,7 @@ urlpatterns = [
url(r'^ajax/delivery/$', delivery_ajax, name='delivery_ajax'),
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/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})/$',
producer_name_ajax, name='pre_order_name_ajax'),
url(r'^ajax/order-init/$', order_init_ajax, name='order_init_ajax'),
......@@ -98,7 +100,8 @@ urlpatterns = [
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/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,
name='customer_product_description_ajax'),
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