def update(self, request, pk, *args, **kwargs):
if 'xls_file' in request.FILES or 'text_xls_form' in request.data:
# A new XLSForm has been uploaded and will replace the existing
# form
existing_xform = get_object_or_404(XForm, pk=pk)
# Behave like `onadata.apps.main.views.update_xform`: only allow
# the update to proceed if the user is the owner
owner = existing_xform.user
if request.user.pk != owner.pk:
raise exceptions.PermissionDenied(
detail=_("Only a form's owner can overwrite its contents"))
survey = utils.publish_xlsform(request, owner, existing_xform)
if not isinstance(survey, XForm):
if isinstance(survey, dict) and 'text' in survey:
# Typical error text; pass it along
raise exceptions.ParseError(detail=survey['text'])
else:
# Something odd; hopefully it can be coerced into a string
raise exceptions.ParseError(detail=survey)
# Let the superclass handle updates to the other fields
# noti = existing_xform.logs.create(source=request.user, type=7, title="Kobo form Updated",
# organization=request.organization,
# description="new kobo form {0} Updated by {1}".
# format(existing_xform.title, request.user.username))
# result = {}
# result['description'] = noti.description
# result['url'] = noti.get_absolute_url()
# ChannelGroup("notify-0").send({"text":json.dumps(result)})
# if noti.organization:
# ChannelGroup("notify-{}".format(noti.organization.id)).send({"text":json.dumps(result)})
return super(XFormViewSet, self).update(request, pk, *args, **kwargs)
评论列表
文章目录