How to use the smartmin.views.SmartDeleteView function in smartmin

To help you get started, we’ve selected a few smartmin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rapidpro / casepro / casepro / profiles / views.py View on Github external
edit_button_url = reverse("profiles.user_update", args=[self.object.pk])
                can_delete = bool(org)  # can only delete in context of an org
            else:
                edit_button_url = None
                can_delete = False

            context["context_data_json"] = {"user": self.object.as_json(full=True, org=org)}
            context["edit_button_url"] = edit_button_url
            context["can_delete"] = can_delete
            context["summary"] = self.get_summary(org, self.object) if org else {}
            return context

        def get_summary(self, org, user):
            return {"total_replies": DailyCount.get_by_user(org, [user], DailyCount.TYPE_REPLIES, None, None).total()}

    class Delete(OrgPermsMixin, SmartDeleteView):
        cancel_url = "@profiles.user_list"

        def has_permission(self, request, *args, **kwargs):
            user = self.get_object()
            return request.user.can_edit(request.org, user) and request.user != user

        def get_queryset(self):
            return self.request.org.get_users()

        def post(self, request, *args, **kwargs):
            user = self.get_object()
            user.remove_from_org(request.org)

            return HttpResponse(status=204)

    class List(OrgPermsMixin, SmartListView):
github nyaruka / smartmin / smartmin / views.py View on Github external
elif action == 'update':
                if 'delete' in self.actions:
                    options['delete_url'] = 'id@%s' % self.url_name_for_action('delete')

                view = type(str("%sUpdateView" % self.model_name), (SmartUpdateView,), options)

            elif action == 'delete':
                if 'list' in self.actions:
                    options['cancel_url'] = '@%s' % self.url_name_for_action('list')
                    options['redirect_url'] = '@%s' % self.url_name_for_action('list')

                elif 'update' in self.actions:
                    options['cancel_url'] = '@%s' % self.url_name_for_action('update')

                view = type(str("%sDeleteView" % self.model_name), (SmartDeleteView,), options)

            elif action == 'list':
                if 'read' in self.actions:
                    options['link_url'] = 'id@%s' % self.url_name_for_action('read')
                elif 'update' in self.actions:
                    options['link_url'] = 'id@%s' % self.url_name_for_action('update')
                else:
                    options['link_fields'] = ()

                if 'create' in self.actions:
                    options['add_button'] = True

                view = type(str("%sListView" % self.model_name), (SmartListView,), options)

            elif action == 'csv_import':
                options['model'] = ImportTask
github rapidpro / casepro / casepro / msgs / views.py View on Github external
kwargs["org"] = self.request.org
            return kwargs

        def derive_initial(self):
            initial = super(FaqCRUDL.Update, self).derive_initial()
            initial["labels"] = self.object.labels.all()
            return initial

        def derive_fields(self):
            fields = ["question", "answer", "language", "parent"]
            if not self.object.parent:
                fields.append("labels")

            return tuple(fields)

    class Delete(OrgPermsMixin, SmartDeleteView):
        cancel_url = "@msgs.faq_list"

        def post(self, request, *args, **kwargs):
            faq = self.get_object()
            faq.release()

            return HttpResponse(status=204)

    class Search(OrgPermsMixin, FaqSearchMixin, SmartTemplateView):
        """
        JSON endpoint for searching FAQs
        """

        def get_context_data(self, **kwargs):
            context = super(FaqCRUDL.Search, self).get_context_data(**kwargs)
github nyaruka / smartmin / smartmin / views.py View on Github external
def get_context_data(self, **kwargs):
        """ Add in the field to use for the name field """
        context = super(SmartDeleteView, self).get_context_data(**kwargs)
        context['name_field'] = self.name_field
        context['cancel_url'] = self.get_cancel_url()
        return context
github rapidpro / casepro / casepro / cases / views.py View on Github external
user_partner = self.request.user.get_partner(self.object.org)

            context["can_manage"] = self.request.user.can_manage(self.object)
            context["can_view_replies"] = not user_partner or user_partner == self.object
            context["labels"] = self.object.get_labels()
            context["summary"] = self.get_summary(self.object)
            return context

        def get_summary(self, partner):
            return {
                "total_replies": DailyCount.get_by_partner([partner], DailyCount.TYPE_REPLIES).total(),
                "cases_open": Case.objects.filter(org=partner.org, assignee=partner, closed_on=None).count(),
                "cases_closed": Case.objects.filter(org=partner.org, assignee=partner).exclude(closed_on=None).count(),
            }

    class Delete(OrgObjPermsMixin, SmartDeleteView):
        cancel_url = "@cases.partner_list"

        def post(self, request, *args, **kwargs):
            partner = self.get_object()
            partner.release()
            return HttpResponse(status=204)

    class List(OrgPermsMixin, SmartListView):
        paginate_by = None

        def get_queryset(self, **kwargs):
            return Partner.get_all(self.request.org).order_by("name")

        def render_to_response(self, context, **response_kwargs):
            if self.request.is_ajax():
                with_activity = str_to_bool(self.request.GET.get("with_activity", ""))
github rapidpro / casepro / casepro / msgs / views.py View on Github external
def get_context_data(self, **kwargs):
            context = super(LabelCRUDL.Read, self).get_context_data(**kwargs)

            # augment usual label JSON
            label_json = self.object.as_json()
            label_json["watching"] = self.object.is_watched_by(self.request.user)

            # angular app requires context data in JSON format
            context["context_data_json"] = {"label": label_json}

            context["rule_tests"] = self.object.rule.get_tests_description() if self.object.rule else ""

            return context

    class Delete(OrgObjPermsMixin, SmartDeleteView):
        cancel_url = "@msgs.label_list"

        def post(self, request, *args, **kwargs):
            label = self.get_object()
            label.release()
            return HttpResponse(status=204)

    class List(OrgPermsMixin, SmartListView):
        def get(self, request, *args, **kwargs):
            with_activity = str_to_bool(self.request.GET.get("with_activity", ""))
            labels = list(Label.get_all(self.request.org, self.request.user).order_by("name"))
            Label.bulk_cache_initialize(labels)

            if with_activity:
                # get message statistics
                this_month = DailyCount.get_by_label(labels, DailyCount.TYPE_INCOMING, *month_range(0)).scope_totals()