Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
others = []
series = [{"name": l[0].name, "y": l[1]} for l in label_zones]
# if there are remaining items, merge into single "Other" zone
if others:
series.append({"name": str(_("Other")), "y": sum([o[1] for o in others])})
return {"series": series}
class DailyCountExportCRUDL(SmartCRUDL):
model = DailyCountExport
actions = ("create", "read")
class Create(NonAtomicMixin, OrgPermsMixin, SmartCreateView):
def post(self, request, *args, **kwargs):
of_type = request.json["type"]
# parse dates and adjust max so it's exclusive
after = parse_iso8601(request.json["after"]).date()
before = parse_iso8601(request.json["before"]).date() + timedelta(days=1)
export = DailyCountExport.create(self.request.org, self.request.user, of_type, after, before)
daily_count_export.delay(export.pk)
return JsonResponse({"export_id": export.pk})
class Read(BaseDownloadView):
title = _("Download Export")
filename = "daily_count_export.xls"
if self.success_message is None:
return _("Your new %s has been created.") % self.model._meta.verbose_name
else:
return self.success_message
def derive_title(self):
"""
Derives our title from our object
"""
if not self.title:
return _("Create %s") % force_text(self.model._meta.verbose_name).title()
else:
return self.title
class SmartCSVImportView(NonAtomicMixin, SmartCreateView):
success_url = 'id@csv_imports.importtask_read'
fields = ('csv_file',)
def derive_title(self):
return _("Import %s") % self.crudl.model._meta.verbose_name_plural.title()
def pre_save(self, obj):
obj = super(SmartCSVImportView, self).pre_save(obj)
obj.model_class = "%s.%s" % (self.crudl.model.__module__, self.crudl.model.__name__)
return obj
def post_save(self, task):
task = super(SmartCSVImportView, self).post_save(task)
task.import_params = json.dumps(self.form.data)
@classmethod
def derive_url_pattern(cls, path, action):
return r"^message/history/(?P\d+)/$"
def get(self, request, *args, **kwargs):
message = Message.objects.get(org=request.org, backend_id=int(kwargs["id"]))
actions = [a.as_json() for a in message.get_history()]
return JsonResponse({"actions": actions}, encoder=JSONEncoder)
class MessageExportCRUDL(SmartCRUDL):
model = MessageExport
actions = ("create", "read")
class Create(NonAtomicMixin, OrgPermsMixin, MessageSearchMixin, SmartCreateView):
def post(self, request, *args, **kwargs):
search = self.derive_search()
export = MessageExport.create(self.request.org, self.request.user, search)
message_export.delay(export.pk)
return JsonResponse({"export_id": export.pk})
class Read(BaseDownloadView):
title = _("Download Messages")
filename = "message_export.xls"
class ReplySearchMixin(object):
def derive_search(self):
"""
"""
Endpoint for unwatching a case
"""
permission = "cases.case_read"
def post(self, request, *args, **kwargs):
self.get_object().unwatch(request.user)
return HttpResponse(status=204)
class CaseExportCRUDL(SmartCRUDL):
model = CaseExport
actions = ("create", "read")
class Create(NonAtomicMixin, OrgPermsMixin, CaseSearchMixin, SmartCreateView):
def post(self, request, *args, **kwargs):
search = self.derive_search()
export = self.model.create(self.request.org, self.request.user, search)
case_export.delay(export.pk)
return JsonResponse({"export_id": export.pk})
class Read(BaseDownloadView):
title = _("Download Cases")
filename = "case_export.xls"
class PartnerFormMixin(object):
def get_form_kwargs(self):
kwargs = super(PartnerFormMixin, self).get_form_kwargs()
def dispatch(self, request, *args, **kwargs):
return super(NonAtomicMixin, self).dispatch(request, *args, **kwargs)
"response": {
"delay": timesince(msg.reply_to.created_on, now=msg.created_on),
"warning": delay > RESPONSE_DELAY_WARN_SECONDS,
},
}
)
return obj
return JsonResponse({"results": [as_json(o) for o in outgoing], "has_more": has_more}, encoder=JSONEncoder)
class ReplyExportCRUDL(SmartCRUDL):
model = ReplyExport
actions = ("create", "read")
class Create(NonAtomicMixin, OrgPermsMixin, ReplySearchMixin, SmartCreateView):
def post(self, request, *args, **kwargs):
search = self.derive_search()
export = self.model.create(self.request.org, self.request.user, search)
reply_export.delay(export.pk)
return JsonResponse({"export_id": export.pk})
class Read(BaseDownloadView):
title = _("Download Replies")
filename = "reply_export.xls"
class FaqSearchMixin(object):
def derive_search(self):
"""