Пример #1
0
 def post(self, request, requestion):
     u"""
     метод скопирован из родительского BenefitsChange,
     но после успешного сохранения другой редирект.
     Также предполагается другая запись логов
     """
     benefits_form = BenefitsForm(
         data=request.POST,
         instance=requestion)
     if benefits_form.is_valid():
         benefits_form.save()
         context_dict = dict([(field, benefits_form.cleaned_data[field])
             for field in benefits_form.changed_data])
         context_dict.update({"requestion": requestion})
         Logger.objects.create_for_action(CHANGE_BENEFITS,
             context_dict=context_dict,
             extra={'user': request.user, 'obj': requestion})
         messages.success(request, u'Льготы для заявки %s были изменены' %
             requestion.requestion_number)
         return HttpResponseRedirect(
             reverse('operator_requestion_info',
                 kwargs={'requestion_id': requestion.id}))
     else:
         return self.render_to_response({
             'requestion': requestion,
             'benefits_form': benefits_form,
             'documents': self.get_own_documents(requestion),
         })
Пример #2
0
 def post(self, request, requestion):
     benefits_form = BenefitsForm(
         data=request.POST,
         instance=requestion)
     if benefits_form.is_valid():
         benefits_form.save()
         context_dict = dict([(field, benefits_form.cleaned_data[field])
             for field in benefits_form.changed_data])
         context_dict.update({"requestion": requestion})
         Logger.objects.create_for_action(CHANGE_BENEFITS,
             context_dict=context_dict,
             extra={'user': request.user, 'obj': requestion})
         messages.success(request, u'Льготы для заявки %s были изменены' %
             requestion.requestion_number)
         return HttpResponseRedirect(
             reverse('account_requestion_info',
                 kwargs={'requestion_id': requestion.id}))
     else:
         return self.render_to_response({
             'requestion': requestion,
             'benefits_form': benefits_form,
             'documents': self.get_own_documents(requestion),
         })
Пример #3
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)
Пример #4
0
    def post(self, request, requestion):
        context = self.get_context_data(requestion)
        change_requestion_form = self.change_requestion_form(
            request.POST, instance=requestion)
        change_benefits_form = BenefitsForm(request.POST, instance=requestion)
        pref_sadiks_form = PreferredSadikForm(request.POST, instance=requestion)
        DocumentFormset = self.get_documents_formset()
        if DocumentFormset:
            formset = self.get_documents_formset()(request.POST,
                instance=requestion, queryset=EvidienceDocument.objects.filter(
                template__destination=BENEFIT_DOCUMENT))
        else:
            formset = None
        can_change_benefits = self.can_change_benefits(requestion)
        if not requestion.editable:
            messages.error(request, u'Заявка %s не может быть изменена' % requestion)
            return HttpResponseRedirect(reverse('account_requestion_info', args=[requestion.id]))
        if all((change_requestion_form.is_valid(), change_benefits_form.is_valid(),
                pref_sadiks_form.is_valid(), (not formset or formset.is_valid()))):
            context_dict = {'requestion': requestion, 'changed_data': [], 'cleaned_data': {}}
            data_changed = False
            extra = {'user': request.user, 'obj': requestion}
            if change_requestion_form.has_changed():
                data_changed = True
                change_requestion_form.save()
                context_dict['changed_data'].extend(change_requestion_form.changed_data)
                context_dict['cleaned_data'].update(change_requestion_form.cleaned_data)
            # изменение льгот возможно только для документально неподтврежденных
            if can_change_benefits:
                if change_benefits_form.has_changed():
                    data_changed = True
                    change_benefits_form.save()
                    context_dict['changed_data'].extend(change_benefits_form.changed_data)
                    context_dict['cleaned_data'].update(change_benefits_form.cleaned_data)
                if formset and formset.has_changed():
                    benefit_documents = formset.save()
                    data_changed = True
                    context_dict['cleaned_data'].update({'benefit_documents': benefit_documents})
            if pref_sadiks_form.has_changed():
                data_changed = True
                pref_sadiks = set(requestion.pref_sadiks.all())
                pref_sadiks_form.save()
                new_pref_sadiks = set(requestion.pref_sadiks.all())
                added_pref_sadiks = new_pref_sadiks - pref_sadiks
                removed_pref_sadiks = pref_sadiks - new_pref_sadiks
                context_dict['changed_data'].extend(pref_sadiks_form.changed_data)
                context_dict['cleaned_data'].update(pref_sadiks_form.cleaned_data)
                extra.update({'added_pref_sadiks': added_pref_sadiks})
                extra.update({'removed_pref_sadiks': removed_pref_sadiks})
            if data_changed:
                if 'location' in context_dict['changed_data']:
                    find_closest_kg(requestion, save=True)
                Logger.objects.create_for_action(self.logger_action,
                    context_dict=context_dict, extra=extra)
                messages.success(request, u'Изменения в заявке %s сохранены' % requestion)
            else:
                messages.error(request, u'Заявка %s не была изменена' % requestion)
            return HttpResponseRedirect(self.redirect_to(requestion))
        context.update({
            'formset': formset,
            'change_requestion_form': change_requestion_form,
            'change_benefits_form': change_benefits_form,
            'pref_sadiks_form': pref_sadiks_form,
            'use_districts': USE_DISTRICTS,

        })
        return self.render_to_response(context)
Пример #5
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)