예제 #1
0
    def post(self, request, *args, **kwargs):
        with atomic():
            preply = self.get_related_entity()
            self.clean(preply)

        # if request.is_ajax():
        if is_ajax(request):
            return HttpResponse()

        return redirect(preply)
예제 #2
0
    def post(self, request, *args, **kwargs):
        # TODO: <return self.delete(request, *args, **kwargs)> ?
        self.perform_deletion(self.request)

        return (
            HttpResponse(self.get_ajax_success_url(), content_type='text/plain')
            # if request.is_ajax() else
            if is_ajax(request) else
            HttpResponseRedirect(self.get_success_url())
        )
예제 #3
0
파일: sending.py 프로젝트: mrjmad/creme_crm
def delete(request):
    sending = get_object_or_404(Sending,
                                id=get_from_POST_or_404(request.POST, 'id'))
    campaign = sending.campaign

    request.user.has_perm_to_change_or_die(campaign)

    sending.delete()  # TODO: try/except ??

    # if request.is_ajax():
    if is_ajax(request):
        return HttpResponse('success')  # TODO: no message, status is OK...

    return redirect(campaign)
예제 #4
0
파일: convert.py 프로젝트: mrjmad/creme_crm
    def post(self, *args, **kwargs):
        src = self.get_related_entity()
        dest_class = self.get_destination_model(src)

        with atomic():
            dest = dest_class()
            dest.build(src)
            dest.name = self.dest_title.format(src=src, dest=dest)
            dest.generate_number()
            dest.save()

        url = dest.get_absolute_url()

        return (http.HttpResponse(url, content_type='text/plain')
                # if self.request.is_ajax() else
                if is_ajax(self.request) else http.HttpResponseRedirect(url))
예제 #5
0
파일: sending.py 프로젝트: mrjmad/creme_crm
def delete_message(request):
    message = get_object_or_404(Message,
                                id=get_from_POST_or_404(request.POST, 'id'))
    campaign = message.sending.campaign

    request.user.has_perm_to_change_or_die(campaign)

    try:
        message.sync_delete()
        message.delete()
    except Exception as e:
        return HttpResponse(e, status=500)  # TODO: WTF ?!

    # if request.is_ajax():
    if is_ajax(request):
        return HttpResponse('success')  # TODO: no message, status is OK...

    return redirect(campaign)
예제 #6
0
def disable_line(request, line_id):
    if request.method != 'POST':
        raise Http404('This view uses POST method.')

    line = get_object_or_404(PollFormLine, pk=line_id)
    pform = line.pform

    request.user.has_perm_to_change_or_die(pform)

    try:
        line.disable()
    except ProtectedError as e:
        raise PermissionDenied(e.args[0]) from e

    # if request.is_ajax():
    if is_ajax(request):
        return HttpResponse()

    return redirect(pform)
예제 #7
0
    def process_exception(self, request, exception):
        if self.error is None or isinstance(exception, self.error):
            # msg = smart_text(exception)
            msg = smart_str(exception)

            # if request.is_ajax():
            if is_ajax(request):
                if self.log_ajax:
                    logger.exception('Error (status=%s)', self.status)

                return HttpResponse(msg, status=self.status)

            if self.template is None:
                return

            return render(
                request,
                self.template,
                {'error_message': msg},
                status=self.status,
            )
예제 #8
0
파일: billing.py 프로젝트: mrjmad/creme_crm
    def post(self, request, *args, **kwargs):
        user = request.user
        action = self.kwargs[self.action_url_kwarg]
        opp_id = self.kwargs[self.opp_id_url_kwarg]
        quote_id = self.kwargs[self.quote_id_url_kwarg]

        has_perm_or_die = (user.has_perm_to_link_or_die
                           if action == 'set_current' else
                           user.has_perm_to_unlink_or_die)

        opp = get_object_or_404(Opportunity, pk=opp_id)
        has_perm_or_die(opp)

        quote = get_object_or_404(Quote, pk=quote_id)
        has_perm_or_die(quote)

        kwargs = {
            'subject_entity': quote,
            'type_id': self.rtype_id,
            'object_entity': opp,
            'user': user,
        }

        relations = Relation.objects.filter(**kwargs)

        if action == 'set_current':
            if not relations:
                Relation.objects.safe_create(**kwargs)
        else:  # action == 'unset_current':
            relations.delete()

        # if request.is_ajax():
        if is_ajax(request):
            return HttpResponse()

        return redirect(opp)
예제 #9
0
파일: billing.py 프로젝트: mrjmad/creme_crm
    def post(self, request, *args, **kwargs):
        klass = self.get_ctype().model_class()

        try:
            rtype_id, set_as_current, workflow_action = self.behaviours[klass]
        except KeyError as e:
            raise Http404('Bad billing document type') from e

        user = request.user
        user.has_perm_to_create_or_die(klass)
        # TODO: check in template too (must upgrade 'has_perm' to use owner!=None)
        user.has_perm_to_link_or_die(klass, owner=user)

        opp = self.get_related_entity()

        b_document = klass.objects.create(
            user=user,
            issuing_date=now(),
            status_id=1,
            currency=opp.currency,
            source=opp.emitter,
            target=opp.target,
        )

        create_relation = partial(
            Relation.objects.create,
            subject_entity=b_document,
            user=user,
        )
        create_relation(type_id=rtype_id, object_entity=opp)

        b_document.generate_number(
        )  # Need the relationship with emitter organisation
        b_document.name = self.generated_name.format(document=b_document,
                                                     opportunity=opp)
        b_document.save()

        relations = Relation.objects.filter(
            subject_entity=opp.id,
            type__in=[
                constants.REL_OBJ_LINKED_PRODUCT,
                constants.REL_OBJ_LINKED_SERVICE,
            ],
        ).select_related('object_entity')

        # TODO: Missing test case
        if relations:
            Relation.populate_real_object_entities(relations)
            vat_value = Vat.get_default_vat()
            Product = get_product_model()

            for relation in relations:
                item = relation.object_entity.get_real_entity()
                line_klass = ProductLine if isinstance(
                    item, Product) else ServiceLine
                line_klass.objects.create(
                    related_item=item,
                    related_document=b_document,
                    unit_price=item.unit_price,
                    unit=item.unit,
                    vat_value=vat_value,
                )

        if set_as_current:
            create_relation(type_id=constants.REL_SUB_CURRENT_DOC,
                            object_entity=opp)

        if workflow_action:
            workflow_action(opp.emitter, opp.target, user)

        # if request.is_ajax():
        if is_ajax(request):
            return HttpResponse()

        return redirect(opp)