Example #1
0
    def post(self, request, requestion):
        form = ChangeRequestionForm(instance=requestion,
            data=request.POST)
        address_form = RequestionAddressForm(instance=requestion.address, data=request.POST)
        if form.is_valid() and address_form.is_valid():
            if form.has_changed() or address_form.has_changed():
                address = address_form.save()
                requestion = form.save(commit=False)
                requestion.address = address
                requestion.save()
#                write logs
                context_dict = {'changed_fields': form.changed_data,
                    'requestion': requestion}
                Logger.objects.create_for_action(CHANGE_REQUESTION,
                    context_dict=context_dict,
                    extra={'user': request.user, 'obj': requestion})
                messages.success(request, u'Изменения в заявке %s сохранены' % requestion)
            else:
                messages.info(request, u'Заявка %s не была изменена' % requestion)
            return HttpResponseRedirect(
                reverse('account_requestion_info',
                        kwargs={'requestion_id': requestion.id}))
        else:
            return self.render_to_response(
                {'form': form, 'requestion': requestion, 'address_form': address_form, 'openlayers_js': get_openlayers_js()})
Example #2
0
    def post(self, request, *args, **kwargs):
        context = self.get_context_data()
        form = RequestionForm(request.POST)
        address_form = RequestionAddressForm(request.POST)
        personal_data_approve_form = PersonalDataApproveForm(request.POST)
        if settings.FACILITY_STORE == settings.FACILITY_STORE_YES:
            benefits_form = BenefitsForm(data=request.POST)
        else:
            benefits_form = BenefitCategoryForm(data=request.POST)
        if (form.is_valid() and benefits_form.is_valid() and
                address_form.is_valid() and personal_data_approve_form.is_valid()):
            profile = request.user.get_profile()
            address = address_form.save()
            requestion = form.save(profile=profile)
            requestion.address = address
            requestion.save()
            pref_sadiks = form.cleaned_data.get('pref_sadiks')
            benefits_form.instance = requestion
            requestion = benefits_form.save()
            context_dict = {'requestion': requestion,
                'pref_sadiks': pref_sadiks,
                'areas': form.cleaned_data.get('areas')}
            context_dict.update(dict([(field, benefits_form.cleaned_data[field])
                for field in benefits_form.changed_data]))
            Logger.objects.create_for_action(ADD_REQUESTION,
                context_dict=context_dict, extra={
                'user': request.user, 'obj': requestion,
                'added_pref_sadiks': pref_sadiks})
            messages.info(request, u'Добавлена заявка %s' % requestion.requestion_number)
#            если были заданы типы льгот, то редирект на изменение документов
            if (settings.FACILITY_STORE == settings.FACILITY_STORE_YES and
                requestion.benefit_category != BenefitCategory.objects.category_without_benefits()):
                return HttpResponseRedirect(reverse("account_benefits_change", kwargs={'requestion_id': requestion.id}))
    #            иначе на страницу с информацией о заявке
            return HttpResponseRedirect(
                reverse('account_requestion_info',
                         kwargs={'requestion_id': requestion.id}))
        else:
            context.update({'form': form, 'benefits_form': benefits_form,
                'address_form': address_form,
                'personal_data_approve_form': personal_data_approve_form,
                'openlayers_js': get_openlayers_js()})
            return self.render_to_response(context)
Example #3
0
    def post(self, request):
        temp_password = User.objects.make_random_password()
        registration_form = OperatorRegistrationForm(data=request.POST,
            password=temp_password, prefix="user")
        profile_form = OperatorProfileRegistrationForm(request.POST,
            prefix="profile")
        requestion_form = OperatorRequestionForm(request.POST,
            prefix="requestion")
        address_form = RequestionAddressForm(request.POST)
        if settings.FACILITY_STORE == settings.FACILITY_STORE_YES:
            benefits_form = BenefitsForm(data=request.POST)
        else:
            benefits_form = BenefitCategoryForm(data=request.POST)
        if (registration_form.is_valid() and profile_form.is_valid() and
            requestion_form.is_valid() and benefits_form.is_valid() and address_form.is_valid()):
            user = registration_form.save()
            #        задаем права
            permission = Permission.objects.get(codename=u'is_requester')
            user.user_permissions.add(permission)
            profile = profile_form.save(user=user)
            address = address_form.save()
            requestion = requestion_form.save(profile=profile)
            requestion.address = address
            requestion.save()
            benefits_form.instance = requestion
            requestion = benefits_form.save()
            added_pref_sadiks = requestion_form.cleaned_data.get('pref_sadiks')
            context_dict = {'requestion': requestion,
                          'pref_sadiks': requestion.pref_sadiks.all(),
                          'areas': requestion_form.cleaned_data.get('areas')}
            context_dict.update(dict([(field, benefits_form.cleaned_data[field])
                for field in benefits_form.changed_data]))
#            если указан email, то отсылаем почту
            if user.email:
                verification_key_object = VerificationKey.objects.create_key(user)
                verification_key_object.send_email_verification(password=temp_password)
            Logger.objects.create_for_action(CREATE_PROFILE,
                context_dict={'user': user, 'profile': profile},
                extra={'user': request.user, 'obj': profile})
            Logger.objects.create_for_action(REQUESTION_REGISTRATION,
                context_dict=context_dict,
                extra={'user': request.user, 'obj': requestion,
                    'added_pref_sadiks': added_pref_sadiks, })
            messages.info(request,
                u'Регистрация пользователя прошла успешно. Создана заявка %s' %
                requestion.requestion_number)
#            если были заданы типы льгот, то редирект на изменение документов
            if (settings.FACILITY_STORE == settings.FACILITY_STORE_YES and
                requestion.benefit_category != BenefitCategory.objects.category_without_benefits()):
                return HttpResponseRedirect(reverse("operator_benefits_change", kwargs={'requestion_id': requestion.id}))
#            иначе на страницу с информацией о заявке
            return HttpResponseRedirect(
                reverse('operator_requestion_info',
                    kwargs={'requestion_id': requestion.id}))


        context = {'registration_form': registration_form,
            'profile_form': profile_form,
            'requestion_form': requestion_form, 'address_form': address_form,
            'openlayers_js': get_openlayers_js()}
        return self.render_to_response(context)