Ejemplo n.º 1
0
    def delete(self, request, *args, **kwargs):
        sid = transaction.savepoint()
        try:
            association = Association.objects.get(
                id=UserToken.get_association_id(request.session))
            if Enterprise.objects.filter(headquar__association_id=UserToken.get_association_id(request.session)).count() == 1:
                raise Exception(
                    (u"Asociación <b>%(name)s</b> no puede quedar sin ninguna sede asociada.") % {"name": association.name})

            d = self.get_object()
            # rastrear dependencias
            deps, msg = get_dep_objects(d)
            if deps:
                messages.warning(self.request,  _('Cannot delete %(name)s') % {
                    "name": capfirst(force_text(self.model._meta.verbose_name))
                    + ' "' + force_text(d) + '"'
                })
                raise Exception(msg)

            d.delete()
            msg = _('The %(name)s "%(obj)s" was deleted successfully.') % {
                'name': capfirst(force_text(self.model._meta.verbose_name)),
                'obj': force_text(d)
            }
            if not d.id:
                messages.success(self.request, msg)
                log.warning(msg, extra=log_params(self.request))
        except Exception, e:
            try:
                transaction.savepoint_rollback(sid)
            except:
                pass
            messages.error(request, e)
            log.warning(force_text(e), extra=log_params(self.request))
Ejemplo n.º 2
0
    def form_valid(self, form):
        sid = transaction.savepoint()
        try:
            self.object = form.save(commit=True)
            headquar = Headquar()
            headquar.name = self.request.POST.get("sede")
            headquar.association_id = UserToken.get_association_id(
                self.request.session)
            headquar.enterprise = self.object
            headquar.save()

            msg = _('The %(name)s "%(obj)s" was added successfully.') % {
                'name': capfirst(force_text(self.model._meta.verbose_name)),
                'obj': force_text(self.object)
            }
            if self.object.id:
                messages.success(self.request, msg)
                log.warning(msg, extra=log_params(self.request))
            return super(EnterpriseCreateView, self).form_valid(form)
        except Exception as e:
            try:
                transaction.savepoint_rollback(sid)
            except:
                pass
            messages.success(self.request, e)
            log.warning(force_text(e), extra=log_params(self.request))
            return super(EnterpriseCreateView, self).form_invalid(form)
Ejemplo n.º 3
0
    def form_valid(self, form):
        sid = transaction.savepoint()
        try:
            self.object = form.save(commit=True)
            headquar = Headquar()
            headquar.name = self.request.POST.get("sede")
            headquar.association_id = UserToken.get_association_id(
                self.request.session)
            headquar.enterprise = self.object
            headquar.save()

            msg = _('The %(name)s "%(obj)s" was added successfully.') % {
                'name': capfirst(force_text(self.model._meta.verbose_name)),
                'obj': force_text(self.object)
            }
            if self.object.id:
                messages.success(self.request, msg)
                log.warning(msg, extra=log_params(self.request))
            return super(EnterpriseCreateView, self).form_valid(form)
        except Exception, e:
            try:
                transaction.savepoint_rollback(sid)
            except:
                pass
            messages.success(self.request, e)
            log.warning(force_text(e), extra=log_params(self.request))
            return super(EnterpriseCreateView, self).form_invalid(form)
Ejemplo n.º 4
0
 def dispatch(self, request, *args, **kwargs):
     self.kwargs['pk'] = UserToken.get_association_id(request.session)
     msg = _(u'%s is not selected or not found in the database.') % _(
         'Association')
     try:
         self.get_object()
     except Exception, e:
         messages.error(self.request, e)
         messages.warning(self.request, msg)
         return HttpResponseRedirect(reverse_lazy('accounts:index'))
Ejemplo n.º 5
0
 def get_queryset(self):
     self.o = empty(self.request, 'o', '-id')
     self.f = empty(self.request, 'f', 'name')
     self.q = empty(self.request, 'q', '')
     column_contains = u'%s__%s' % (self.f, 'contains')
     return self.model.objects.filter(
         headquar__association_id=UserToken.get_association_id(
             self.request.session)
     ).annotate(num_sedes=Count("headquar")).filter(
         **{column_contains: self.q}).order_by(self.o).distinct()
Ejemplo n.º 6
0
 def get_queryset(self):
     self.o = empty(self.request, 'o', '-id')
     self.f = empty(self.request, 'f', 'name')
     self.q = empty(self.request, 'q', '')
     column_contains = u'%s__%s' % (self.f, 'contains')
     return self.model.objects.filter(
         headquar__association_id=UserToken.get_association_id(
             self.request.session)).annotate(
                 num_sedes=Count("headquar")).filter(**{
                     column_contains: self.q
                 }).order_by(self.o).distinct()
Ejemplo n.º 7
0
    def delete(self, request, *args, **kwargs):
        sid = transaction.savepoint()
        try:
            association = Association.objects.get(
                id=UserToken.get_association_id(request.session))
            if Enterprise.objects.filter(
                    headquar__association_id=UserToken.get_association_id(
                        request.session)).count() == 1:
                raise Exception((
                    u"Asociación <b>%(name)s</b> no puede quedar sin ninguna sede asociada."
                ) % {"name": association.name})

            d = self.get_object()
            # rastrear dependencias
            deps, msg = get_dep_objects(d)
            if deps:
                messages.warning(
                    self.request,
                    _('Cannot delete %(name)s') % {
                        "name":
                        capfirst(force_text(self.model._meta.verbose_name)) +
                        ' "' + force_text(d) + '"'
                    })
                raise Exception(msg)

            d.delete()
            msg = _('The %(name)s "%(obj)s" was deleted successfully.') % {
                'name': capfirst(force_text(self.model._meta.verbose_name)),
                'obj': force_text(d)
            }
            if not d.id:
                messages.success(self.request, msg)
                log.warning(msg, extra=log_params(self.request))
        except Exception as e:
            try:
                transaction.savepoint_rollback(sid)
            except:
                pass
            messages.error(request, e)
            log.warning(force_text(e), extra=log_params(self.request))
        return HttpResponseRedirect(self.success_url)
Ejemplo n.º 8
0
    def dispatch(self, request, *args, **kwargs):
        association_id = UserToken.get_association_id(request.session)
        msg = _(u'%s is not selected or not found in the database.') % _(
            'Association')
        try:
            Association.objects.get(pk=association_id)
        except Exception as e:
            messages.error(self.request, e)
            messages.warning(self.request, msg)
            return HttpResponseRedirect(reverse_lazy('accounts:index'))

        return super(EnterpriseListView, self).dispatch(request, *args, **kwargs)
Ejemplo n.º 9
0
    def dispatch(self, request, *args, **kwargs):
        self.kwargs['pk'] = UserToken.get_association_id(request.session)
        msg = _(u'%s is not selected or not found in the database.') % _(
            'Association')
        try:
            self.get_object()
        except Exception as e:
            messages.error(self.request, e)
            messages.warning(self.request, msg)
            return HttpResponseRedirect(reverse_lazy('accounts:index'))

        return super(AssociationUpdateView,
                     self).dispatch(request, *args, **kwargs)
Ejemplo n.º 10
0
    def form_valid(self, form):
        try:
            form.instance.association_id = UserToken.get_association_id(
                self.request.session)
            form.instance.enterprise_id = UserToken.get_enterprise_id(
                self.request.session)

            self.object = form.save(commit=True)
            msg = _('The %(name)s "%(obj)s" was added successfully.') % {
                'name': capfirst(force_text(self.model._meta.verbose_name)),
                'obj': force_text(self.object)
            }
            if self.object.id:
                messages.success(self.request, msg)
                log.warning(msg, extra=log_params(self.request))
            return super(HeadquarCreateView, self).form_valid(form)
        except Exception as e:
            messages.error(self.request, e)
            log.warning(force_text(e), extra=log_params(self.request))
            return super(HeadquarCreateView, self).form_invalid(form)
Ejemplo n.º 11
0
    def form_valid(self, form):
        try:
            form.instance.association_id = UserToken.get_association_id(
                self.request.session)
            form.instance.enterprise_id = UserToken.get_enterprise_id(
                self.request.session)

            self.object = form.save(commit=True)
            msg = _('The %(name)s "%(obj)s" was added successfully.') % {
                'name': capfirst(force_text(self.model._meta.verbose_name)),
                'obj': force_text(self.object)
            }
            if self.object.id:
                messages.success(self.request, msg)
                log.warning(msg, extra=log_params(self.request))
            return super(HeadquarCreateView, self).form_valid(form)
        except Exception, e:
            messages.error(self.request, e)
            log.warning(force_text(e), extra=log_params(self.request))
            return super(HeadquarCreateView, self).form_invalid(form)