Пример #1
0
    def post(self, request, template_id, **kwargs):
        ps = TemplatePartyService()
        template = ps.get(id=template_id)

        form = AddMemberToTemplateForm(request.POST, party=template)
        if not form.is_valid():
            errors = get_form_errors_as_str(form)
            messages.error(request, errors)
        else:
            info = form.cleaned_data.get('info')
            message_level = messages.ERROR
            try:
                ps.add_member_to_template(template, info)
                message = 'User successfully invited'
                message_level = messages.SUCCESS
            except Profile.DoesNotExist:
                message = 'Such user does not found'
            except MemberAlreadyInPartyException:
                message = 'This member is already in template'

            messages.add_message(request, message_level, message)

        return redirect(
            reverse(TemplatePartyView.name,
                    kwargs={'template_id': template_id}))
Пример #2
0
    def post(self, request, template_id: int, **kwargs):
        template = TemplatePartyService().get(id=template_id)
        TemplatePartyService().set_state(template, TemplateParty.INACTIVE)

        return redirect(
            reverse(TemplatePartyView.name,
                    kwargs={'template_id': template_id}))
Пример #3
0
 def post(self, request, template_id: int, **kwargs):
     template = TemplatePartyService().get(id=template_id)
     try:
         TemplatePartyService().set_state(template, TemplateParty.ACTIVE)
     except TemplatePartyScheduleIsNotSetException:
         messages.error(request, 'Set template schedule first')
     return redirect(
         reverse(TemplatePartyView.name,
                 kwargs={'template_id': template_id}))
Пример #4
0
def create_party(template_id):
    template = TemplatePartyService().get(id=template_id)

    if TemplatePartyService().has_active_parties(template):
        logger.error('Task can`t be run because this template(id={0}) has active parties'
                     .format(template_id))
        raise TemplatePartyHasActiveRelatedPartyException()

    PartyService().create_from_template(template)
Пример #5
0
    def post(self, request, template_id: int, **kwargs):
        food_id = int(request.POST.get('food'))
        quantity = abs(int(request.POST.get('quantity')))

        template = TemplatePartyService().get(id=template_id)
        food = FoodService().get(id=food_id)
        TemplatePartyService().order_food(template, food, quantity)

        return redirect(
            reverse(TemplatePartyView.name,
                    kwargs={'template_id': template_id}))
Пример #6
0
    def post(self, request, template_id: int, **kwargs):
        member_id = request.POST.get('member')
        member = TemplateMemberService().get(id=member_id)
        TemplatePartyService().remove_member_from_template(member)

        return redirect(
            reverse(TemplatePartyView.name,
                    kwargs={'template_id': template_id}))
Пример #7
0
    def post(self, request, template_id: int, **kwargs):
        order_item_id = int(request.POST.get('order_item'))

        order_item = TemplateOrderService().get(id=order_item_id)
        TemplatePartyService().remove_from_order(order_item)

        return redirect(
            reverse(TemplatePartyView.name,
                    kwargs={'template_id': template_id}))
Пример #8
0
    def save(self, commit=True) -> TemplateParty:
        name = self.cleaned_data.get('name')
        members = self.cleaned_data.get('members')
        food = self.cleaned_data.get('food')

        creator = ProfileService().get(id=self.user.id)
        return TemplatePartyService().create(name=name,
                                             creator=creator,
                                             members=members,
                                             food=food)
Пример #9
0
    def post(self, request, template_id: int, **kwargs):
        template = TemplatePartyService().get(id=template_id)
        form = AddCustomFoodToTemplateForm(request.POST, party=template)
        if not form.is_valid():
            errors = get_form_errors_as_str(form)
            messages.error(request, errors)
        else:
            form.save()

        return redirect(
            reverse(TemplatePartyView.name,
                    kwargs={'template_id': template_id}))
Пример #10
0
    def post(self, request, template_id: int, **kwargs):
        template = TemplatePartyService().get(id=template_id)

        form = SetScheduleForm(request.POST, template=template)
        if not form.is_valid():
            errors = get_form_errors_as_str(form)
            messages.error(request, errors)
        else:
            form.save()
            messages.success(request, 'Template schedule is set')

        return redirect(
            reverse(TemplatePartyView.name,
                    kwargs={'template_id': template.id}))
Пример #11
0
    def get_context_data(self, template_id: int, **kwargs):
        context = {}

        template_party = TemplatePartyService().get(id=template_id)
        template_members = TemplatePartyService().get_template_members(
            template_party)
        template_ordered_food = TemplatePartyService(
        ).get_template_ordered_food(template_party)

        context['template'] = template_party
        context['is_active'] = TemplatePartyService().is_active(template_party)
        context['members'] = template_members
        context['ordered_food'] = template_ordered_food

        context['food'] = Food.objects.all()

        context[AddMemberToTemplateForm.form_name] = AddMemberToTemplateForm(
            party=template_party)
        context[SetScheduleForm.form_name] = SetScheduleForm(
            template=template_party)
        context[AddCustomFoodToTemplateForm.
                form_name] = AddCustomFoodToTemplateForm(party=template_party)

        return context
Пример #12
0
    def post(self, request, template_id: int):
        template = TemplatePartyService().get(id=template_id)
        TemplatePartyService().delete(template)

        return redirect(reverse(TemplatesListView.name))
Пример #13
0
 def post(self, request, party_id: int):
     party = PartyService().get(id=party_id)
     template_party = TemplatePartyService().create_from_existing(party)
     return redirect(
         reverse(TemplatePartyView.name,
                 kwargs={'template_id': template_party.id}))
Пример #14
0
 def get_queryset(self):
     return TemplatePartyService().filter(created_by=self.request.user)
Пример #15
0
    def clean_name(self):
        name = self.cleaned_data.get('name')
        if TemplatePartyService().filter(name=name).exists():
            raise ValidationError("Template with such name already exists")

        return name
Пример #16
0
    def save(self, commit=True):
        schedule = self.cleaned_data.get('schedule')
        TemplatePartyService().set_frequency(self.template, schedule)

        return self.template