Beispiel #1
0
    def get_context_data(self, **kwargs):
        context = super(PermanenceView, self).get_context_data(**kwargs)
        context['DISPLAY_PRODUCER'] = settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM

        if self.request.user.is_anonymous:
            from repanier.apps import REPANIER_SETTINGS_CONFIG

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

        return context
Beispiel #2
0
    def get_context_data(self, **kwargs):
        context = super(PermanenceView, self).get_context_data(**kwargs)

        if self.request.user.is_anonymous:
            from repanier.apps import REPANIER_SETTINGS_CONFIG

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

        return context
Beispiel #3
0
def order_info_ajax(request):
    if request.is_ajax():
        from repanier.apps import REPANIER_SETTINGS_CONFIG
        order_info = EMPTY_STRING
        notification = REPANIER_SETTINGS_CONFIG.safe_translation_getter(
            'notification', any_language=True, default=EMPTY_STRING)
        if notification:
            if REPANIER_SETTINGS_CONFIG.notification_is_public or request.user.is_authenticated:
                order_info = """
                <div class="row">
                    <div class="panel-group">
                        <div class="panel panel-default">
                            <div class="panel-body">
                                <div class="col-md-12">
                                {notification}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                """.format(notification=notification)

        return HttpResponse(order_info)
    raise Http404
Beispiel #4
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)
Beispiel #5
0
    def get_context_data(self, **kwargs):
        from repanier.apps import (
            REPANIER_SETTINGS_DISPLAY_ANONYMOUS_ORDER_FORM,
            REPANIER_SETTINGS_CONFIG,
            REPANIER_SETTINGS_NOTIFICATION,
        )

        context = super(OrderView, self).get_context_data(**kwargs)
        context["first_page"] = self.first_page
        context["permanence"] = self.permanence
        context["permanence_id"] = self.permanence.id
        context["all_dates"] = self.all_dates
        context["date_id"] = self.date_id
        context["date_Selected"] = self.date_selected
        context[
            "notification"] = REPANIER_SETTINGS_NOTIFICATION.get_notification_display(
            )
        if self.first_page:
            if settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM:
                producer_set = Producer.objects.filter(
                    permanence=self.permanence.id).only(
                        "id", "short_profile_name")
            else:
                producer_set = None
            context["producer_set"] = producer_set
            if self.producer_id == "all":
                department_set = (LUT_DepartmentForCustomer.objects.filter(
                    offeritem__permanence_id=self.permanence.id,
                    offeritem__is_active=True,
                    offeritem__is_box=False,
                ).order_by("tree_id", "lft").distinct("id", "tree_id", "lft"))
            else:
                department_set = (LUT_DepartmentForCustomer.objects.filter(
                    offeritem__producer_id=self.producer_id,
                    offeritem__permanence_id=self.permanence.id,
                    offeritem__is_active=True,
                    offeritem__is_box=False,
                ).order_by("tree_id", "lft").distinct("id", "tree_id", "lft"))
            context["department_set"] = department_set
            context["box_set"] = OfferItemWoReceiver.objects.filter(
                permanence_id=self.permanence.id,
                is_box=True,
                is_active=True,
                may_order=True,
                translations__language_code=translation.get_language(),
            ).order_by("customer_unit_price", "unit_deposit",
                       "translations__long_name")
            context["staff_order"] = Staff.get_or_create_order_responsible()
            if self.is_anonymous:
                context[
                    "how_to_register"] = REPANIER_SETTINGS_CONFIG.safe_translation_getter(
                        "how_to_register",
                        any_language=True,
                        default=EMPTY_STRING)
            else:
                context["how_to_register"] = EMPTY_STRING

        # use of str() to avoid "12 345" when rendering the template
        context["producer_id"] = str(self.producer_id)
        # use of str() to avoid "12 345" when rendering the template
        context["department_id"] = str(self.department_id)

        context["box_id"] = str(self.box_id)
        context["is_box"] = "yes" if self.is_box else EMPTY_STRING
        if self.is_box:
            offer_item = get_object_or_404(OfferItemWoReceiver, id=self.box_id)
            context["box_description"] = html_box_content(
                offer_item, self.user)
        if self.is_basket:
            context["is_basket"] = "yes"
            context["is_select_view"] = EMPTY_STRING
            context["is_basket_view"] = "active"

            customer = (Customer.objects.filter(
                user_id=self.user.id, may_order=True).order_by("?").first())
            if customer is None:
                raise Http404
            translation.activate(customer.language)
            customer_invoice = (CustomerInvoice.objects.filter(
                permanence_id=self.permanence.id,
                customer_id=customer.id).order_by("?").first())
            if customer_invoice is None:
                customer_invoice = CustomerInvoice.objects.create(
                    permanence_id=self.permanence.id,
                    customer_id=customer.id,
                    status=self.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.delivery is not None:
                status = customer_invoice.delivery.status
            else:
                status = customer_invoice.status
            basket_message = get_html_basket_message(customer, self.permanence,
                                                     status)
            html = customer_invoice.get_html_my_order_confirmation(
                permanence=self.permanence,
                is_basket=True,
                basket_message=basket_message,
            )
            context["span_btn_confirm_order"] = html["#span_btn_confirm_order"]
        else:
            context["is_basket"] = EMPTY_STRING
            context["is_select_view"] = "active"
            context["is_basket_view"] = EMPTY_STRING
        context["is_like"] = "yes" if self.is_like else EMPTY_STRING

        context["communication"] = self.communication
        context["q"] = self.q

        context["may_order"] = self.may_order
        context[
            "display_anonymous_order_form"] = REPANIER_SETTINGS_DISPLAY_ANONYMOUS_ORDER_FORM
        return context
Beispiel #6
0
    def get_context_data(self, **kwargs):
        from repanier.apps import REPANIER_SETTINGS_DISPLAY_ANONYMOUS_ORDER_FORM, REPANIER_SETTINGS_CONFIG, \
            REPANIER_SETTINGS_NOTIFICATION

        context = super(OrderView, self).get_context_data(**kwargs)
        context['first_page'] = self.first_page
        context['permanence'] = self.permanence
        context['permanence_id'] = self.permanence.id
        context["all_dates"] = self.all_dates
        context["date_id"] = self.date_id
        context["date_Selected"] = self.date_selected
        context["notification"] = None if self.is_anonymous and \
                                          not REPANIER_SETTINGS_NOTIFICATION.notification_is_public  else \
            REPANIER_SETTINGS_NOTIFICATION.safe_translation_getter('notification', any_language=True)
        if self.first_page:
            if settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM:
                producer_set = Producer.objects.filter(
                    permanence=self.permanence.id).only(
                        "id", "short_profile_name")
            else:
                producer_set = None
            context['producer_set'] = producer_set
            if self.producer_id == 'all':
                department_set = LUT_DepartmentForCustomer.objects.filter(
                    offeritem__permanence_id=self.permanence.id,
                    offeritem__is_active=True,
                    offeritem__is_box=False) \
                    .order_by("tree_id", "lft") \
                    .distinct("id", "tree_id", "lft")
            else:
                department_set = LUT_DepartmentForCustomer.objects.filter(
                    offeritem__producer_id=self.producer_id,
                    offeritem__permanence_id=self.permanence.id,
                    offeritem__is_active=True,
                    offeritem__is_box=False) \
                    .order_by("tree_id", "lft") \
                    .distinct("id", "tree_id", "lft")
            context['department_set'] = department_set
            context['box_set'] = OfferItemWoReceiver.objects.filter(
                permanence_id=self.permanence.id,
                is_box=True,
                is_active=True,
                may_order=True,
                translations__language_code=translation.get_language(
                )).order_by(
                    'customer_unit_price',
                    'unit_deposit',
                    'translations__long_name',
                )
            context['staff_order'] = Staff.get_or_create_order_responsible()
            if self.is_anonymous:
                context[
                    'how_to_register'] = REPANIER_SETTINGS_CONFIG.safe_translation_getter(
                        'how_to_register',
                        any_language=True,
                        default=EMPTY_STRING)
            else:
                context['how_to_register'] = EMPTY_STRING

        # use of str() to avoid "12 345" when rendering the template
        context['producer_id'] = str(self.producer_id)
        # use of str() to avoid "12 345" when rendering the template
        context['department_id'] = str(self.department_id)

        context['box_id'] = str(self.box_id)
        context['is_box'] = "yes" if self.is_box else EMPTY_STRING
        if self.is_box:
            offer_item = get_object_or_404(OfferItemWoReceiver, id=self.box_id)
            context['box_description'] = html_box_content(
                offer_item, self.user)
        context['is_basket'] = "yes" if self.is_basket else EMPTY_STRING
        context['is_like'] = "yes" if self.is_like else EMPTY_STRING

        context['communication'] = self.communication
        context['q'] = self.q

        context['may_order'] = self.may_order
        context[
            'display_anonymous_order_form'] = REPANIER_SETTINGS_DISPLAY_ANONYMOUS_ORDER_FORM
        return context
Beispiel #7
0
    def get_context_data(self, **kwargs):
        from repanier.apps import REPANIER_SETTINGS_DISPLAY_ANONYMOUS_ORDER_FORM, REPANIER_SETTINGS_CONFIG, \
            REPANIER_SETTINGS_NOTIFICATION

        context = super(OrderView, self).get_context_data(**kwargs)
        context['first_page'] = self.first_page
        context['permanence'] = self.permanence
        context['permanence_id'] = self.permanence.id
        context["all_dates"] = self.all_dates
        context["date_id"] = self.date_id
        context["date_Selected"] = self.date_selected
        context["notification"] = REPANIER_SETTINGS_NOTIFICATION.get_notification_display()
        if self.first_page:
            if settings.REPANIER_SETTINGS_SHOW_PRODUCER_ON_ORDER_FORM:
                producer_set = Producer.objects.filter(permanence=self.permanence.id).only("id", "short_profile_name")
            else:
                producer_set = None
            context['producer_set'] = producer_set
            if self.producer_id == 'all':
                department_set = LUT_DepartmentForCustomer.objects.filter(
                    offeritem__permanence_id=self.permanence.id,
                    offeritem__is_active=True,
                    offeritem__is_box=False) \
                    .order_by("tree_id", "lft") \
                    .distinct("id", "tree_id", "lft")
            else:
                department_set = LUT_DepartmentForCustomer.objects.filter(
                    offeritem__producer_id=self.producer_id,
                    offeritem__permanence_id=self.permanence.id,
                    offeritem__is_active=True,
                    offeritem__is_box=False) \
                    .order_by("tree_id", "lft") \
                    .distinct("id", "tree_id", "lft")
            context['department_set'] = department_set
            context['box_set'] = OfferItemWoReceiver.objects.filter(
                permanence_id=self.permanence.id,
                is_box=True,
                is_active=True,
                may_order=True,
                translations__language_code=translation.get_language()
            ).order_by(
                'customer_unit_price',
                'unit_deposit',
                'translations__long_name',
            )
            context['staff_order'] = Staff.get_or_create_order_responsible()
            if self.is_anonymous:
                context['how_to_register'] = REPANIER_SETTINGS_CONFIG.safe_translation_getter(
                    'how_to_register', any_language=True, default=EMPTY_STRING)
            else:
                context['how_to_register'] = EMPTY_STRING

        # use of str() to avoid "12 345" when rendering the template
        context['producer_id'] = str(self.producer_id)
        # use of str() to avoid "12 345" when rendering the template
        context['department_id'] = str(self.department_id)

        context['box_id'] = str(self.box_id)
        context['is_box'] = "yes" if self.is_box else EMPTY_STRING
        if self.is_box:
            offer_item = get_object_or_404(OfferItemWoReceiver, id=self.box_id)
            context['box_description'] = html_box_content(offer_item, self.user)
        if self.is_basket:
            context['is_basket'] = "yes"
            context['is_select_view'] = EMPTY_STRING
            context['is_basket_view'] = 'active'

            customer = Customer.objects.filter(
                user_id=self.user.id, may_order=True).order_by('?').first()
            if customer is None:
                raise Http404
            translation.activate(customer.language)
            customer_invoice = CustomerInvoice.objects.filter(
                permanence_id=self.permanence.id,
                customer_id=customer.id
            ).order_by('?').first()
            if customer_invoice is None:
                raise Http404
            if customer_invoice.delivery is not None:
                status = customer_invoice.delivery.status
            else:
                status = customer_invoice.status
            basket_message = get_html_basket_message(
                customer,
                self.permanence,
                status
            )
            html = customer_invoice.get_html_my_order_confirmation(
                permanence=self.permanence,
                is_basket=True,
                basket_message=basket_message
            )
            context['span_btn_confirm_order'] = html['#span_btn_confirm_order']
        else:
            context['is_basket'] = EMPTY_STRING
            context['is_select_view'] = 'active'
            context['is_basket_view'] = EMPTY_STRING
        context['is_like'] = "yes" if self.is_like else EMPTY_STRING

        context['communication'] = self.communication
        context['q'] = self.q

        context['may_order'] = self.may_order
        context['display_anonymous_order_form'] = REPANIER_SETTINGS_DISPLAY_ANONYMOUS_ORDER_FORM
        return context
Beispiel #8
0
def login_view(request, template_name=EMPTY_STRING,
               redirect_field_name=REDIRECT_FIELD_NAME,
               authentication_form=AuthenticationForm,
               extra_context=None):
    """
    Displays the login form and handles the login action.
    """
    template_name = get_repanier_template_name('registration/login.html')
    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, allowed_hosts=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)
Beispiel #9
0
def home_info_ajax(request):
    if request.is_ajax():
        from repanier.apps import REPANIER_SETTINGS_CONFIG
        permanences = []
        home_info = "&nbsp;"
        for permanence in Permanence.objects.filter(
                status=PERMANENCE_OPENED) \
                .only("id", "permanence_date", "with_delivery_point") \
                .order_by('-permanence_date', '-id'):
            permanences.append(
                format_html(
                    '<div class="panel-heading"><h4 class="panel-title"><a href="{}">{}</a></h4></div>',
                    reverse('order_view', args=(permanence.id, )),
                    permanence.get_permanence_customer_display()))
            if permanence.offer_description_on_home_page and permanence.offer_description:
                if permanence.picture:
                    permanences.append(
                        format_html(
                            '<div class="panel-body"><div class="col-xs-12"><img class="img-responsive img-rounded" style="float: left; margin: 5px;" alt="{}" title="{}" src="{}{}"/><div class="clearfix visible-xs-block visible-sm-block"></div>{}</div></div>',
                            permanence.get_permanence_customer_display(),
                            permanence.get_permanence_customer_display(),
                            settings.MEDIA_URL, permanence.picture,
                            mark_safe(permanence.offer_description)))
                else:
                    permanences.append(
                        format_html(
                            '<div class="panel-body"><div class="col-xs-12">{}</div></div>',
                            mark_safe(permanence.offer_description)))
        if len(permanences) > 0:
            home_info = """
            <div class="container">
                <div class="row">
                    <div class="panel-group">
                        <div class="panel panel-default">
                            {permanences}
                        </div>
                    </div>
                </div>
            </div>
            """.format(permanences="".join(permanences))

        notification = REPANIER_SETTINGS_CONFIG.safe_translation_getter(
            'notification', any_language=True, default=EMPTY_STRING)
        if notification:
            if REPANIER_SETTINGS_CONFIG.notification_is_public or request.user.is_authenticated:
                home_info = """
                <div class="container">
                    <div class="row">
                        <div class="panel-group">
                            <div class="panel panel-default">
                                <div class="panel-body">
                                    {notification}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                {home_info}
                """.format(notification=notification, home_info=home_info)

        return HttpResponse(home_info)
    raise Http404