示例#1
0
 def get_list_display(self, request):
     producer_id = sint(request.GET.get('producer', 0))
     if producer_id != 0:
         producer_queryset = Producer.objects.filter(id=producer_id).order_by('?')
         producer = producer_queryset.first()
     else:
         producer = None
     permanence_id = sint(request.GET.get('permanence', 0))
     permanence_open = False
     permanence = Permanence.objects.filter(id=permanence_id, status=PERMANENCE_OPENED).order_by('?')
     if permanence.exists():
         permanence_open = True
     if producer is not None:
         self.list_editable = ('stock',)
         if producer.manage_replenishment:
             if permanence_open:
                 return ('department_for_customer', 'producer', 'get_long_name',
                         'stock',
                         'get_html_producer_qty_stock_invoiced')
             else:
                 return ('department_for_customer', 'producer', 'get_long_name',
                         'stock',
                         'get_html_producer_qty_stock_invoiced',
                         'add_2_stock')
         elif producer.manage_production:
             return ('department_for_customer', 'producer', 'get_long_name',
                     'stock',
                     'get_html_producer_qty_stock_invoiced')
         else:
             return ('department_for_customer', 'producer', 'get_long_name',
                     'get_html_producer_qty_stock_invoiced')
     else:
         return ('department_for_customer', 'producer', 'get_long_name',
                 'get_html_producer_qty_stock_invoiced')
示例#2
0
def flexible_dates(request, product_id, contract_id):
    if request.is_ajax():
        user = request.user
        if user.is_order_manager:
            product_id = sint(product_id)
            product = Product.objects.filter(id=product_id).order_by('?').first()
            if product is not None:
                contract_id = sint(contract_id)
                contract = None
                contract_content = None
                if contract_id > 0:
                    contract = Contract.objects.filter(id=contract_id).order_by('?').first()
                    if contract is not None:
                        contract_content = ContractContent.objects.filter(
                            product_id=product_id,
                            contract_id=contract_id
                        ).order_by('?').first()
                        if contract_content is not None:
                            if product.order_unit > PRODUCT_ORDER_UNIT_DEPOSIT:
                                contract_content.flexible_dates = True
                            else:
                                contract_content.flexible_dates = not (contract_content.flexible_dates)
                            contract_content.save(update_fields=["flexible_dates"])
                        # else:
                        #     contract_content = ContractContent.objects.create(
                        #         contract_id=contract_id,
                        #         product_id=product_id,
                        #     )
                        #     contract_content.all_dates = contract.all_dates
                        #     contract_content.save()
                return HttpResponse(
                    product.get_html_is_into_offer(contract=contract, contract_content=contract_content))
    raise Http404
示例#3
0
 def get(self, request, *args, **kwargs):
     self.first_page = kwargs.get('page', True)
     permanence_id = sint(kwargs.get('permanence_id', 0))
     self.permanence = Permanence.objects.filter(id=permanence_id).only(
         "id", "status", "permanence_date", "with_delivery_point",
         "contract").order_by('?').first()
     permanence_ok_or_404(self.permanence)
     self.user = request.user
     self.is_basket = self.request.GET.get('is_basket', False)
     self.is_like = self.request.GET.get('is_like', False)
     if self.permanence.contract is not None and self.permanence.contract.permanences_dates is not None:
         self.all_dates = sorted(
             self.permanence.contract.permanences_dates.split(
                 settings.DJANGO_SETTINGS_DATES_SEPARATOR))
         len_all_dates = len(self.all_dates)
         if len_all_dates < 2:
             self.date_id = 'all'
         else:
             date_id = sint(self.request.GET.get('date'), -1)
             if date_id < 0 or date_id >= len_all_dates:
                 self.date_id = 'all'
             else:
                 self.date_id = date_id
                 self.date_selected = self.all_dates[date_id]
     customer_may_order = Customer.objects.filter(
         user_id=self.user.id, is_active=True).order_by('?').exists()
     if self.user.is_anonymous or not customer_may_order:
         self.is_anonymous = True
         self.may_order = False
     else:
         self.is_anonymous = False
         customer = self.user.customer
         self.may_order = customer.may_order if customer is not None else False
     self.q = self.request.GET.get('q', None)
     if not self.q:
         self.producer_id = self.request.GET.get('producer', 'all')
         if self.producer_id != 'all':
             self.producer_id = sint(self.producer_id)
         self.department_id = self.request.GET.get('department', 'all')
         if self.department_id != 'all':
             self.department_id = sint(self.department_id)
         self.box_id = self.request.GET.get('box', 'all')
         if self.box_id != 'all':
             self.box_id = sint(self.box_id)
             self.is_box = True
             # Do not display "all department" as selected
             self.department_id = None
     if len(request.GET) == 0:
         # This to let display a communication into a popup when the user is on the first order screen
         self.communication = True
     else:
         self.communication = False
     return super(OrderView, self).get(request, *args, **kwargs)
示例#4
0
 def get(self, request, *args, **kwargs):
     self.first_page = kwargs.get('page', True)
     permanence_id = sint(kwargs.get('permanence_id', 0))
     self.permanence = Permanence.objects.filter(id=permanence_id).only(
         "id", "status", "permanence_date", "with_delivery_point", "contract"
     ).order_by('?').first()
     permanence_ok_or_404(self.permanence)
     self.user = request.user
     self.is_basket = self.request.GET.get('is_basket', False)
     self.is_like = self.request.GET.get('is_like', False)
     if self.permanence.contract is not None and self.permanence.contract.permanences_dates is not None:
         self.all_dates = sorted(
             self.permanence.contract.permanences_dates.split(settings.DJANGO_SETTINGS_DATES_SEPARATOR))
         len_all_dates = len(self.all_dates)
         if len_all_dates < 2:
             self.date_id = 'all'
         else:
             date_id = sint(self.request.GET.get('date'), -1)
             if date_id < 0 or date_id >= len_all_dates:
                 self.date_id = 'all'
             else:
                 self.date_id = date_id
                 self.date_selected = self.all_dates[date_id]
     customer_may_order = Customer.objects.filter(user_id=self.user.id, is_active=True).order_by('?').exists()
     if self.user.is_anonymous or not customer_may_order:
         self.is_anonymous = True
         self.may_order = False
     else:
         self.is_anonymous = False
         customer = self.user.customer
         self.may_order = customer.may_order if customer is not None else False
     self.q = self.request.GET.get('q', None)
     if not self.q:
         self.producer_id = self.request.GET.get('producer', 'all')
         if self.producer_id != 'all':
             self.producer_id = sint(self.producer_id)
         self.department_id = self.request.GET.get('department', 'all')
         if self.department_id != 'all':
             self.department_id = sint(self.department_id)
         self.box_id = self.request.GET.get('box', 'all')
         if self.box_id != 'all':
             self.box_id = sint(self.box_id)
             self.is_box = True
             # Do not display "all department" as selected
             self.department_id = None
     if len(request.GET) == 0:
         # This to let display a communication into a popup when the user is on the first order screen
         self.communication = True
     else:
         self.communication = False
     return super(OrderView, self).get(request, *args, **kwargs)
示例#5
0
def like_ajax(request):
    if request.is_ajax():
        user = request.user
        if user.is_authenticated:
            offer_item_id = sint(request.GET.get('offer_item', 0))
            offer_item = OfferItemWoReceiver.objects.filter(id=offer_item_id).order_by('?').first()
            if offer_item is not None and offer_item.product_id is not None:
                product = offer_item.product
                json_dict = {}
                if product.likes.filter(id=user.id).exists():
                    # user has already liked this company
                    # remove like/user
                    product.likes.remove(user)
                else:
                    # add a new like for a company
                    product.likes.add(user)
                like_html = offer_item.get_html_like(user)
                if settings.REPANIER_SETTINGS_CONTRACT:
                    for offer_item in OfferItemWoReceiver.objects.filter(product_id=product.id).only("id").order_by(
                            '?'):
                        json_dict[".btn_like{}".format(offer_item.id)] = like_html
                else:
                    json_dict[".btn_like{}".format(offer_item.id)] = like_html
                return JsonResponse(json_dict)
    raise Http404
示例#6
0
def like_ajax(request):
    if request.is_ajax():
        user = request.user
        if user.is_authenticated:
            offer_item_id = sint(request.GET.get('offer_item', 0))
            offer_item = OfferItemWoReceiver.objects.filter(
                id=offer_item_id).order_by('?').first()
            if offer_item is not None and offer_item.product_id is not None:
                product = offer_item.product
                json_dict = {}
                if product.likes.filter(id=user.id).exists():
                    # user has already liked this company
                    # remove like/user
                    product.likes.remove(user)
                else:
                    # add a new like for a company
                    product.likes.add(user)
                like_html = offer_item.get_html_like(user)
                if settings.REPANIER_SETTINGS_CONTRACT:
                    for offer_item in OfferItemWoReceiver.objects.filter(
                            product_id=product.id).only("id").order_by('?'):
                        json_dict[".btn_like{}".format(
                            offer_item.id)] = like_html
                else:
                    json_dict[".btn_like{}".format(offer_item.id)] = like_html
                return JsonResponse(json_dict)
    raise Http404
示例#7
0
 def get_list_display(self, request):
     producer_id = sint(request.GET.get('producer', 0))
     if producer_id != 0:
         producer_queryset = Producer.objects.filter(id=producer_id).order_by('?')
         producer = producer_queryset.first()
     else:
         producer = None
     # permanence_id = sint(request.GET.get('permanence', 0))
     # permanence_open = False
     # permanence = Permanence.objects.filter(id=permanence_id, status=PERMANENCE_OPENED).order_by('?')
     # if permanence.exists():
     #     permanence_open = True
     if producer is not None:
         if settings.REPANIER_SETTINGS_STOCK:
             self.list_editable = ('stock',)
             return ('department_for_customer', 'get_html_long_name_with_producer',
                     'stock', 'limit_order_quantity_to_stock',
                     'get_html_producer_qty_stock_invoiced',
                     'add_2_stock')
         else:
             return ('department_for_customer', 'get_html_long_name_with_producer',
                     'get_html_producer_qty_stock_invoiced')
     else:
         return ('department_for_customer', 'get_html_long_name_with_producer',
                 'get_html_producer_qty_stock_invoiced')
示例#8
0
 def get_list_display(self, request):
     producer_id = sint(request.GET.get('producer', 0))
     if producer_id != 0:
         producer_queryset = Producer.objects.filter(id=producer_id).order_by('?')
         producer = producer_queryset.first()
     else:
         producer = None
     # permanence_id = sint(request.GET.get('permanence', 0))
     # permanence_open = False
     # permanence = Permanence.objects.filter(id=permanence_id, status=PERMANENCE_OPENED).order_by('?')
     # if permanence.exists():
     #     permanence_open = True
     if producer is not None:
         if settings.REPANIER_SETTINGS_STOCK:
             self.list_editable = ('stock',)
             return ('department_for_customer', 'get_html_long_name_with_producer',
                     'stock', 'limit_order_quantity_to_stock',
                     'get_html_producer_qty_stock_invoiced',
                     'add_2_stock')
         else:
             return ('department_for_customer', 'get_html_long_name_with_producer',
                     'get_html_producer_qty_stock_invoiced')
     else:
         return ('department_for_customer', 'get_html_long_name_with_producer',
                 'get_html_producer_qty_stock_invoiced')
示例#9
0
 def get_list_display(self, request):
     producer_id = sint(request.GET.get('producer', 0))
     if producer_id != 0:
         producer_queryset = Producer.objects.filter(id=producer_id).order_by('?')
         producer = producer_queryset.first()
     else:
         producer = None
     if producer is not None:
         if producer.producer_pre_opening:
             self.list_editable = ('producer_unit_price', 'stock')
             return ('is_into_offer', 'producer', 'department_for_customer', 'get_long_name', 'language_column',
                     'producer_unit_price',
                     'stock')
         elif producer.manage_replenishment or producer.manage_production:
             self.list_editable = ('producer_unit_price', 'stock')
             return ('is_into_offer', 'producer', 'department_for_customer', 'get_long_name', 'language_column',
                     'producer_unit_price',
                     'get_customer_alert_order_quantity', 'stock')
         else:
             self.list_editable = ('producer_unit_price',)
             return ('is_into_offer', 'producer', 'department_for_customer', 'get_long_name', 'language_column',
                     'producer_unit_price',
                     'get_customer_alert_order_quantity')
     else:
         self.list_editable = ('producer_unit_price', 'stock')
         return ('is_into_offer', 'producer', 'department_for_customer', 'get_long_name', 'language_column',
                 'producer_unit_price',
                 'get_customer_alert_order_quantity', 'stock')
示例#10
0
def task_form_ajax(request):
    if not request.is_ajax():
        raise Http404
    try:
        customer = request.user.customer
    except:
        raise Http404
    result = "ko"
    p_permanence_board_id = sint(request.GET.get('task', -1))
    p_value_id = sint(request.GET.get('value', -1))
    if p_permanence_board_id >= 0 and p_value_id >= 0:
        if p_value_id == 0:
            # The customer may leave if (1) PLANNED or (2) less then 24h after registration and < CLOSED
            row_counter = PermanenceBoard.objects.filter(
                id=p_permanence_board_id,
                customer_id=customer.id,
                permanence__status__lt=PERMANENCE_OPENED,
                permanence_role__customers_may_register=True,
            ).update(
                customer=None
            )
            if row_counter == 0:
                row_counter = PermanenceBoard.objects.filter(
                    id=p_permanence_board_id,
                    customer_id=customer.id,
                    permanence__status__lt=PERMANENCE_CLOSED,
                    permanence_role__customers_may_register=True,
                    is_registered_on__gte=timezone.now() - datetime.timedelta(days=1)
                ).update(
                    customer=None
                )
        elif customer.may_order:
            # The customer may enroll until <= SEND
            row_counter = PermanenceBoard.objects.filter(
                id=p_permanence_board_id,
                customer__isnull=True,
                permanence__status__lte=PERMANENCE_SEND,
                permanence_role__customers_may_register=True
            ).update(
                customer_id=customer.id,
                is_registered_on=timezone.now()
            )
        else:
            row_counter = 0
        if row_counter > 0:
            result = "ok"
    return HttpResponse(result)
示例#11
0
 def dispatch(self, request, *args, **kwargs):
     permanence_id = sint(kwargs.get('permanence_id', 0))
     self.permanence = Permanence.objects.filter(id=permanence_id).only("id", "status", "permanence_date",
                                                                        "with_delivery_point").order_by('?').first()
     permanence_ok_or_404(self.permanence)
     self.user = request.user
     self.basket = kwargs.get('basket', False)
     if not self.basket:
         self.like = kwargs.get('like', False)
     else:
         # Not both favorite and basket
         self.like = False
     if self.permanence.with_delivery_point:
         self.delivery_id = sint(kwargs.get('delivery_id', 0))
     if self.user.is_anonymous() or self.user.is_staff:
         self.is_anonymous = True
         self.may_order = False
         self.q = None
     else:
         self.is_anonymous = False
         customer = self.user.customer
         self.may_order = customer.may_order if customer is not None else False
         self.q = self.request.GET.get('q', None)
         if self.q == EMPTY_STRING:
             self.q = None
     self.producer_id = self.request.GET.get('producer', 'all')
     if self.producer_id != 'all':
         self.producer_id = sint(self.producer_id)
     self.departementforcustomer_id = self.request.GET.get('departementforcustomer', 'all')
     if self.departementforcustomer_id != 'all':
         self.departementforcustomer_id = sint(self.departementforcustomer_id)
     self.box_id = self.request.GET.get('box', 'all')
     if self.box_id != 'all':
         self.box_id = sint(self.box_id)
         self.is_box = True
         # Do not display "all department" as selected
         self.departementforcustomer_id = None
     else:
         self.is_box = False
     if self.producer_id == 'all' and self.departementforcustomer_id == 'all' \
             and not self.basket and 'page' not in request.GET \
             and self.q is None:
         # This to let display a communication into a popup when the user is on the first order screen
         self.communication = True
     else:
         self.communication = False
     return super(OrderView, self).dispatch(request, *args, **kwargs)
示例#12
0
def task_form_ajax(request):
    if not request.is_ajax():
        raise Http404
    try:
        customer = request.user.customer
    except:
        raise Http404
    result = "ko"
    p_permanence_board_id = sint(request.GET.get('task', -1))
    p_value_id = sint(request.GET.get('value', -1))
    if p_permanence_board_id >= 0 and p_value_id >= 0:
        if p_value_id == 0:
            # The customer may leave if (1) PLANNED or (2) less then 24h after registration and < CLOSED
            row_counter = PermanenceBoard.objects.filter(
                id=p_permanence_board_id,
                customer_id=customer.id,
                permanence__status__lt=PERMANENCE_OPENED,
                permanence_role__customers_may_register=True,
            ).update(
                customer=None
            )
            if row_counter == 0:
                row_counter = PermanenceBoard.objects.filter(
                    id=p_permanence_board_id,
                    customer_id=customer.id,
                    permanence__status__lt=PERMANENCE_CLOSED,
                    permanence_role__customers_may_register=True,
                    is_registered_on__gte=timezone.now() - datetime.timedelta(days=1)
                ).update(
                    customer=None
                )
        elif customer.may_order:
            # The customer may enroll until <= SEND
            row_counter = PermanenceBoard.objects.filter(
                id=p_permanence_board_id,
                customer__isnull=True,
                permanence__status__lte=PERMANENCE_SEND,
                permanence_role__customers_may_register=True
            ).update(
                customer_id=customer.id,
                is_registered_on=timezone.now()
            )
        else:
            row_counter = 0
        if row_counter > 0:
            result = "ok"
    return HttpResponse(result)
示例#13
0
 def queryset(self, request, queryset):
     if self.value():
         permanence_id = sint(self.value(), 0)
         if permanence_id > 0:
             return queryset.filter(permanence_id=permanence_id)
     else:
         return queryset.filter(permanence__status=PERMANENCE_SEND)
     return queryset
示例#14
0
    def get(self, request, *args, **kwargs):
        self.first_page = kwargs.get("page", True)
        permanence_id = sint(kwargs.get("permanence_id", 0))
        self.permanence = (
            Permanence.objects.filter(id=permanence_id)
            .only("id", "status", "permanence_date", "with_delivery_point")
            .order_by("?")
            .first()
        )
        permanence_ok_or_404(self.permanence)
        self.user = request.user
        self.is_basket = self.request.GET.get("is_basket", False)
        self.is_like = self.request.GET.get("is_like", False)
        customer_may_order = (
            Customer.objects.filter(user_id=self.user.id, is_active=True)
            .order_by("?")
            .exists()
        )
        if self.user.is_anonymous or not customer_may_order:
            self.is_anonymous = True
            self.may_order = False
        else:
            self.is_anonymous = False
            customer = self.user.customer
            self.may_order = customer.may_order if customer is not None else False
        self.q = self.request.GET.get("q", None)
        if not self.q:
            self.producer_id = self.request.GET.get("producer", "all")
            if self.producer_id != "all":
                self.producer_id = sint(self.producer_id)
            self.department_id = self.request.GET.get("department", "all")
            if self.department_id != "all":
                self.department_id = sint(self.department_id)
            self.box_id = self.request.GET.get("box", "all")
            if self.box_id != "all":
                self.box_id = sint(self.box_id)
                self.is_box = True
                # Do not display "all department" as selected
                self.department_id = None
        if len(request.GET) == 0:
            # This to let display a communication into a popup when the user is on the first order screen
            self.communication = True
        else:
            self.communication = False

        return super(OrderView, self).get(request, *args, **kwargs)
示例#15
0
 def queryset(self, request, queryset):
     if self.value():
         permanence_id = sint(self.value(), 0)
         if permanence_id > 0:
             return queryset.filter(permanence_id=permanence_id)
     else:
         return queryset.filter(permanence__status=PERMANENCE_SEND)
     return queryset
示例#16
0
def delivery_select_ajax(request):
    if not request.is_ajax():
        raise Http404
    # construct a list which will contain all of the data for the response
    user = request.user
    customer = Customer.objects.filter(
        user_id=user.id, may_order=True
    ).order_by('?').first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    permanence_id = sint(request.GET.get('permanence', 0))
    customer_invoice = CustomerInvoice.objects.filter(
        customer_id=customer.id,
        permanence_id=permanence_id
    ).order_by('?').first()
    if customer_invoice is None:
        raise Http404
    if customer.delivery_point is not None:
        qs = DeliveryBoard.objects.filter(
            Q(
                permanence_id=permanence_id,
                delivery_point_id=customer.delivery_point_id,
                status=PERMANENCE_OPENED
            ) | Q(
                permanence_id=permanence_id,
                delivery_point__customer_responsible__isnull=True,
                status=PERMANENCE_OPENED
            )
        )
    else:
        qs = DeliveryBoard.objects.filter(
            permanence_id=permanence_id,
            delivery_point__customer_responsible__isnull=True,
            status=PERMANENCE_OPENED
        )
    is_selected = False
    delivery_counter = 0
    html = EMPTY_STRING
    # IMPORTANT : Do not limit to delivery.status=PERMANENCE_OPENED to include potentialy closed
    # delivery already selected by the customer
    for delivery in qs:
        if delivery.id == customer_invoice.delivery_id:
            is_selected = True
            html += "<option value=\"{}\" selected>{}</option>".format(delivery.id,
                                                                       delivery.get_delivery_customer_display())
        elif delivery.status == PERMANENCE_OPENED and customer_invoice.status == PERMANENCE_OPENED:
            delivery_counter += 1
            html += "<option value=\"{}\">{}</option>".format(delivery.id,
                                                              delivery.get_delivery_customer_display())
    if not is_selected:
        if delivery_counter == 0:
            label = "{}".format(_('No delivery point is open for you. You can not place order.'))
        else:
            label = "{}".format(_('Please, select a delivery point'))
        html = "<option value=\"-1\" selected>{}</option>".format(label) + html

    return JsonResponse({"#delivery": mark_safe(html)})
示例#17
0
def repanier_select_task(context, *args, **kwargs):
    request = context['request']
    user = request.user
    result = EMPTY_STRING
    customer_is_active = Customer.objects.filter(
        user_id=user.id, is_active=True).order_by('?').exists()
    if customer_is_active:
        p_task_id = sint(kwargs.get('task_id', 0))
        if p_task_id > 0:
            permanence_board = PermanenceBoard.objects.filter(
                id=p_task_id).select_related(
                    "customer", "permanence_role",
                    "permanence").order_by('?').first()
            if permanence_board is not None:
                if permanence_board.customer is not None:
                    if permanence_board.customer.user_id == user.id and permanence_board.permanence.status <= PERMANENCE_CLOSED:
                        result = """
                        <b><i>
                        <select name="value" id="task{task_id}"
                        onchange="task_ajax({task_id})" class="form-control">
                        <option value="0">---</option>
                        <option value="1" selected>{long_basket_name}</option>
                        </select>
                        </i></b>
                        """.format(
                            task_id=permanence_board.id,
                            long_basket_name=user.customer.long_basket_name)
                    else:
                        result = """
                        <select name="value" id="task{task_id}"
                        class="form-control">
                        <option value="0" selected>{long_basket_name}</option>
                        </select>
                        """.format(task_id=permanence_board.id,
                                   long_basket_name=permanence_board.customer.
                                   long_basket_name)
                else:
                    if permanence_board.permanence_role.customers_may_register:
                        if permanence_board.permanence.status <= PERMANENCE_CLOSED:
                            result = """
                            <b><i>
                            <select name="value" id="task{task_id}"
                            onchange="task_ajax({task_id})" class="form-control">
                            <option value="0" selected>---</option>
                            <option value="1">{long_basket_name}</option>
                            </select>
                            </i></b>
                            """.format(task_id=permanence_board.id,
                                       long_basket_name=user.customer.
                                       long_basket_name)
                        else:
                            result = """
                            <select name="value" id="task{task_id}"
                            class="form-control">
                            <option value="0" selected>---</option>
                            </select>
                            """.format(task_id=permanence_board.id)
    return mark_safe(result)
示例#18
0
 def get(self, request, *args, **kwargs):
     self.first_page = kwargs.get('page', True)
     permanence_id = sint(kwargs.get('permanence_id', 0))
     self.permanence = Permanence.objects.filter(id=permanence_id).only(
         "id", "status", "permanence_date",
         "with_delivery_point").order_by('?').first()
     permanence_ok_or_404(self.permanence)
     self.user = request.user
     self.is_basket = self.request.GET.get('is_basket', False)
     self.is_like = self.request.GET.get('is_like', False)
     customer_may_order = Customer.objects.filter(
         user_id=self.user.id, is_active=True).order_by('?').exists()
     if self.user.is_anonymous or not customer_may_order:
         self.is_anonymous = True
         self.may_order = False
     else:
         self.is_anonymous = False
         customer = self.user.customer
         self.may_order = customer.may_order if customer is not None else False
     self.q = self.request.GET.get('q', None)
     self.producer_id = self.request.GET.get('producer', 'all')
     if self.producer_id != 'all':
         self.producer_id = sint(self.producer_id)
     self.departementforcustomer_id = self.request.GET.get(
         'departementforcustomer', 'all')
     if self.departementforcustomer_id != 'all':
         self.departementforcustomer_id = sint(
             self.departementforcustomer_id)
     self.box_id = self.request.GET.get('box', 'all')
     if self.box_id != 'all':
         self.box_id = sint(self.box_id)
         self.is_box = True
         # Do not display "all department" as selected
         self.departementforcustomer_id = None
     else:
         self.is_box = False
     if self.producer_id == 'all' and self.departementforcustomer_id == 'all' \
             and not self.is_basket and 'page' not in request.GET \
             and self.q is None:
         # This to let display a communication into a popup when the user is on the first order screen
         self.communication = True
     else:
         self.communication = False
     return super(OrderView, self).get(request, *args, **kwargs)
示例#19
0
def order_description_view(request, permanence_id):
    user = request.user
    customer = Customer.objects.filter(
        user_id=user.id, may_order=True).order_by('?').first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    permanence = Permanence.objects.filter(id=permanence_id).order_by('?').first()
    permanence_ok_or_404(permanence)
    is_basket = request.GET.get('is_basket', EMPTY_STRING)
    is_like = request.GET.get('is_like', EMPTY_STRING)
    if permanence.contract is not None:
        all_dates = permanence.contract.all_dates
        len_all_dates = len(all_dates)
        if len_all_dates < 2:
            date_id = 'all'
        else:
            date_id = sint(request.GET.get('date'), -1)
            if date_id < 0 or date_id >= len_all_dates:
                date_id = 'all'
    else:
        all_dates = []
        date_id = 'all'
    producer_id = request.GET.get('producer', 'all')
    department_id = request.GET.get('department', 'all')
    box_id = request.GET.get('box', 'all')
    if box_id != 'all':
        is_box = True
        # Do not display "all department" as selected
        department_id = None
    else:
        is_box = False
    q = request.GET.get('q', None)

    template_name = get_repanier_template_name("order_description.html")
    return render(
        request, template_name,
        {
            'is_like': is_like,
            'is_basket': is_basket,
            'is_box': is_box,
            'q': q,
            'all_dates': all_dates,

            'date_id': date_id,
            'producer_id': producer_id,
            'department_id': department_id,
            'box_id': box_id,
            'permanence_id': permanence_id,
            'may_order': True,

            'permanence': permanence,

            'is_description_view': 'active'
        }
    )
示例#20
0
 def changelist_view(self, request, extra_context=None):
     # Important : Needed to pass contract to product.get_html_is_into_offer() in the list_display of 'get_html_is_into_offer'
     # and in 'deselect_is_into_offer'
     if settings.REPANIER_SETTINGS_CONTRACT:
         contract_id = sint(request.GET.get('commitment', 0))
         contract = Contract.objects.filter(id=contract_id).order_by('?').first()
     else:
         contract = None
     self._contract = contract
     return super(ProductAdmin, self).changelist_view(request, extra_context=extra_context)
示例#21
0
def repanier_html_permanence_title(*args, **kwargs):
    result = EMPTY_STRING
    p_permanence_id = sint(kwargs.get('permanence_id', 0))
    if p_permanence_id > 0:
        permanence = Permanence.objects.filter(id=p_permanence_id).order_by('?').first()
        if permanence is not None:
            result = permanence.get_html_permanence_title_display()
        else:
            result = EMPTY_STRING
    return result
示例#22
0
 def changelist_view(self, request, extra_context=None):
     # Important : Needed to pass contract to product.get_html_is_into_offer() in the list_display of 'get_html_is_into_offer'
     # and in 'deselect_is_into_offer'
     if settings.REPANIER_SETTINGS_CONTRACT:
         contract_id = sint(request.GET.get('commitment', 0))
         contract = Contract.objects.filter(id=contract_id).order_by('?').first()
     else:
         contract = None
     self._contract = contract
     return super(ProductAdmin, self).changelist_view(request, extra_context=extra_context)
示例#23
0
def repanier_html_permanence_title(*args, **kwargs):
    result = EMPTY_STRING
    p_permanence_id = sint(kwargs.get("permanence_id", 0))
    if p_permanence_id > 0:
        permanence = Permanence.objects.filter(id=p_permanence_id).order_by("?").first()
        if permanence is not None:
            result = permanence.get_html_permanence_title_display()
        else:
            result = EMPTY_STRING
    return result
示例#24
0
def is_into_offer(request, product_id, contract_id):
    if request.is_ajax():
        user = request.user
        if user.is_order_manager:
            product_id = sint(product_id)
            product = Product.objects.filter(
                id=product_id).order_by('?').first()
            if product is not None:
                contract_id = sint(contract_id)
                contract = None
                contract_content = None
                if contract_id > 0:
                    contract = Contract.objects.filter(
                        id=contract_id).order_by('?').first()
                    if contract is not None:
                        contract_content = ContractContent.objects.filter(
                            product_id=product_id,
                            contract_id=contract_id).order_by('?').first()
                        if contract_content is None:
                            contract_content = ContractContent.objects.create(
                                contract_id=contract_id,
                                product_id=product_id,
                                permanences_dates=contract.permanences_dates,
                                flexible_dates=product.order_unit >
                                PRODUCT_ORDER_UNIT_DEPOSIT)
                        else:
                            if contract_content.permanences_dates is not None:
                                contract_content.permanences_dates = None
                                contract_content.not_permanences_dates = contract.permanences_dates
                            else:
                                contract_content.permanences_dates = contract.permanences_dates
                                contract_content.not_permanences_dates = None
                            contract_content.save(update_fields=[
                                'permanences_dates', 'not_permanences_dates'
                            ])
                else:
                    product.is_into_offer = not product.is_into_offer
                    product.save(update_fields=['is_into_offer'])
                return HttpResponse(
                    product.get_html_is_into_offer(
                        contract=contract, contract_content=contract_content))
    raise Http404
示例#25
0
def btn_confirm_order_ajax(request):
    if not request.is_ajax():
        raise Http404
    permanence_id = sint(request.GET.get('permanence', 0))
    user = request.user
    if not user.is_authenticated():
        raise Http404
    customer = Customer.objects.filter(
        user_id=user.id, is_active=True, may_order=True).order_by('?').first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    permanence = Permanence.objects.filter(id=permanence_id).order_by('?').first()
    if permanence is None:
        raise Http404
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence_id,
        customer_id=customer.id,
        is_order_confirm_send=False,
        total_price_with_tax__gt=DECIMAL_ZERO
    ).order_by('?')
    if not customer_invoice.exists():
        raise Http404
    filename = "{0}-{1}.xlsx".format(
        slugify(_("Order")),
        slugify(permanence)
    )
    sender_email, sender_function, signature, cc_email_staff = get_signature(
        is_reply_to_order_email=True)
    export_order_2_1_customer(
        customer, filename, permanence, sender_email,
        sender_function, signature
    )
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence_id,
        customer_id=customer.id
    ).order_by('?').first()
    customer_invoice.confirm_order()
    customer_invoice.save()
    to_json = []
    my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax(), to_json)
    basket_message = calc_basket_message(
        customer,
        permanence,
        PERMANENCE_CLOSED
    )
    my_order_confirmation(
        permanence=permanence,
        customer_invoice=customer_invoice,
        is_basket=True,
        basket_message=basket_message,
        to_json=to_json
    )
    return HttpResponse(json.dumps(to_json, cls=DjangoJSONEncoder), content_type="application/json")
示例#26
0
 def get_list_display(self, request):
     producer_id = sint(request.GET.get('producer', 0))
     if producer_id != 0:
         producer_queryset = Producer.objects.filter(
             id=producer_id).order_by('?')
         producer = producer_queryset.first()
     else:
         producer = None
     permanence_id = sint(request.GET.get('permanence', 0))
     permanence_open = False
     permanence = Permanence.objects.filter(
         id=permanence_id, status=PERMANENCE_OPENED).order_by('?')
     if permanence.exists():
         permanence_open = True
     if producer is not None:
         self.list_editable = ('stock', )
         if producer.manage_replenishment:
             if permanence_open:
                 return ('department_for_customer', 'producer',
                         'get_long_name', 'stock',
                         'get_html_producer_qty_stock_invoiced')
             else:
                 return ('department_for_customer', 'producer',
                         'get_long_name', 'stock',
                         'get_html_producer_qty_stock_invoiced',
                         'add_2_stock')
         elif producer.represent_this_buyinggroup:
             if settings.DJANGO_SETTINGS_IS_MINIMALIST:
                 return ('department_for_customer', 'producer',
                         'get_long_name',
                         'get_html_producer_qty_stock_invoiced')
             else:
                 return ('department_for_customer', 'producer',
                         'get_long_name', 'stock',
                         'get_html_producer_qty_stock_invoiced')
         else:
             return ('department_for_customer', 'producer', 'get_long_name',
                     'get_html_producer_qty_stock_invoiced')
     else:
         return ('department_for_customer', 'producer', 'get_long_name',
                 'get_html_producer_qty_stock_invoiced')
示例#27
0
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, SIZE_L]:
            msg = "%s" % _('Wrong picture size.')
            data = json.dumps({'error': msg})
            return HttpResponse(data, content_type="application/json", status=403)

        disk = os.statvfs(settings.MEDIA_ROOT)
        if disk.f_blocks > 0 and ((disk.f_bfree + 1.0) / disk.f_blocks) < 0.2:
            msg = "%s" % _('Please, contact the administrator of the webserver : There is not enough disk space.')
            data = json.dumps({'error': msg})
            return HttpResponse(data, content_type="application/json", status=403)
        file_ = form.cleaned_data['file']

        image_types = ['image/png', 'image/jpg', 'image/jpeg', 'image/pjpeg',
                       'image/gif']

        if file_.content_type not in image_types:
            msg = "%s" % _('The system does not recognize the format.')
            data = json.dumps({'error': msg})
            return HttpResponse(data, content_type="application/json", status=403)

        file_name, extension = os.path.splitext(file_.name)
        safe_name = '{0}{1}'.format(slugify(file_name), extension)
        name = os.path.join(upload_to or "tmp", safe_name)

        if default_storage.exists(name):
            msg = "%s" % _(
                 'A picture with the same file name already exist. This picture will not replace it.'
            )
            return HttpResponse(
                json.dumps(
                    {'url'     : default_storage.url(name),
                     'filename': name,
                     'msg'     : msg
                     }
                ), content_type="application/json")
        else:
            image = Image.open(file_)
            if image.size[0] > size or image.size[1] > size:
                msg = "%s" % _('The file size is too big.')
                return HttpResponse(json.dumps({'error': msg}), content_type="application/json",
                                    status=403)
            file_name = default_storage.save(name, image.fp)
            url = default_storage.url(file_name)
            return HttpResponse(
                json.dumps(
                    {'url': url, 'filename': file_name}
                ), content_type="application/json")

    return HttpResponse(status=403)
示例#28
0
def is_into_offer(request, product_id):
    if request.is_ajax():
        user = request.user
        if user.is_order_manager:
            product_id = sint(product_id)
            product = Product.objects.filter(
                id=product_id).order_by("?").first()
            if product is not None:
                product.is_into_offer = not product.is_into_offer
                product.save(update_fields=["is_into_offer"])
                return HttpResponse(product.get_html_is_into_offer())
    raise Http404
示例#29
0
def delivery_select_ajax(request):
    if not request.is_ajax():
        raise Http404
    # construct a list which will contain all of the data for the response
    user = request.user
    customer = Customer.objects.filter(user_id=user.id,
                                       may_order=True).order_by('?').first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    permanence_id = sint(request.GET.get('permanence', 0))
    customer_invoice = CustomerInvoice.objects.filter(
        customer_id=customer.id,
        permanence_id=permanence_id).order_by('?').first()
    if customer_invoice is None:
        raise Http404
    if customer.delivery_point is not None:
        qs = DeliveryBoard.objects.filter(
            Q(permanence_id=permanence_id,
              delivery_point_id=customer.delivery_point_id,
              status=PERMANENCE_OPENED)
            | Q(permanence_id=permanence_id,
                delivery_point__customer_responsible__isnull=True,
                status=PERMANENCE_OPENED))
    else:
        qs = DeliveryBoard.objects.filter(
            permanence_id=permanence_id,
            delivery_point__customer_responsible__isnull=True,
            status=PERMANENCE_OPENED)
    is_selected = False
    delivery_counter = 0
    html = EMPTY_STRING
    # IMPORTANT : Do not limit to delivery.status=PERMANENCE_OPENED to include potentialy closed
    # delivery already selected by the customer
    for delivery in qs:
        if delivery.id == customer_invoice.delivery_id:
            is_selected = True
            html += "<option value=\"{}\" selected>{}</option>".format(
                delivery.id, delivery.get_delivery_customer_display())
        elif delivery.status == PERMANENCE_OPENED and customer_invoice.status == PERMANENCE_OPENED:
            delivery_counter += 1
            html += "<option value=\"{}\">{}</option>".format(
                delivery.id, delivery.get_delivery_customer_display())
    if not is_selected:
        if delivery_counter == 0:
            label = "{}".format(
                _('No delivery point is open for you. You can not place order.'
                  ))
        else:
            label = "{}".format(_('Please, select a delivery point'))
        html = "<option value=\"-1\" selected>{}</option>".format(label) + html

    return JsonResponse({"#delivery": mark_safe(html)})
def customer_product_description_ajax(request):
    if request.is_ajax():
        offer_item_id = sint(request.GET.get('offer_item', 0))
        offer_item = get_object_or_404(OfferItem, id=offer_item_id)
        permanence = offer_item.permanence
        permanence_ok_or_404(permanence)
        if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND:
            html = render_to_string(
                template_order_product_description,
                {'offer': offer_item, 'MEDIA_URL': settings.MEDIA_URL}
            )
            return JsonResponse({"#orderModal": mark_safe(html)})
    raise Http404
示例#31
0
def repanier_display_task(*args, **kwargs):
    result = EMPTY_STRING
    p_permanence_board_id = sint(kwargs.get('permanence_board_id', 0))
    if p_permanence_board_id > 0:
        permanence_board = PermanenceBoard.objects.filter(id=p_permanence_board_id).select_related(
            "permanence_role"
        ).order_by('?').first()
        if permanence_board is not None:
            if permanence_board.permanence_role.customers_may_register:
                result = permanence_board.permanence_role
            else:
                result = '<p><b>%s</b></p>' % (permanence_board.permanence_role,)
    return mark_safe(result)
示例#32
0
def customer_product_description_ajax(request):
    if request.is_ajax():
        offer_item_id = sint(request.GET.get('offer_item', 0))
        offer_item = get_object_or_404(OfferItem, id=offer_item_id)
        permanence = offer_item.permanence
        permanence_ok_or_404(permanence)
        if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND:
            html = render_to_string(template_order_product_description, {
                'offer': offer_item,
                'MEDIA_URL': settings.MEDIA_URL
            })
            return JsonResponse({"#orderModal": mark_safe(html)})
    raise Http404
示例#33
0
def is_into_offer(request, product_id, contract_id):
    if request.is_ajax():
        user = request.user
        if user.is_order_manager:
            product_id = sint(product_id)
            product = Product.objects.filter(id=product_id).order_by('?').first()
            if product is not None:
                contract_id = sint(contract_id)
                contract = None
                contract_content = None
                if contract_id > 0:
                    contract = Contract.objects.filter(id=contract_id).order_by('?').first()
                    if contract is not None:
                        contract_content = ContractContent.objects.filter(
                            product_id=product_id,
                            contract_id=contract_id
                        ).order_by('?').first()
                        if contract_content is None:
                            contract_content = ContractContent.objects.create(
                                contract_id=contract_id,
                                product_id=product_id,
                                permanences_dates=contract.permanences_dates,
                                flexible_dates=product.order_unit > PRODUCT_ORDER_UNIT_DEPOSIT
                            )
                        else:
                            if contract_content.permanences_dates is not None:
                                contract_content.permanences_dates = None
                                contract_content.not_permanences_dates = contract.permanences_dates
                            else:
                                contract_content.permanences_dates = contract.permanences_dates
                                contract_content.not_permanences_dates = None
                            contract_content.save(update_fields=['permanences_dates', 'not_permanences_dates'])
                else:
                    product.is_into_offer = not product.is_into_offer
                    product.save(update_fields=['is_into_offer'])
                return HttpResponse(
                    product.get_html_is_into_offer(contract=contract, contract_content=contract_content))
    raise Http404
示例#34
0
 def clean_product(self):
     product_id = sint(self.cleaned_data.get("product"), 0)
     if product_id <= 0:
         if product_id == -1:
             self.add_error(
                 'product',
                 _("Please select first a producer in the filter of previous screen")
             )
         else:
             self.add_error(
                 'product',
                 _("No more product to add. Please update a product of previous screen")
             )
     return product_id
示例#35
0
 def clean_product(self):
     product_id = sint(self.cleaned_data.get("product"), 0)
     if product_id <= 0:
         if product_id == -1:
             self.add_error(
                 'product',
                 _("Please select first a producer in the filter of previous screen")
             )
         else:
             self.add_error(
                 'product',
                 _("No more product to add. Please update a product of previous screen")
             )
     return product_id
示例#36
0
def repanier_display_task(*args, **kwargs):
    result = EMPTY_STRING
    p_task_id = sint(kwargs.get('task_id', 0))
    if p_task_id > 0:
        permanence_board = PermanenceBoard.objects.filter(
            id=p_task_id).select_related("permanence_role").order_by(
                '?').first()
        if permanence_board is not None:
            if permanence_board.permanence_role.customers_may_register:
                result = permanence_board.permanence_role
            else:
                result = "<p><b>{}</b></p>".format(
                    permanence_board.permanence_role)
    return mark_safe(result)
示例#37
0
def flexible_dates(request, product_id, contract_id):
    if request.is_ajax():
        user = request.user
        if user.is_order_manager:
            product_id = sint(product_id)
            product = Product.objects.filter(
                id=product_id).order_by('?').first()
            if product is not None:
                contract_id = sint(contract_id)
                contract = None
                contract_content = None
                if contract_id > 0:
                    contract = Contract.objects.filter(
                        id=contract_id).order_by('?').first()
                    if contract is not None:
                        contract_content = ContractContent.objects.filter(
                            product_id=product_id,
                            contract_id=contract_id).order_by('?').first()
                        if contract_content is not None:
                            if product.order_unit > PRODUCT_ORDER_UNIT_DEPOSIT:
                                contract_content.flexible_dates = True
                            else:
                                contract_content.flexible_dates = not (
                                    contract_content.flexible_dates)
                            contract_content.save(
                                update_fields=["flexible_dates"])
                        # else:
                        #     contract_content = ContractContent.objects.create(
                        #         contract_id=contract_id,
                        #         product_id=product_id,
                        #     )
                        #     contract_content.all_dates = contract.all_dates
                        #     contract_content.save()
                return HttpResponse(
                    product.get_html_is_into_offer(
                        contract=contract, contract_content=contract_content))
    raise Http404
示例#38
0
def btn_confirm_order_ajax(request):
    if not request.is_ajax():
        raise Http404
    permanence_id = sint(request.GET.get('permanence', 0))
    user = request.user
    customer = Customer.objects.filter(user_id=user.id,
                                       is_active=True,
                                       may_order=True).order_by('?').first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    permanence = Permanence.objects.filter(
        id=permanence_id).order_by('?').first()
    if permanence is None:
        raise Http404
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence_id,
        customer_id=customer.id,
        is_order_confirm_send=False,
        is_group=False,
        # total_price_with_tax__gt=DECIMAL_ZERO
        purchase__quantity_ordered__gt=DECIMAL_ZERO,
    ).order_by('?')
    if not customer_invoice.exists():
        raise Http404
    filename = "{0}-{1}.xlsx".format(slugify(_("Order")), slugify(permanence))
    sender_email, sender_function, signature, cc_email_staff = get_signature(
        is_reply_to_order_email=True)
    export_order_2_1_customer(customer, filename, permanence, sender_email,
                              sender_function, signature)
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence_id,
        customer_id=customer.id).order_by('?').first()
    customer_invoice.confirm_order()
    customer_invoice.save()
    to_json = []
    my_basket(customer_invoice.is_order_confirm_send,
              customer_invoice.get_total_price_with_tax(), to_json)
    if customer_invoice.delivery is not None:
        status = customer_invoice.delivery.status
    else:
        status = customer_invoice.status
    basket_message = calc_basket_message(customer, permanence, status)
    customer_invoice.my_order_confirmation(permanence=permanence,
                                           is_basket=True,
                                           basket_message=basket_message,
                                           to_json=to_json)
    return HttpResponse(json.dumps(to_json, cls=DjangoJSONEncoder),
                        content_type="application/json")
示例#39
0
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]:
            data = json.dumps({'error': _not_lazy('Wrong size.')})
            return HttpResponse(data, content_type="application/json", status=403)

        disk = os.statvfs(settings.MEDIA_ROOT)
        if disk.f_blocks > 0 and ((disk.f_bfree + 1.0) / disk.f_blocks) < 0.2:
            data = json.dumps({'error': _not_lazy(
                'Please, contact the administrator of the webserver : There is not enough disk space.')})
            return HttpResponse(data, content_type="application/json", status=403)
        file_ = form.cleaned_data['file']

        image_types = ['image/png', 'image/jpg', 'image/jpeg', 'image/pjpeg',
                       'image/gif']

        if file_.content_type not in image_types:
            data = json.dumps({'error': _not_lazy('The system does not recognize the format.')})
            return HttpResponse(data, content_type="application/json", status=403)

        file_name, extension = os.path.splitext(file_.name)
        safe_name = '{0}{1}'.format(slugify(file_name), extension)
        name = os.path.join(upload_to or "tmp", safe_name)

        if default_storage.exists(name):
            return HttpResponse(
                json.dumps(
                    {'url'     : default_storage.url(name),
                     'filename': name,
                     'msg'     : _not_lazy(
                         'An image with same file name already exist. Please, check the file name and rename it if necessary.')
                     }
                ), content_type="application/json")
        else:
            image = Image.open(file_)
            if image.size[0] > size or image.size[1] > size:
                return HttpResponse(json.dumps({'error': _not_lazy('Wrong size.')}), content_type="application/json",
                                    status=403)

        file_name = default_storage.save(name, image.fp)
        url = default_storage.url(file_name)

        return HttpResponse(json.dumps({'url': url, 'filename': file_name}), content_type="application/json")

    return HttpResponse(status=403)
示例#40
0
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, SIZE_L]:
            msg = "{}".format(_('Wrong picture size.'))
            return JsonResponse({'error': msg}, status=403)

        disk = os.statvfs(settings.MEDIA_ROOT)
        if disk.f_blocks > 0 and ((disk.f_bfree + 1.0) / disk.f_blocks) < 0.2:
            msg = "{}".format(_('Please, contact the administrator of the webserver : There is not enough disk space.'))
            return JsonResponse({'error': msg}, status=403)
        file_ = form.cleaned_data['file']

        image_types = ['image/png', 'image/jpg', 'image/jpeg', 'image/pjpeg',
                       'image/gif']

        if file_.content_type not in image_types:
            msg = "{}".format(_('The system does not recognize the format.'))
            return JsonResponse({'error': msg}, status=403)

        file_name, extension = os.path.splitext(file_.name)
        safe_name = '{}{}'.format(slugify(file_name), extension)
        name = os.path.join(upload_to or "tmp", safe_name)

        if default_storage.exists(name):
            msg = "{}".format(_(
                'A picture with the same file name already exist. This picture will not replace it.'
            ))
            return JsonResponse(
                {'url': default_storage.url(name),
                 'filename': name,
                 'msg': msg
                 }
            )
        else:
            image = Image.open(file_)
            if image.size[0] > size or image.size[1] > size:
                msg = "{}".format(_('The file size is too big.'))
                return JsonResponse({'error': msg}, status=403)
            file_name = default_storage.save(name, image.fp)
            url = default_storage.url(file_name)
            return JsonResponse({'url': url, 'filename': file_name})

    return HttpResponse(status=403)
示例#41
0
def btn_confirm_order_ajax(request):
    if not request.is_ajax():
        raise Http404
    user = request.user
    customer = Customer.objects.filter(
        user_id=user.id, may_order=True).order_by('?').first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    permanence_id = sint(request.GET.get('permanence', 0))
    permanence = Permanence.objects.filter(id=permanence_id).order_by('?').first()
    permanence_ok_or_404(permanence)
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence_id,
        customer_id=customer.id,
        is_order_confirm_send=False,
        is_group=False,
    ).order_by('?').first()
    if customer_invoice is None:
        raise Http404
    filename = "{}-{}.xlsx".format(
        _("Order"),
        permanence
    )
    export_order_2_1_customer(customer, filename, permanence)
    customer_invoice.confirm_order()
    customer_invoice.save()
    json_dict = my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax())
    if customer_invoice.delivery is not None:
        status = customer_invoice.delivery.status
    else:
        status = customer_invoice.status
    basket_message = get_html_basket_message(
        customer,
        permanence,
        status
    )
    json_dict.update(customer_invoice.get_html_my_order_confirmation(
        permanence=permanence,
        is_basket=True,
        basket_message=basket_message
    ))
    return JsonResponse(json_dict)
def customer_product_description_ajax(request):
    if request.is_ajax():
        offer_item_id = sint(request.GET.get("offer_item", 0))
        offer_item = get_object_or_404(OfferItem, id=offer_item_id)
        permanence = offer_item.permanence
        permanence_ok_or_404(permanence)
        if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND:
            try:
                result = offer_item.cache_part_e
                result = html_box_content(offer_item, request.user, result)

                if result is None or result == EMPTY_STRING:
                    result = "%s" % _("There is no more product's information")
            except TranslationDoesNotExist:
                result = "%s" % _("There is no more product's information")
        else:
            result = "%s" % _("There is no more product's information")
        return HttpResponse(result)
    raise Http404
示例#43
0
文件: product.py 项目: CenaZ/repanier
    def get_list_display(self, request):
        producer_id = sint(request.GET.get('producer', 0))
        if producer_id != 0:
            producer_queryset = Producer.objects.filter(
                id=producer_id).order_by('?')
            producer = producer_queryset.first()
        else:
            producer = None

        list_display = [
            'get_is_into_offer',
            '__str__',
        ]
        list_editable = [
            'producer_unit_price',
        ]
        if settings.DJANGO_SETTINGS_MULTIPLE_LANGUAGE:
            list_display += [
                'language_column',
            ]
        list_display += ['producer_unit_price']
        if not settings.DJANGO_SETTINGS_IS_MINIMALIST:
            list_display += [
                'get_customer_alert_order_quantity',
            ]
        if producer is not None:
            if producer.producer_pre_opening or producer.manage_replenishment:
                list_display += [
                    'stock',
                ]
                list_editable += [
                    'stock',
                ]
            elif not settings.DJANGO_SETTINGS_IS_MINIMALIST and producer.represent_this_buyinggroup:
                list_display += [
                    'stock',
                ]
                list_editable += [
                    'stock',
                ]
        self.list_editable = list_editable
        return list_display
示例#44
0
def like_ajax(request):
    if request.is_ajax():
        user = request.user
        if user.is_authenticated:
            offer_item_id = sint(request.GET.get('offer_item', 0))
            offer_item = OfferItem.objects.filter(id=offer_item_id).order_by('?').first()
            if offer_item is not None and offer_item.product_id is not None:
                product = offer_item.product
                to_json = []
                if product.likes.filter(id=user.id).exists():
                    # user has already liked this company
                    # remove like/user
                    product.likes.remove(user)
                else:
                    # add a new like for a company
                    product.likes.add(user)
                option_dict = {'id': ".btn_like%s" % offer_item_id, 'html': offer_item.get_like(user)}
                to_json.append(option_dict)
                return HttpResponse(json.dumps(to_json, cls=DjangoJSONEncoder), content_type="application/json")
    raise Http404
示例#45
0
def like_ajax(request):
    if request.is_ajax():
        user = request.user
        if user.is_authenticated():
            offer_item_id = sint(request.GET.get("offer_item", 0))
            offer_item = OfferItem.objects.filter(id=offer_item_id).order_by("?").select_related("product").first()
            if offer_item is not None:
                product = offer_item.product
                to_json = []
                if product.likes.filter(id=user.id).exists():
                    # user has already liked this company
                    # remove like/user
                    product.likes.remove(user)
                else:
                    # add a new like for a company
                    product.likes.add(user)
                option_dict = {"id": ".btn_like%s" % offer_item_id, "html": offer_item.get_like(user)}
                to_json.append(option_dict)
                return HttpResponse(json.dumps(to_json, cls=DjangoJSONEncoder), content_type="application/json")
    raise Http404
示例#46
0
def like_ajax(request):
    if request.is_ajax():
        user = request.user
        if user.is_authenticated:
            offer_item_id = sint(request.GET.get("offer_item", 0))
            offer_item = (OfferItemWoReceiver.objects.filter(
                id=offer_item_id).order_by("?").first())
            if offer_item is not None and offer_item.product_id is not None:
                product = offer_item.product
                json_dict = {}
                if product.likes.filter(id=user.id).exists():
                    # user has already liked this company
                    # remove like/user
                    product.likes.remove(user)
                else:
                    # add a new like for a company
                    product.likes.add(user)
                like_html = offer_item.get_html_like(user)
                json_dict[".btn_like{}".format(offer_item.id)] = like_html
                return JsonResponse(json_dict)
    raise Http404
def customer_product_description_ajax(request):
    if request.is_ajax():
        offer_item_id = sint(request.GET.get('offer_item', 0))
        offer_item = get_object_or_404(OfferItem, id=offer_item_id)
        permanence = offer_item.permanence
        permanence_ok_or_404(permanence)
        if PERMANENCE_OPENED <= permanence.status <= PERMANENCE_SEND:
            offer_item.long_name = offer_item.product.long_name
            result = html_box_content(
                offer_item, request.user,
                render_to_string('repanier/cache_part_e.html', {
                    'offer': offer_item,
                    'MEDIA_URL': settings.MEDIA_URL
                }))

            if result is None or result == EMPTY_STRING:
                result = "%s" % _("There is no more product's information")
        else:
            result = "%s" % _("There is no more product's information")
        return HttpResponse(result)
    raise Http404
def btn_confirm_order_ajax(request):
    if not request.is_ajax():
        raise Http404
    user = request.user
    customer = Customer.objects.filter(user_id=user.id,
                                       may_order=True).order_by('?').first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    permanence_id = sint(request.GET.get('permanence', 0))
    permanence = Permanence.objects.filter(
        id=permanence_id).order_by('?').first()
    if permanence is None:
        raise Http404
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence_id,
        customer_id=customer.id,
        is_order_confirm_send=False,
        is_group=False,
    ).order_by('?').first()
    if customer_invoice is None:
        raise Http404
    filename = "{0}-{1}.xlsx".format(_("Order"), permanence)
    export_order_2_1_customer(customer, filename, permanence)
    customer_invoice.confirm_order()
    customer_invoice.save()
    json_dict = my_basket(customer_invoice.is_order_confirm_send,
                          customer_invoice.get_total_price_with_tax())
    if customer_invoice.delivery is not None:
        status = customer_invoice.delivery.status
    else:
        status = customer_invoice.status
    basket_message = get_html_basket_message(customer, permanence, status)
    json_dict.update(
        customer_invoice.get_html_my_order_confirmation(
            permanence=permanence,
            is_basket=True,
            basket_message=basket_message))
    return JsonResponse(json_dict)
示例#49
0
def test_mail_config_ajax(request):
    from repanier.apps import REPANIER_SETTINGS_CONFIG
    config = REPANIER_SETTINGS_CONFIG
    html_id = request.POST.get("id", EMPTY_STRING)
    email_host = request.POST.get("id_email_host", EMPTY_STRING)
    email_port = sint(request.POST.get("id_email_port", EMPTY_STRING), 0)
    email_use_tls = request.POST.get("id_email_use_tls", "false") == "true"
    email_host_user = request.POST.get("id_email_host_user", EMPTY_STRING)
    email_host_password = request.POST.get("id_new_email_host_password",
                                           EMPTY_STRING)
    to_email = request.user.email
    if not email_host_password:
        email_host_password = config.email_host_password

    # Send test email
    email_send = send_test_email(host=email_host,
                                 port=email_port,
                                 host_user=email_host_user,
                                 host_password=email_host_password,
                                 use_tls=email_use_tls,
                                 to_email=to_email)
    if not email_send:
        json_dict = {
            "#{}".format(html_id):
            _("This mail server configuration did not allow to send mail. Retry to validate ?"
              )
        }

    else:
        json_dict = {
            "#{}".format(html_id):
            _("This mail server configuration is valid. An email has been sent to {} and to {}."
              ).format(email_host_user, to_email)
        }

    return JsonResponse(json_dict)
示例#50
0
def repanier_select_task(context, *args, **kwargs):
    request = context['request']
    user = request.user
    result = EMPTY_STRING
    if user.is_staff or user.is_superuser:
        pass
    else:
        p_permanence_board_id = sint(kwargs.get('permanence_board_id', 0))
        if p_permanence_board_id > 0:
            permanence_board = PermanenceBoard.objects.filter(id=p_permanence_board_id).select_related(
                "customer", "permanence_role", "permanence"
            ).order_by('?').first()
            if permanence_board is not None:
                if permanence_board.customer is not None:
                    if permanence_board.customer.user_id == user.id and permanence_board.permanence.status <= PERMANENCE_CLOSED:
                        result = """
                        <b><i>
                        <select name="value" id="permanence_board{permanence_board_id}"
                        onchange="permanence_board_ajax({permanence_board_id})" class="form-control">
                        <option value="0">---</option>
                        <option value="1" selected>{long_basket_name}</option>
                        </select>
                        </i></b>
                        """.format(
                            permanence_board_id=permanence_board.id,
                            long_basket_name=user.customer.long_basket_name
                        )
                    else:
                        result = """
                        <select name="value" id="permanence_board{permanence_board_id}"
                        class="form-control">
                        <option value="0" selected>{long_basket_name}</option>
                        </select>
                        """.format(
                            permanence_board_id=permanence_board.id,
                            long_basket_name=permanence_board.customer.long_basket_name
                        )
                else:
                    if permanence_board.permanence_role.customers_may_register:
                        if permanence_board.permanence.status <= PERMANENCE_CLOSED:
                            result = """
                            <b><i>
                            <select name="value" id="permanence_board{permanence_board_id}"
                            onchange="permanence_board_ajax({permanence_board_id})" class="form-control">
                            <option value="0" selected>---</option>
                            <option value="1">{long_basket_name}</option>
                            </select>
                            </i></b>
                            """.format(
                                permanence_board_id=permanence_board.id,
                                long_basket_name=user.customer.long_basket_name
                            )
                        else:
                            result = """
                            <select name="value" id="permanence_board{permanence_board_id}"
                            class="form-control">
                            <option value="0" selected>---</option>
                            </select>
                            """.format(
                                permanence_board_id=permanence_board.id
                            )
    return mark_safe(result)
示例#51
0
def order_init_ajax(request):
    if request.is_ajax():
        # construct a list which will contain all of the data for the response
        permanence_id = sint(request.GET.get('pe', 0))
        permanence_qs = Permanence.objects.filter(id=permanence_id) \
            .only("id", "status", "with_delivery_point").order_by('?')
        if not permanence_qs.exists():
            raise Http404
        user = request.user
        to_json = []
        if user.is_authenticated():
            permanence = permanence_qs.prefetch_related("producers").first()
            customer = Customer.objects.filter(
                user_id=user.id, is_active=True
            ).only(
                "id", "vat_id", "short_basket_name", "email2", "delivery_point",
                "balance", "date_balance", "may_order"
            ).order_by('?').first()
            if customer is None:
                my_basket(False, REPANIER_MONEY_ZERO, to_json)
            else:
                customer_invoice = CustomerInvoice.objects.filter(
                    permanence_id=permanence.id,
                    customer_id=customer.id
                ).order_by('?').first()
                if customer_invoice is None:
                    customer_invoice = CustomerInvoice.objects.create(
                        permanence_id=permanence.id,
                        customer_id=customer.id,
                        status=permanence.status,
                        customer_who_pays_id=customer.id,
                    )
                    customer_invoice.set_delivery(delivery=None)
                    customer_invoice.save()
                if customer_invoice is None:
                    raise Http404
                my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax(), to_json)
                if customer.balance.amount < 0:
                    my_balance = _('My balance : <font color="red">%(balance)s</font> at %(date)s') % {
                        'balance': customer.balance,
                        'date'   : customer.date_balance.strftime(settings.DJANGO_SETTINGS_DATE)}
                else:
                    my_balance = _('My balance : <font color="green">%(balance)s</font> at %(date)s') % {
                        'balance': customer.balance,
                        'date'   : customer.date_balance.strftime(settings.DJANGO_SETTINGS_DATE)}
                option_dict = {'id': "#my_balance", 'html': my_balance}
                to_json.append(option_dict)
                basket = sboolean(request.GET.get('ba', False))
                from repanier.apps import REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS, \
                    REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM, \
                    REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION
                if basket or (REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS
                              and customer_invoice.is_order_confirm_send):
                    if customer_invoice.status <= PERMANENCE_OPENED:
                        basket_message = calc_basket_message(customer, permanence, customer_invoice.status)
                    else:
                        if customer_invoice.delivery is not None:
                            basket_message = EMPTY_STRING
                        else:
                            basket_message = "%s" % (
                                _('The orders are closed.'),
                            )
                    my_order_confirmation(
                        permanence=permanence,
                        customer_invoice=customer_invoice,
                        is_basket=basket,
                        basket_message=basket_message,
                        to_json=to_json
                    )
                else:
                    if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS:
                        my_order_confirmation(
                            permanence=permanence,
                            customer_invoice=customer_invoice,
                            is_basket=basket,
                            to_json=to_json
                        )
                if customer.may_order:
                    if REPANIER_SETTINGS_DISPLAY_PRODUCER_ON_ORDER_FORM:
                        for producer in permanence.producers.all():
                            producer_invoice = ProducerInvoice.objects.filter(
                                producer_id=producer.id, permanence_id=permanence.id
                            ).only(
                                "total_price_with_tax", "status"
                            ).order_by('?').first()
                            if producer_invoice is None:
                                producer_invoice = ProducerInvoice.objects.create(
                                    permanence_id=permanence.id,
                                    producer_id=producer.id,
                                    status=permanence.status
                                )
                            if producer.minimum_order_value.amount > DECIMAL_ZERO:
                                if producer_invoice is None:
                                    ratio = 0
                                else:
                                    ratio = producer_invoice.total_price_with_tax.amount / producer.minimum_order_value.amount
                                    if ratio >= DECIMAL_ONE:
                                        ratio = 100
                                    else:
                                        ratio *= 100
                                option_dict = {'id'  : "#order_procent%d" % producer.id,
                                               'html': "%s%%" % number_format(ratio, 0)}
                                to_json.append(option_dict)
                            if producer_invoice.status != PERMANENCE_OPENED:
                                option_dict = {'id'  : "#order_closed%d" % producer.id,
                                               'html': '&nbsp;<span class="glyphicon glyphicon-ban-circle" aria-hidden="true"></span>'}
                                to_json.append(option_dict)
                    communication = sboolean(request.GET.get('co', False))
                    if communication \
                            and customer_invoice.total_price_with_tax == DECIMAL_ZERO \
                            and not customer_invoice.is_order_confirm_send:
                        now = timezone.now()
                        permanence_boards = PermanenceBoard.objects.filter(
                            customer_id=customer.id, permanence_date__gte=now,
                            permanence__status__lte=PERMANENCE_WAIT_FOR_DONE
                        ).order_by("permanence_date")[:2]
                        is_staff = Staff.objects.filter(
                            customer_responsible_id=customer.id
                        ).order_by('?').exists()
                        if (not is_staff and REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION > DECIMAL_ZERO) \
                                or len(permanence_boards) > 0:
                            if len(permanence_boards) == 0:
                                count_activity = PermanenceBoard.objects.filter(
                                    customer_id=customer.id, permanence_date__lt=now,
                                    permanence_date__gte=now - datetime.timedelta(
                                        days=float(REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION) * 7
                                    )
                                ).count()
                            else:
                                count_activity = None
                            html = render_to_string(
                                'repanier/communication.html',
                                {'permanence_boards': permanence_boards, 'count_activity': count_activity})
                            option_dict = {'id': "#communication", 'html': html}
                            to_json.append(option_dict)
                else:
                    option_dict = {'id': "#may_not_order", 'html': '1'}
                    to_json.append(option_dict)
        else:
            customer = None
            my_basket(False, REPANIER_MONEY_ZERO, to_json)
        request_offer_items = request.GET.getlist('oi')
        for request_offer_item in request_offer_items:
            offer_item_id = sint(request_offer_item)
            if user.is_authenticated() and customer is not None:
                # No need to check customer.may_order.
                # Select one purchase
                purchase = Purchase.objects.filter(
                    customer_id=customer.id,
                    offer_item_id=offer_item_id,
                    is_box_content=False
                ).select_related(
                    "offer_item"
                ).order_by('?').first()
                if purchase is not None:
                    offer_item = purchase.offer_item
                    if offer_item is not None:
                        option_dict = display_selected_value(
                            offer_item,
                            purchase.quantity_ordered)
                        to_json.append(option_dict)
                else:
                    offer_item = OfferItem.objects.filter(
                        id=offer_item_id
                    ).order_by('?').first()
                    if offer_item is not None:
                        option_dict = display_selected_value(
                            offer_item,
                            DECIMAL_ZERO)
                        to_json.append(option_dict)
                box_purchase = Purchase.objects.filter(
                    customer_id=customer.id,
                    offer_item_id=offer_item_id,
                    is_box_content=True
                ).select_related(
                    "offer_item"
                ).order_by('?').first()
                if box_purchase is not None:
                    offer_item = box_purchase.offer_item
                    if offer_item is not None:
                        option_dict = display_selected_box_value(customer, offer_item, box_purchase)
                        to_json.append(option_dict)
                option_dict = {'id': ".btn_like%s" % offer_item_id, 'html': offer_item.get_like(user)}
                to_json.append(option_dict)
            else:
                option_dict = {'id'  : "#offer_item%s" % offer_item_id,
                               'html': '<option value="0" selected>---</option>'}
                to_json.append(option_dict)
                msg_html = '<span class="glyphicon glyphicon-heart-empty"></span>'
                option_dict = {'id': ".btn_like%s" % offer_item_id, 'html': msg_html}
                to_json.append(option_dict)
    else:
        raise Http404
    return HttpResponse(json.dumps(to_json, cls=DjangoJSONEncoder), content_type="application/json")
示例#52
0
def is_into_offer_content(request, product_id, contract_id, one_date_str):
    if request.is_ajax():
        user = request.user
        if user.is_order_manager:
            product_id = sint(product_id)
            product = Product.objects.filter(id=product_id).order_by('?').only(
                'is_into_offer').first()
            if product is not None:
                contract_id = sint(contract_id)
                contract = Contract.objects.filter(id=contract_id).order_by('?').first()
                if contract is not None:
                    contract_content = ContractContent.objects.filter(
                        product_id=product_id,
                        contract_id=contract_id
                    ).order_by('?').first()
                    if contract_content is None or contract_content.permanences_dates is None:
                        all_not_dates_str = contract.permanences_dates.split(settings.DJANGO_SETTINGS_DATES_SEPARATOR)
                        all_not_dates_str.remove(one_date_str)
                        if len(all_not_dates_str) > 0:
                            not_permanences_dates = settings.DJANGO_SETTINGS_DATES_SEPARATOR.join(all_not_dates_str)
                        else:
                            not_permanences_dates = None
                        if contract_content is None:
                            contract_content = ContractContent.objects.create(
                                contract_id=contract_id,
                                product_id=product_id,
                                permanences_dates=one_date_str,
                                not_permanences_dates=not_permanences_dates,
                                flexible_dates=product.order_unit > PRODUCT_ORDER_UNIT_DEPOSIT
                            )
                        else:
                            contract_content.permanences_dates = one_date_str
                            contract_content.not_permanences_dates = not_permanences_dates
                            contract_content.save(update_fields=['permanences_dates', 'not_permanences_dates'])
                    else:
                        all_dates_str = list(filter(None, contract_content.permanences_dates.split(
                            settings.DJANGO_SETTINGS_DATES_SEPARATOR)))
                        if contract_content.not_permanences_dates is not None:
                            all_not_dates_str = list(filter(None, contract_content.not_permanences_dates.split(
                                settings.DJANGO_SETTINGS_DATES_SEPARATOR)))
                        else:
                            all_not_dates_str = []
                        if one_date_str in all_dates_str:
                            all_dates_str.remove(one_date_str)
                            all_not_dates_str.append(one_date_str)
                        else:
                            all_dates_str.append(one_date_str)
                            all_not_dates_str.remove(one_date_str)
                        if len(all_dates_str) > 0:
                            permanences_dates = settings.DJANGO_SETTINGS_DATES_SEPARATOR.join(all_dates_str)
                        else:
                            permanences_dates = None
                        if len(all_not_dates_str) > 0:
                            not_permanences_dates = settings.DJANGO_SETTINGS_DATES_SEPARATOR.join(all_not_dates_str)
                        else:
                            not_permanences_dates = None
                        contract_content.permanences_dates = permanences_dates
                        contract_content.not_permanences_dates = not_permanences_dates
                        contract_content.save(update_fields=['permanences_dates', 'not_permanences_dates'])

                    return HttpResponse(product.get_html_is_into_offer(contract=contract,
                                                                       contract_content=contract_content))
    raise Http404
示例#53
0
def login_view(request,
               template_name='repanier/registration/login.html',
               redirect_field_name=REDIRECT_FIELD_NAME,
               authentication_form=AuthenticationForm,
               extra_context=None):
    """
    Displays the login form and handles the login action.
    """
    redirect_to = request.POST.get(
        redirect_field_name, request.GET.get(redirect_field_name,
                                             EMPTY_STRING))
    # Ensure the user-originating redirection url is safe.
    if not is_safe_url(url=redirect_to, host=request.get_host()):
        redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)

    staff_responsibilities = None
    user = request.user

    if request.method == "POST":
        form = authentication_form(request, data=request.POST)

        if form.is_valid():
            # Okay, security check complete. Log the user in.
            auth_login(request, form.get_user())

            # Now the logged in user is set in request.user
            user = request.user

            if user.is_authenticated:

                if user.is_staff:
                    return HttpResponseRedirect("{}?{}".format(
                        redirect_to,
                        get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')))

                staff_qs = Staff.objects.filter(
                    customer_responsible_id=user.customer_id,
                    is_active=True).order_by('?')
                may_become_a_staff_user = staff_qs.exists()

                if not may_become_a_staff_user:
                    return HttpResponseRedirect(redirect_to)

                # Ask the user to log in as a customer or as a staff member
                staff_responsibilities = staff_qs.all()

    else:
        if user.is_authenticated:
            as_staff_id = sint(request.GET.get('as_id', 0))

            if as_staff_id == 0:
                if user.is_superuser:
                    return HttpResponseRedirect("{}?{}".format(
                        redirect_to,
                        get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')))
                else:
                    # The user want to be logged in as a customer
                    return HttpResponseRedirect(redirect_to)

            as_staff = Staff.objects.filter(
                id=as_staff_id,
                customer_responsible_id=user.customer_id,
                is_active=True).order_by('?').first()

            if as_staff is None:
                # This should not occurs
                # But if ... then log the user as a customer
                return HttpResponseRedirect(redirect_to)

            RepanierAuthBackend.set_staff_right(request=request,
                                                user=user,
                                                as_staff=as_staff)
            return HttpResponseRedirect("{}?{}".format(
                redirect_to, get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON')))

    form = authentication_form(request)

    if user.is_anonymous:
        from repanier.apps import REPANIER_SETTINGS_CONFIG

        how_to_register = REPANIER_SETTINGS_CONFIG.safe_translation_getter(
            'how_to_register', any_language=True, default=EMPTY_STRING)
    else:
        how_to_register = EMPTY_STRING

    context = {
        'form': form,
        redirect_field_name: redirect_to,
        'how_to_register': how_to_register,
        'staff_responsibilities': staff_responsibilities,
    }
    if extra_context is not None:
        context.update(extra_context)
    return TemplateResponse(request, template_name, context)
示例#54
0
def order_select_ajax(request):
    if not request.is_ajax():
        raise Http404
    user = request.user
    customer = Customer.objects.filter(
        user_id=user.id, may_order=True) \
        .only("id", "vat_id", "language").order_by('?').first()
    if customer is None:
        raise Http404
    translation.activate(customer.language)
    offer_item_id = sint(request.GET.get('offer_item', 0))
    offer_item = OfferItemWoReceiver.objects.filter(
        id=offer_item_id
    ).order_by('?').first()
    if offer_item is None:
        raise Http404
    # Select one purchase
    purchase = PurchaseWoReceiver.objects.filter(
        customer_id=customer.id,
        offer_item_id=offer_item_id,
        is_box_content=False
    ).order_by('?').only('quantity_ordered').first()
    producer_invoice = ProducerInvoice.objects.filter(
        permanence_id=offer_item.permanence_id,
        producer_id=offer_item.producer_id,
        status=PERMANENCE_OPENED
    ).order_by('?')
    if producer_invoice.exists():
        # The orders are opened for this producer and this permanence
        if offer_item.may_order:
            # This offer_item may be ordered
            customer_invoice = CustomerInvoice.objects.filter(
                permanence_id=offer_item.permanence_id,
                customer_id=customer.id).only("status").order_by('?').first()
            if customer_invoice is not None:
                status = customer_invoice.status
                if PERMANENCE_OPENED <= status <= PERMANENCE_SEND:
                    a_price = offer_item.customer_unit_price.amount + offer_item.unit_deposit.amount
                    q_min = offer_item.customer_minimum_order_quantity
                    if purchase is not None:
                        q_previous_order = purchase.quantity_ordered
                    else:
                        q_previous_order = DECIMAL_ZERO
                    if status == PERMANENCE_OPENED and offer_item.limit_order_quantity_to_stock:
                        q_alert = offer_item.stock - offer_item.quantity_invoiced + q_previous_order
                        if q_alert < DECIMAL_ZERO:
                            q_alert = DECIMAL_ZERO
                    else:
                        q_alert = offer_item.customer_alert_order_quantity
                    q_step = offer_item.customer_increment_order_quantity
                    q_order_is_displayed = False
                    q_select_id = 0
                    selected = EMPTY_STRING
                    if q_previous_order <= 0:
                        q_order_is_displayed = True
                        selected = "selected"

                    q_valid = q_min
                    html = EMPTY_STRING
                    if q_valid <= q_alert:
                        if (status == PERMANENCE_OPENED or
                                (status <= PERMANENCE_SEND and selected == "selected")):
                            html = "<option value=\"0\" {}>---</option>".format(
                                selected
                            )
                    else:
                        if (status == PERMANENCE_OPENED or
                                (status <= PERMANENCE_SEND and selected == "selected")):
                            html = "<option value=\"0\" {}>{}</option>".format(
                                selected,
                                _("Sold out")
                            )
                    q_counter = 0  # Limit to avoid too long selection list
                    while q_valid <= q_alert and q_counter <= LIMIT_ORDER_QTY_ITEM:
                        q_select_id += 1
                        q_counter += 1
                        selected = EMPTY_STRING
                        if not q_order_is_displayed:
                            if q_previous_order <= q_valid:
                                q_order_is_displayed = True
                                selected = "selected"
                        if (status == PERMANENCE_OPENED or
                                (status <= PERMANENCE_SEND and selected == "selected")):
                            display = offer_item.get_display(
                                qty=q_valid,
                                order_unit=offer_item.order_unit,
                                unit_price_amount=a_price,
                                for_order_select=True
                            )
                            html += "<option value=\"{}\" {}>{}</option>".format(
                                q_select_id,
                                selected,
                                display
                            )
                        if q_valid < q_step:
                            # 1; 2; 4; 6; 8 ... q_min = 1; q_step = 2
                            # 0,5; 1; 2; 3 ... q_min = 0,5; q_step = 1
                            q_valid = q_step
                        else:
                            # 1; 2; 3; 4 ... q_min = 1; q_step = 1
                            # 0,125; 0,175; 0,225 ... q_min = 0,125; q_step = 0,50
                            q_valid = q_valid + q_step

                    if not q_order_is_displayed:
                        # An custom order_qty > q_alert
                        q_select_id += 1
                        display = offer_item.get_display(
                            qty=q_previous_order,
                            order_unit=offer_item.order_unit,
                            unit_price_amount=a_price,
                            for_order_select=True
                        )
                        html = "<option value=\"{}\" selected>{}</option>".format(
                            q_select_id,
                            display
                        )
                    if status == PERMANENCE_OPENED:
                        html += "<option value=\"other_qty\">{}</option>".format(
                            _("Other qty")
                        )
                else:
                    html = "<option value=\"0\" selected>---</option>"
            else:
                html = "<option value=\"0\" selected>---</option>"
        else:
            html = "<option value=\"0\" selected>---</option>"
    else:
        if purchase is not None and purchase.quantity_ordered != DECIMAL_ZERO:
            html = get_html_selected_value(offer_item, purchase.quantity_ordered, is_open=True)
        else:
            html = "<option value=\"0\" selected>{}</option>".format(
                _("Closed")
            )

    return JsonResponse({"#offer_item{}".format(offer_item.id): mark_safe(html)})
示例#55
0
 def queryset(self, request, queryset):
     if self.value():
         permanence_id = sint(self.value(), 0)
         if permanence_id > 0:
             return queryset.filter(permanence_id=permanence_id)
     return queryset
示例#56
0
def order_init_ajax(request):
    if not request.is_ajax():
        raise Http404
    permanence_id = sint(request.GET.get('pe', 0))
    permanence = Permanence.objects.filter(id=permanence_id).order_by('?').first()
    permanence_ok_or_404(permanence)
    user = request.user
    customer = Customer.objects.filter(
        user_id=user.id, may_order=True
    ).only(
        "id", "vat_id", "short_basket_name", "email2", "delivery_point",
        "balance", "date_balance", "may_order"
    ).order_by('?').first()
    if customer is None:
        raise Http404
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence.id,
        customer_id=customer.id
    ).order_by('?').first()
    if customer_invoice is None:
        customer_invoice = CustomerInvoice.objects.create(
            permanence_id=permanence.id,
            customer_id=customer.id,
            status=permanence.status,
            customer_charged_id=customer.id,
        )
        customer_invoice.set_order_delivery(delivery=None)
        customer_invoice.calculate_order_price()
        customer_invoice.save()

    if customer_invoice is None:
        raise Http404

    basket = sboolean(request.GET.get('ba', False))

    if customer_invoice.delivery is not None:
        status = customer_invoice.delivery.status
    else:
        status = customer_invoice.status
    if status <= PERMANENCE_OPENED:
        basket_message = get_html_basket_message(customer, permanence, status)
    else:
        if customer_invoice.delivery is not None:
            basket_message = EMPTY_STRING
        else:
            basket_message = "{}".format(
                _('The orders are closed.')
            )
    if settings.REPANIER_SETTINGS_TEMPLATE == "bs3":
        json_dict = customer_invoice.get_html_my_order_confirmation(
            permanence=permanence,
            is_basket=basket,
            basket_message=basket_message
        )
    else:
        json_dict = {}
    if customer.may_order:
        if settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM:
            for producer_invoice in ProducerInvoice.objects.filter(
                    permanence_id=permanence.id
            ).only(
                "total_price_with_tax", "status"
            ).order_by('?'):
                json_dict.update(producer_invoice.get_order_json())
        communication = sboolean(request.GET.get('co', False))
        if communication:
            now = timezone.now()
            permanence_boards = PermanenceBoard.objects.filter(
                customer_id=customer.id,
                permanence_date__gte=now,
                permanence__status__lte=PERMANENCE_WAIT_FOR_INVOICED
            ).order_by("permanence_date")[:2]
            from repanier.apps import REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION
            if REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION > DECIMAL_ZERO or len(permanence_boards) > 0:
                if len(permanence_boards) == 0:
                    count_activity = PermanenceBoard.objects.filter(
                        customer_id=customer.id, permanence_date__lt=now,
                        permanence_date__gte=now - datetime.timedelta(
                            days=float(REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION) * 7
                        )
                    ).count()
                else:
                    count_activity = None
                template_name = get_repanier_template_name("communication_permanence_board.html")
                html = render_to_string(
                    template_name,
                    {'permanence_boards': permanence_boards, 'count_activity': count_activity}
                )
                json_dict["#communicationModal"] = mark_safe(html)
    json_dict.update(my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax()))
    return JsonResponse(json_dict)
示例#57
0
def order_ajax(request):
    if not request.is_ajax():
        raise Http404
    user = request.user
    customer = Customer.objects.filter(
        user_id=user.id, may_order=True
    ).order_by('?').first()
    if customer is None:
        raise Http404
    offer_item_id = sint(request.GET.get('offer_item', 0))
    value_id = sint(request.GET.get('value', 0))
    is_basket = sboolean(request.GET.get('is_basket', False))
    qs = CustomerInvoice.objects.filter(
        permanence__offeritem=offer_item_id,
        customer_id=customer.id,
        status=PERMANENCE_OPENED).order_by('?')
    json_dict = {}
    if qs.exists():
        qs = ProducerInvoice.objects.filter(
            permanence__offeritem=offer_item_id,
            producer__offeritem=offer_item_id,
            status=PERMANENCE_OPENED
        ).order_by('?')
        if qs.exists():
            purchase, updated = create_or_update_one_cart_item(
                customer=customer,
                offer_item_id=offer_item_id,
                value_id=value_id,
                batch_job=False,
                comment=EMPTY_STRING
            )
            offer_item = OfferItemWoReceiver.objects.filter(
                id=offer_item_id
            ).order_by('?').first()
            if purchase is None:
                json_dict["#offer_item{}".format(offer_item.id)] = get_html_selected_value(offer_item, DECIMAL_ZERO,
                                                                                           is_open=True)
            else:
                json_dict["#offer_item{}".format(offer_item.id)] = get_html_selected_value(offer_item,
                                                                                           purchase.quantity_ordered,
                                                                                           is_open=True)
            if updated and offer_item.is_box:
                # update the content
                for content in BoxContent.objects.filter(
                        box=offer_item.product_id
                ).only(
                    "product_id"
                ).order_by('?'):
                    box_offer_item = OfferItemWoReceiver.objects.filter(
                        product_id=content.product_id,
                        permanence_id=offer_item.permanence_id
                    ).order_by('?').first()
                    if box_offer_item is not None:
                        # Select one purchase
                        purchase = PurchaseWoReceiver.objects.filter(
                            customer_id=customer.id,
                            offer_item_id=box_offer_item.id,
                            is_box_content=False
                        ).order_by('?').only('quantity_ordered').first()
                        if purchase is not None:
                            json_dict["#offer_item{}".format(box_offer_item.id)] = get_html_selected_value(
                                box_offer_item,
                                purchase.quantity_ordered,
                                is_open=True
                            )
                        box_purchase = PurchaseWoReceiver.objects.filter(
                            customer_id=customer.id,
                            offer_item_id=box_offer_item.id,
                            is_box_content=True
                        ).order_by('?').only('quantity_ordered').first()
                        if box_purchase is not None:
                            json_dict["#box_offer_item{}".format(box_offer_item.id)] = get_html_selected_box_value(
                                box_offer_item,
                                box_purchase.quantity_ordered
                            )

            if settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM:
                producer_invoice = ProducerInvoice.objects.filter(
                    producer_id=offer_item.producer_id, permanence_id=offer_item.permanence_id
                ).only("total_price_with_tax").order_by('?').first()
                json_dict.update(producer_invoice.get_order_json())

            customer_invoice = CustomerInvoice.objects.filter(
                permanence_id=offer_item.permanence_id,
                customer_id=customer.id
            ).order_by('?').first()
            invoice_confirm_status_is_changed = customer_invoice.cancel_confirm_order()
            if settings.REPANIER_SETTINGS_CUSTOMER_MUST_CONFIRM_ORDER and invoice_confirm_status_is_changed:
                template_name = get_repanier_template_name("communication_confirm_order.html")
                html = render_to_string(template_name)
                json_dict["#communicationModal"] = mark_safe(html)
                customer_invoice.save()

            json_dict.update(
                my_basket(customer_invoice.is_order_confirm_send, customer_invoice.get_total_price_with_tax()))
            permanence = Permanence.objects.filter(
                id=offer_item.permanence_id
            ).order_by('?').first()

            if is_basket:
                basket_message = get_html_basket_message(customer, permanence, PERMANENCE_OPENED)
            else:
                basket_message = EMPTY_STRING
            json_dict.update(customer_invoice.get_html_my_order_confirmation(
                permanence=permanence,
                is_basket=is_basket,
                basket_message=basket_message
            ))
    return JsonResponse(json_dict)
示例#58
0
def order_select_ajax(request):
    if request.is_ajax():
        # construct a list which will contain all of the data for the response
        user = request.user
        to_json = []
        if user.is_authenticated():
            customer = Customer.objects.filter(
                user_id=user.id, is_active=True, may_order=True) \
                .only("id", "vat_id", "language").order_by('?').first()
            if customer is not None:
                translation.activate(customer.language)
                offer_item_id = sint(request.GET.get('offer_item', 0))
                # Select one purchase
                purchase = Purchase.objects.filter(
                    customer_id=customer.id,
                    offer_item_id=offer_item_id,
                    is_box_content=False
                ).order_by('?').first()
                if purchase is not None:
                    q_previous_order = purchase.quantity_ordered
                else:
                    q_previous_order = DECIMAL_ZERO
                offer_item = OfferItem.objects.filter(id=offer_item_id, is_active=True) \
                    .order_by('?').first()
                qs = ProducerInvoice.objects.filter(
                    permanence__offeritem=offer_item_id,
                    producer__offeritem=offer_item_id,
                    status=PERMANENCE_OPENED
                ).order_by('?')
                if qs.exists():
                    if offer_item is not None:
                        customer_invoice = CustomerInvoice.objects.filter(
                            permanence_id=offer_item.permanence_id,
                            customer=customer.id).only("status").order_by('?').first()
                        if customer_invoice is not None:
                            status = customer_invoice.status
                            if PERMANENCE_OPENED <= status <= PERMANENCE_SEND:
                                a_price = offer_item.customer_unit_price.amount + offer_item.unit_deposit.amount
                                q_min = offer_item.customer_minimum_order_quantity
                                if status == PERMANENCE_OPENED and offer_item.limit_order_quantity_to_stock:
                                    q_alert = offer_item.stock - offer_item.quantity_invoiced + q_previous_order
                                    if q_alert < DECIMAL_ZERO:
                                        q_alert = DECIMAL_ZERO
                                else:
                                    q_alert = offer_item.customer_alert_order_quantity
                                q_step = offer_item.customer_increment_order_quantity
                                q_order_is_displayed = False
                                q_select_id = 0
                                selected = EMPTY_STRING
                                if q_previous_order <= 0:
                                    q_order_is_displayed = True
                                    selected = "selected"

                                q_valid = q_min
                                if q_valid <= q_alert:
                                    if (status == PERMANENCE_OPENED or
                                            (status <= PERMANENCE_SEND and selected == "selected")):
                                        option_dict = {'value': '0', 'selected': selected, 'label': '---'}
                                        to_json.append(option_dict)
                                else:
                                    if (status == PERMANENCE_OPENED or
                                            (status <= PERMANENCE_SEND and selected == "selected")):
                                        sold_out = _("Sold out")
                                        option_dict = {'value': '0', 'selected': selected, 'label': sold_out}
                                        to_json.append(option_dict)
                                q_counter = 0  # Limit to avoid too long selection list
                                while q_valid <= q_alert and q_counter <= LIMIT_ORDER_QTY_ITEM:
                                    q_select_id += 1
                                    q_counter += 1
                                    selected = EMPTY_STRING
                                    if not q_order_is_displayed:
                                        if q_previous_order <= q_valid:
                                            q_order_is_displayed = True
                                            selected = "selected"
                                    if (status == PERMANENCE_OPENED or
                                            (status <= PERMANENCE_SEND and selected == "selected")):
                                        display = get_display(
                                            qty=q_valid,
                                            order_average_weight=offer_item.order_average_weight,
                                            order_unit=offer_item.order_unit,
                                            unit_price_amount=a_price,
                                            for_order_select=True
                                        )
                                        option_dict = {'value': str(q_select_id), 'selected': selected,
                                                       'label': display}
                                        to_json.append(option_dict)
                                    if q_valid < q_step:
                                        # 1; 2; 4; 6; 8 ... q_min = 1; q_step = 2
                                        # 0,5; 1; 2; 3 ... q_min = 0,5; q_step = 1
                                        q_valid = q_step
                                    else:
                                        # 1; 2; 3; 4 ... q_min = 1; q_step = 1
                                        # 0,125; 0,175; 0,225 ... q_min = 0,125; q_step = 0,50
                                        q_valid = q_valid + q_step

                                if not q_order_is_displayed:
                                    # An custom order_qty > q_alert
                                    q_select_id += 1
                                    selected = "selected"
                                    display = get_display(
                                        qty=q_previous_order,
                                        order_average_weight=offer_item.order_average_weight,
                                        order_unit=offer_item.order_unit,
                                        unit_price_amount=a_price,
                                        for_order_select=True
                                    )
                                    option_dict = {'value': str(q_select_id), 'selected': selected,
                                                   'label': display}
                                    to_json.append(option_dict)
                                if status == PERMANENCE_OPENED:
                                    # _not_lazy string are not placed in the "django.po"
                                    other = _("Other qty")
                                    option_dict = {'value': 'other_qty', 'selected': EMPTY_STRING, 'label': other}
                                    to_json.append(option_dict)
                            else:
                                option_dict = {'value': '0', 'selected': 'selected', 'label': '---'}
                                to_json.append(option_dict)
                        else:
                            option_dict = {'value': '0', 'selected': 'selected', 'label': '---'}
                            to_json.append(option_dict)
                    else:
                        option_dict = {'value': '0', 'selected': 'selected', 'label': '---'}
                        to_json.append(option_dict)
                else:
                    if q_previous_order <= DECIMAL_ZERO:
                        closed = _("Closed")
                        option_dict = {'value': '0', 'selected': 'selected', 'label': '%s' % closed}
                        to_json.append(option_dict)
                    else:
                        option_dict = display_selected_value(offer_item, purchase.quantity_ordered)
                        to_json.append(option_dict)
            else:
                option_dict = {'value': '0', 'selected': 'selected', 'label': '---'}
                to_json.append(option_dict)
        else:
            option_dict = {'value': '0', 'selected': 'selected', 'label': '---'}
            to_json.append(option_dict)
    else:
        raise Http404
    return HttpResponse(json.dumps(to_json, cls=DjangoJSONEncoder), content_type="application/json")
示例#59
0
def order_init_ajax(request):
    if not request.is_ajax():
        raise Http404
    permanence_id = sint(request.GET.get('pe', 0))
    permanence = Permanence.objects.filter(
        id=permanence_id).order_by('?').first()
    permanence_ok_or_404(permanence)
    user = request.user
    customer = Customer.objects.filter(user_id=user.id, may_order=True).only(
        "id", "vat_id", "short_basket_name", "email2", "delivery_point",
        "balance", "date_balance", "may_order").order_by('?').first()
    if customer is None:
        raise Http404
    customer_invoice = CustomerInvoice.objects.filter(
        permanence_id=permanence.id,
        customer_id=customer.id).order_by('?').first()
    if customer_invoice is None:
        customer_invoice = CustomerInvoice.objects.create(
            permanence_id=permanence.id,
            customer_id=customer.id,
            status=permanence.status,
            customer_charged_id=customer.id,
        )
        customer_invoice.set_delivery(delivery=None)
        customer_invoice.save()

    if customer_invoice is None:
        raise Http404

    basket = sboolean(request.GET.get('ba', False))

    if customer_invoice.delivery is not None:
        status = customer_invoice.delivery.status
    else:
        status = customer_invoice.status
    if status <= PERMANENCE_OPENED:
        basket_message = get_html_basket_message(customer, permanence, status)
    else:
        if customer_invoice.delivery is not None:
            basket_message = EMPTY_STRING
        else:
            basket_message = "{}".format(_('The orders are closed.'))
    json_dict = customer_invoice.get_html_my_order_confirmation(
        permanence=permanence, is_basket=basket, basket_message=basket_message)
    if customer.may_order:
        if settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM:
            for producer_invoice in ProducerInvoice.objects.filter(
                    permanence_id=permanence.id).only("total_price_with_tax",
                                                      "status").order_by('?'):
                json_dict.update(producer_invoice.get_order_json())
        communication = sboolean(request.GET.get('co', False))
        if communication:
            now = timezone.now()
            permanence_boards = PermanenceBoard.objects.filter(
                customer_id=customer.id,
                permanence_date__gte=now,
                permanence__status__lte=PERMANENCE_WAIT_FOR_INVOICED).order_by(
                    "permanence_date")[:2]
            from repanier.apps import REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION
            if REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION > DECIMAL_ZERO or len(
                    permanence_boards) > 0:
                if len(permanence_boards) == 0:
                    count_activity = PermanenceBoard.objects.filter(
                        customer_id=customer.id,
                        permanence_date__lt=now,
                        permanence_date__gte=now -
                        datetime.timedelta(days=float(
                            REPANIER_SETTINGS_MAX_WEEK_WO_PARTICIPATION) *
                                           7)).count()
                else:
                    count_activity = None
                html = render_to_string(
                    'repanier/communication_permanence_board.html', {
                        'permanence_boards': permanence_boards,
                        'count_activity': count_activity
                    })
                json_dict["#communicationModal"] = mark_safe(html)
    json_dict.update(
        my_basket(customer_invoice.is_order_confirm_send,
                  customer_invoice.get_total_price_with_tax()))
    return JsonResponse(json_dict)
示例#60
0
def repanier_user_bs3(context, *args, **kwargs):
    from repanier.apps import REPANIER_SETTINGS_DISPLAY_WHO_IS_WHO

    request = context["request"]
    user = request.user
    nodes = []
    if user.is_authenticated:
        if not user.is_staff:
            nodes = []
            p_permanence_id = sint(kwargs.get("permanence_id", 0))
            if p_permanence_id > 0:
                nodes.append(
                    '<li id="li_my_basket" style="display:none;" class="dropdown">'
                )
                nodes.append(
                    '<a href="{}?is_basket=yes" class="btn btn-info"><span id="my_basket"></span></a>'.format(
                        reverse("order_view", args=(p_permanence_id,))
                    )
                )
                nodes.append("</li>")
            nodes.append(
                """
                <li id="li_my_name" class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> {}<b class="caret"></b></a>
                <ul class="dropdown-menu">
                """.format(
                    # _('Welkom'),
                    user.username
                    or '<span id = "my_name"></ span>'
                )
            )
            nodes.append(
                '<li><a href="{}">{}</a></li>'.format(
                    reverse("send_mail_to_coordinators_view"), _("Inform")
                )
            )
            if REPANIER_SETTINGS_DISPLAY_WHO_IS_WHO:
                nodes.append(
                    '<li><a href="{}">{}</a></li>'.format(
                        reverse("who_is_who_view"), _("Who's who")
                    )
                )
            if user.customer_id is not None:
                nodes.append(
                    '<li><a href="{}">{}</a></li>'.format(
                        reverse("my_profile_view"), _("My profile")
                    )
                )
                if settings.REPANIER_SETTINGS_MANAGE_ACCOUNTING:
                    last_customer_invoice = (
                        CustomerInvoice.objects.filter(
                            customer__user_id=request.user.id,
                            invoice_sort_order__isnull=False,
                        )
                        .only("balance", "date_balance")
                        .order_by("-invoice_sort_order")
                        .first()
                    )
                    if last_customer_invoice is not None:
                        if last_customer_invoice.balance < DECIMAL_ZERO:
                            my_balance = _(
                                'My balance : <font color="red">%(balance)s</font> at %(date)s'
                            ) % {
                                "balance": last_customer_invoice.balance,
                                "date": last_customer_invoice.date_balance.strftime(
                                    settings.DJANGO_SETTINGS_DATE
                                ),
                            }
                        else:
                            my_balance = _(
                                'My balance : <font color="green">%(balance)s</font> at %(date)s'
                            ) % {
                                "balance": last_customer_invoice.balance,
                                "date": last_customer_invoice.date_balance.strftime(
                                    settings.DJANGO_SETTINGS_DATE
                                ),
                            }
                    else:
                        my_balance = _("My balance")
                    nodes.append(
                        '<li><a href="{}">{}</a></li>'.format(
                            reverse("customer_invoice_view", args=(0,)), my_balance
                        )
                    )
                nodes.append('<li class="divider"></li>')
            nodes.append(
                '<li><a href="{}">{}</a></li>'.format(reverse("logout"), _("Logout"))
            )
            nodes.append("</ul></li>")

    else:
        p_offer_uuid = kwargs.get("offer_uuid", None)
        if len(p_offer_uuid) == 36:
            producer = (
                Producer.objects.filter(offer_uuid=p_offer_uuid)
                .only("long_profile_name")
                .order_by("?")
                .first()
            )
            if producer is not None:
                nodes = [
                    '<li><a href="#">{} {}</a></li>'.format(
                        _("Welkom"), producer.long_profile_name
                    )
                ]
        else:
            nodes = [
                '<li class="dropdown"><a href="{}">{}</a></li>'.format(
                    reverse("login_form"), _("Login")
                )
            ]

    return mark_safe("".join(nodes))