本文整理汇总了Python中main.models.MetaData.media_upload方法的典型用法代码示例。如果您正苦于以下问题:Python MetaData.media_upload方法的具体用法?Python MetaData.media_upload怎么用?Python MetaData.media_upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类main.models.MetaData
的用法示例。
在下文中一共展示了MetaData.media_upload方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
def edit(request, username, id_string):
xform = XForm.objects.get(user__username=username, id_string=id_string)
if username == request.user.username or request.user.has_perm("odk_logger.change_xform", xform):
if request.POST.get("description"):
xform.description = request.POST["description"]
elif request.POST.get("title"):
xform.title = request.POST["title"]
elif request.POST.get("toggle_shared"):
if request.POST["toggle_shared"] == "data":
xform.shared_data = not xform.shared_data
elif request.POST["toggle_shared"] == "form":
xform.shared = not xform.shared
elif request.POST["toggle_shared"] == "active":
xform.downloadable = not xform.downloadable
elif request.POST.get("form-license"):
MetaData.form_license(xform, request.POST["form-license"])
elif request.POST.get("data-license"):
MetaData.data_license(xform, request.POST["data-license"])
elif request.POST.get("source") or request.FILES.get("source"):
MetaData.source(xform, request.POST.get("source"), request.FILES.get("source"))
elif request.FILES.get("media"):
MetaData.media_upload(xform, request.FILES.get("media"))
elif request.POST.get("map_name"):
mapbox_layer = MapboxLayerForm(request.POST)
if mapbox_layer.is_valid():
MetaData.mapbox_layer_upload(xform, mapbox_layer.cleaned_data)
elif request.FILES:
MetaData.supporting_docs(xform, request.FILES["doc"])
xform.update()
if request.is_ajax():
return HttpResponse("Updated succeeded.")
else:
return HttpResponseRedirect(reverse(show, kwargs={"username": username, "id_string": id_string}))
return HttpResponseForbidden("Update failed.")
示例2: edit
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
def edit(request, username, id_string):
xform = XForm.objects.get(user__username=username, id_string=id_string)
if request.GET.get("crowdform"):
crowdform_action = request.GET["crowdform"]
request_username = request.user.username
# ensure is crowdform
if xform.is_crowd_form:
if crowdform_action == "delete":
MetaData.objects.get(
xform__id_string=id_string, data_value=request_username, data_type=MetaData.CROWDFORM_USERS
).delete()
elif crowdform_action == "add":
MetaData.crowdform_users(xform, request_username)
return HttpResponseRedirect(reverse(profile, kwargs={"username": request_username}))
if username == request.user.username or request.user.has_perm("odk_logger.change_xform", xform):
if request.POST.get("description"):
xform.description = request.POST["description"]
elif request.POST.get("title"):
xform.title = request.POST["title"]
elif request.POST.get("toggle_shared"):
if request.POST["toggle_shared"] == "data":
xform.shared_data = not xform.shared_data
elif request.POST["toggle_shared"] == "form":
xform.shared = not xform.shared
elif request.POST["toggle_shared"] == "active":
xform.downloadable = not xform.downloadable
elif request.POST["toggle_shared"] == "crowd":
if xform.is_crowd_form:
xform.is_crowd_form = False
else:
xform.is_crowd_form = True
xform.shared = True
xform.shared_data = True
elif request.POST.get("form-license"):
MetaData.form_license(xform, request.POST["form-license"])
elif request.POST.get("data-license"):
MetaData.data_license(xform, request.POST["data-license"])
elif request.POST.get("source") or request.FILES.get("source"):
MetaData.source(xform, request.POST.get("source"), request.FILES.get("source"))
elif request.FILES.get("media"):
MetaData.media_upload(xform, request.FILES.get("media"))
elif request.POST.get("map_name"):
mapbox_layer = MapboxLayerForm(request.POST)
if mapbox_layer.is_valid():
MetaData.mapbox_layer_upload(xform, mapbox_layer.cleaned_data)
elif request.FILES:
MetaData.supporting_docs(xform, request.FILES["doc"])
xform.update()
if request.is_ajax():
return HttpResponse(_(u"Updated succeeded."))
else:
return HttpResponseRedirect(reverse(show, kwargs={"username": username, "id_string": id_string}))
return HttpResponseForbidden(_(u"Update failed."))
示例3: formList
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
def formList(request, username):
render_formlist = False
formlist_user = get_object_or_404(User, username=username)
profile, created = UserProfile.objects.get_or_create(user=formlist_user)
if profile.require_auth:
# source, http://djangosnippets.org/snippets/243/
if 'HTTP_AUTHORIZATION' in request.META:
auth = request.META['HTTP_AUTHORIZATION'].split()
# NOTE: We are only support BASIC authentication for now.
if len(auth) == 2 and auth[0].lower() == "basic":
uname, passwd = base64.b64decode(auth[1]).split(':')
# ensure listing this user's forms
if formlist_user.username == uname:
user = authenticate(username=uname, password=passwd)
if user is not None and user.is_active:
render_formlist = True
else:
render_formlist = True
if render_formlist:
"""This is where ODK Collect gets its download list."""
xforms = XForm.objects.filter(downloadable=True, user__username=username)
urls = [
{'url': request.build_absolute_uri(xform.url()), 'text': xform.title
, 'media': {'m': MetaData.media_upload(xform), 'user': xform.user,
'id': xform.id_string}}
for xform in xforms
]
return render_to_response("formList.xml", {'urls': urls, 'host':
'http://%s' % request.get_host()}, mimetype="text/xml")
return HttpResponseNotAuthorized('Must be logged in')
示例4: test_metadata_file_hash
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
def test_metadata_file_hash(self):
self._publish_transportation_form()
src = os.path.join(self.this_directory, "fixtures",
"transportation", "screenshot.png")
uf = UploadedFile(file=open(src), content_type='image/png')
count = MetaData.objects.count()
MetaData.media_upload(self.xform, uf)
# assert successful insert of new metadata record
self.assertEqual(MetaData.objects.count(), count + 1)
md = MetaData.objects.get(xform=self.xform,
data_value='screenshot.png')
# assert checksum string has been generated, hash length > 1
self.assertTrue(len(md.hash) > 16)
md.data_file.storage.delete(md.data_file.name)
md = MetaData.objects.get(xform=self.xform,
data_value='screenshot.png')
self.assertEqual(len(md.hash), 0)
示例5: show
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
def show(request, username=None, id_string=None, uuid=None):
if uuid:
xform = get_object_or_404(XForm, uuid=uuid)
request.session["public_link"] = xform.uuid if MetaData.public_link(xform) else False
return HttpResponseRedirect(
reverse(show, kwargs={"username": xform.user.username, "id_string": xform.id_string})
)
xform, is_owner, can_edit, can_view = get_xform_and_perms(username, id_string, request)
# no access
if not (xform.shared or can_view or request.session.get("public_link")):
return HttpResponseRedirect(reverse(home))
context = RequestContext(request)
context.cloned = (
len(XForm.objects.filter(user__username=request.user.username, id_string=id_string + XForm.CLONED_SUFFIX)) > 0
)
context.public_link = MetaData.public_link(xform)
context.is_owner = is_owner
context.can_edit = can_edit
context.can_view = can_view or request.session.get("public_link")
context.xform = xform
context.content_user = xform.user
context.base_url = "https://%s" % request.get_host()
context.source = MetaData.source(xform)
context.form_license = MetaData.form_license(xform).data_value
context.data_license = MetaData.data_license(xform).data_value
context.supporting_docs = MetaData.supporting_docs(xform)
context.media_upload = MetaData.media_upload(xform)
context.mapbox_layer = MetaData.mapbox_layer_upload(xform)
if is_owner:
context.sms_support_form = ActivateSMSSupportFom(
initial={"enable_sms_support": xform.allows_sms, "sms_id_string": xform.sms_id_string}
)
if not xform.allows_sms:
context.sms_compatible = check_form_sms_compatibility(None, json_survey=json.loads(xform.json))
else:
url_root = request.build_absolute_uri("/")[:-1]
context.sms_providers_doc = providers_doc(url_root=url_root, username=username, id_string=id_string)
context.url_root = url_root
context.form_license_form = FormLicenseForm(initial={"value": context.form_license})
context.data_license_form = DataLicenseForm(initial={"value": context.data_license})
context.doc_form = SupportDocForm()
context.source_form = SourceForm()
context.media_form = MediaForm()
context.mapbox_layer_form = MapboxLayerForm()
users_with_perms = []
for perm in get_users_with_perms(xform, attach_perms=True).items():
has_perm = []
if "change_xform" in perm[1]:
has_perm.append(_(u"Can Edit"))
if "view_xform" in perm[1]:
has_perm.append(_(u"Can View"))
users_with_perms.append((perm[0], u" | ".join(has_perm)))
context.users_with_perms = users_with_perms
context.permission_form = PermissionForm(username)
if xform.allows_sms:
context.sms_support_doc = get_autodoc_for(xform)
return render_to_response("show.html", context_instance=context)
示例6: xformsManifest
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
def xformsManifest(request, username, id_string):
xform = get_object_or_404(XForm, id_string=id_string, user__username=username)
response = render_to_response("xformsManifest.xml", {
#'urls': urls,
'host': request.build_absolute_uri()\
.replace(request.get_full_path(), ''),
'media_files': MetaData.media_upload(xform)
}, mimetype="text/xml; charset=utf-8")
response['X-OpenRosa-Version'] = '1.0'
tz = pytz.timezone(settings.TIME_ZONE)
dt = datetime.now(tz).strftime('%a, %d %b %Y %H:%M:%S %Z')
response['Date'] = dt
return response
示例7: formList
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
def formList(request, username):
"""
This is where ODK Collect gets its download list.
"""
if username.lower() == 'crowdforms':
xforms = XForm.objects.filter(is_crowd_form=True)\
.exclude(user__username=username)
else:
formlist_user = get_object_or_404(User, username=username)
profile, created = \
UserProfile.objects.get_or_create(user=formlist_user)
if profile.require_auth:
response = helper_auth_helper(request)
if response:
return response
# unauthorized if user in auth request does not match user in path
# unauthorized if user not active
if formlist_user.username != request.user.username or\
not request.user.is_active:
return HttpResponseNotAuthorized()
xforms = \
XForm.objects.filter(downloadable=True, user__username=username)
# retrieve crowd_forms for this user
crowdforms = XForm.objects.filter(
metadata__data_type=MetaData.CROWDFORM_USERS,
metadata__data_value=username
)
xforms = chain(xforms, crowdforms)
urls = [{
'url': request.build_absolute_uri(xform.url()),
'text': xform.title if not xform.is_crowd_form else
'Crowd/%s' % xform.title,
'media': {
'm': MetaData.media_upload(xform),
'user': xform.user,
'id': xform.id_string
}
} for xform in xforms]
return render_to_response("formList.xml", {
'urls': urls,
'host': 'http://%s' % request.get_host()
}, mimetype="text/xml")
示例8: show
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
def show(request, username=None, id_string=None, uuid=None):
if uuid:
xform = get_object_or_404(XForm, uuid=uuid)
request.session['public_link'] = MetaData.public_link(xform)
return HttpResponseRedirect(reverse(show, kwargs={
'username': xform.user.username,
'id_string': xform.id_string
}))
xform, is_owner, can_edit, can_view = get_xform_and_perms(
username, id_string, request)
# no access
if not (xform.shared or can_view or request.session.get('public_link')):
return HttpResponseRedirect(reverse(home))
context = RequestContext(request)
context.cloned = len(
XForm.objects.filter(user__username=request.user.username,
id_string=id_string + XForm.CLONED_SUFFIX)
) > 0
context.public_link = MetaData.public_link(xform)
context.is_owner = is_owner
context.can_edit = can_edit
context.can_view = can_view or request.session.get('public_link')
context.xform = xform
context.content_user = xform.user
context.base_url = "https://%s" % request.get_host()
context.source = MetaData.source(xform)
context.form_license = MetaData.form_license(xform).data_value
context.data_license = MetaData.data_license(xform).data_value
context.supporting_docs = MetaData.supporting_docs(xform)
context.media_upload = MetaData.media_upload(xform)
context.mapbox_layer = MetaData.mapbox_layer_upload(xform)
if is_owner:
context.form_license_form = FormLicenseForm(
initial={'value': context.form_license})
context.data_license_form = DataLicenseForm(
initial={'value': context.data_license})
context.doc_form = SupportDocForm()
context.source_form = SourceForm()
context.media_form = MediaForm()
context.mapbox_layer_form = MapboxLayerForm()
context.users_with_perms = get_users_with_perms(
xform,
attach_perms=True
).items()
context.permission_form = PermissionForm(username)
user_list = [u.username for u in User.objects.exclude(username=username)]
context.user_json_list = simplejson.dumps(user_list)
return render_to_response("show.html", context_instance=context)
示例9: xformsManifest
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
def xformsManifest(request, username, id_string):
xform = get_object_or_404(
XForm, id_string=id_string, user__username=username)
formlist_user = xform.user
profile, created = \
UserProfile.objects.get_or_create(user=formlist_user)
if profile.require_auth:
authenticator = HttpDigestAuthenticator()
if not authenticator.authenticate(request):
return authenticator.build_challenge_response()
response = render_to_response("xformsManifest.xml", {
#'urls': urls,
'host': request.build_absolute_uri().replace(
request.get_full_path(), ''),
'media_files': MetaData.media_upload(xform)
}, mimetype="text/xml; charset=utf-8")
response['X-OpenRosa-Version'] = '1.0'
tz = pytz.timezone(settings.TIME_ZONE)
dt = datetime.now(tz).strftime('%a, %d %b %Y %H:%M:%S %Z')
response['Date'] = dt
return response
示例10: edit
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
#.........这里部分代码省略.........
'data_license': request.POST['data-license'],
}, audit, request)
MetaData.data_license(xform, request.POST['data-license'])
elif request.POST.get('source') or request.FILES.get('source'):
audit = {
'xform': xform.id_string
}
audit_log(
Actions.FORM_UPDATED, request.user, owner,
_("Source for '%(id_string)s' updated to '%(source)s'.") %
{
'id_string': xform.id_string,
'source': request.POST.get('source'),
}, audit, request)
MetaData.source(xform, request.POST.get('source'),
request.FILES.get('source'))
elif request.POST.get('enable_sms_support_trigger') is not None:
sms_support_form = ActivateSMSSupportFom(request.POST)
if sms_support_form.is_valid():
audit = {
'xform': xform.id_string
}
enabled = \
sms_support_form.cleaned_data.get('enable_sms_support')
if enabled:
audit_action = Actions.SMS_SUPPORT_ACTIVATED
audit_message = _(u"SMS Support Activated on")
else:
audit_action = Actions.SMS_SUPPORT_DEACTIVATED
audit_message = _(u"SMS Support Deactivated on")
audit_log(
audit_action, request.user, owner,
audit_message
% {'id_string': xform.id_string}, audit, request)
# stored previous states to be able to rollback form status
# in case we can't save.
pe = xform.allows_sms
pid = xform.sms_id_string
xform.allows_sms = enabled
xform.sms_id_string = \
sms_support_form.cleaned_data.get('sms_id_string')
compat = check_form_sms_compatibility(None,
json.loads(xform.json))
if compat['type'] == 'alert-error':
xform.allows_sms = False
xform.sms_id_string = pid
try:
xform.save()
except IntegrityError:
# unfortunately, there's no feedback mechanism here
xform.allows_sms = pe
xform.sms_id_string = pid
elif request.FILES.get('media'):
audit = {
'xform': xform.id_string
}
audit_log(
Actions.FORM_UPDATED, request.user, owner,
_("Media added to '%(id_string)s'.") %
{
'id_string': xform.id_string
}, audit, request)
for aFile in request.FILES.getlist("media"):
MetaData.media_upload(xform, aFile)
elif request.POST.get('map_name'):
mapbox_layer = MapboxLayerForm(request.POST)
if mapbox_layer.is_valid():
audit = {
'xform': xform.id_string
}
audit_log(
Actions.FORM_UPDATED, request.user, owner,
_("Map layer added to '%(id_string)s'.") %
{
'id_string': xform.id_string
}, audit, request)
MetaData.mapbox_layer_upload(xform, mapbox_layer.cleaned_data)
elif request.FILES:
audit = {
'xform': xform.id_string
}
audit_log(
Actions.FORM_UPDATED, request.user, owner,
_("Supporting document added to '%(id_string)s'.") %
{
'id_string': xform.id_string
}, audit, request)
MetaData.supporting_docs(xform, request.FILES['doc'])
xform.update()
if request.is_ajax():
return HttpResponse(_(u'Update succeeded.'))
else:
return HttpResponseRedirect(reverse(show, kwargs={
'username': username,
'id_string': id_string
}))
return HttpResponseForbidden(_(u'Update failed.'))
示例11: edit
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
#.........这里部分代码省略.........
)
MetaData.form_license(xform, request.POST["form-license"])
elif request.POST.get("data-license"):
audit = {"xform": xform.id_string}
audit_log(
Actions.FORM_UPDATED,
request.user,
owner,
_("Data license for '%(id_string)s' updated to " "'%(data_license)s'.")
% {"id_string": xform.id_string, "data_license": request.POST["data-license"]},
audit,
request,
)
MetaData.data_license(xform, request.POST["data-license"])
elif request.POST.get("source") or request.FILES.get("source"):
audit = {"xform": xform.id_string}
audit_log(
Actions.FORM_UPDATED,
request.user,
owner,
_("Source for '%(id_string)s' updated to '%(source)s'.")
% {"id_string": xform.id_string, "source": request.POST.get("source")},
audit,
request,
)
MetaData.source(xform, request.POST.get("source"), request.FILES.get("source"))
elif request.POST.get("enable_sms_support_trigger") is not None:
sms_support_form = ActivateSMSSupportFom(request.POST)
if sms_support_form.is_valid():
audit = {"xform": xform.id_string}
enabled = sms_support_form.cleaned_data.get("enable_sms_support")
if enabled:
audit_action = Actions.SMS_SUPPORT_ACTIVATED
audit_message = _(u"SMS Support Activated on")
else:
audit_action = Actions.SMS_SUPPORT_DEACTIVATED
audit_message = _(u"SMS Support Deactivated on")
audit_log(
audit_action, request.user, owner, audit_message % {"id_string": xform.id_string}, audit, request
)
# stored previous states to be able to rollback form status
# in case we can't save.
pe = xform.allows_sms
pid = xform.sms_id_string
xform.allows_sms = enabled
xform.sms_id_string = sms_support_form.cleaned_data.get("sms_id_string")
compat = check_form_sms_compatibility(None, json.loads(xform.json))
if compat["type"] == "alert-error":
xform.allows_sms = False
xform.sms_id_string = pid
try:
xform.save()
except IntegrityError:
# unfortunately, there's no feedback mechanism here
xform.allows_sms = pe
xform.sms_id_string = pid
elif request.FILES.get("media"):
audit = {"xform": xform.id_string}
audit_log(
Actions.FORM_UPDATED,
request.user,
owner,
_("Media added to '%(id_string)s'.") % {"id_string": xform.id_string},
audit,
request,
)
for aFile in request.FILES.getlist("media"):
MetaData.media_upload(xform, aFile)
elif request.POST.get("map_name"):
mapbox_layer = MapboxLayerForm(request.POST)
if mapbox_layer.is_valid():
audit = {"xform": xform.id_string}
audit_log(
Actions.FORM_UPDATED,
request.user,
owner,
_("Map layer added to '%(id_string)s'.") % {"id_string": xform.id_string},
audit,
request,
)
MetaData.mapbox_layer_upload(xform, mapbox_layer.cleaned_data)
elif request.FILES:
audit = {"xform": xform.id_string}
audit_log(
Actions.FORM_UPDATED,
request.user,
owner,
_("Supporting document added to '%(id_string)s'.") % {"id_string": xform.id_string},
audit,
request,
)
MetaData.supporting_docs(xform, request.FILES["doc"])
xform.update()
if request.is_ajax():
return HttpResponse(_(u"Updated succeeded."))
else:
return HttpResponseRedirect(reverse(show, kwargs={"username": username, "id_string": id_string}))
return HttpResponseForbidden(_(u"Update failed."))
示例12: show
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
def show(request, username=None, id_string=None, uuid=None):
if uuid:
xform = get_object_or_404(XForm, uuid=uuid)
request.session['public_link'] = xform.uuid if MetaData.public_link(xform) else False
return HttpResponseRedirect(reverse(show, kwargs={
'username': xform.user.username,
'id_string': xform.id_string
}))
xform, is_owner, can_edit, can_view = get_xform_and_perms(
username, id_string, request)
# no access
if not (
xform.shared or can_view or\
request.session.get('public_link')):
return HttpResponseRedirect(reverse(home))
context = RequestContext(request)
context.cloned = len(
XForm.objects.filter(user__username=request.user.username,
id_string=id_string + XForm.CLONED_SUFFIX)
) > 0
context.public_link = MetaData.public_link(xform)
context.is_owner = is_owner
context.can_edit = can_edit
context.can_view = can_view or request.session.get('public_link')
context.xform = xform
context.content_user = xform.user
context.base_url = "https://%s" % request.get_host()
context.source = MetaData.source(xform)
context.form_license = MetaData.form_license(xform).data_value
context.data_license = MetaData.data_license(xform).data_value
context.supporting_docs = MetaData.supporting_docs(xform)
context.media_upload = MetaData.media_upload(xform)
context.mapbox_layer = MetaData.mapbox_layer_upload(xform)
if is_owner:
context.sms_support_form = ActivateSMSSupportFom(
initial={'enable_sms_support': xform.allows_sms,
'sms_id_string': xform.sms_id_string})
if not xform.allows_sms:
context.sms_compatible = check_form_sms_compatibility(None,
json_survey=json.loads(xform.json))
else:
url_root = request.build_absolute_uri('/')[:-1]
context.sms_providers_doc = providers_doc(
url_root=url_root,
username=username,
id_string=id_string)
context.url_root = url_root
context.form_license_form = FormLicenseForm(
initial={'value': context.form_license})
context.data_license_form = DataLicenseForm(
initial={'value': context.data_license})
context.doc_form = SupportDocForm()
context.source_form = SourceForm()
context.media_form = MediaForm()
context.mapbox_layer_form = MapboxLayerForm()
context.users_with_perms = get_users_with_perms(
xform,
attach_perms=True
).items()
context.permission_form = PermissionForm(username)
context.sms_support_doc = get_autodoc_for(xform)
user_list = [u.username for u in User.objects.exclude(username=username)]
context.user_json_list = simplejson.dumps(user_list)
return render_to_response("show.html", context_instance=context)
示例13: edit
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
def edit(request, username, id_string):
xform = XForm.objects.get(user__username=username, id_string=id_string)
if request.GET.get('crowdform'):
crowdform_action = request.GET['crowdform']
request_username = request.user.username
# ensure is crowdform
if xform.is_crowd_form:
if crowdform_action == 'delete':
MetaData.objects.get(
xform__id_string=id_string,
data_value=request_username,
data_type=MetaData.CROWDFORM_USERS
).delete()
elif crowdform_action == 'add':
MetaData.crowdform_users(xform, request_username)
return HttpResponseRedirect(reverse(profile, kwargs={
'username': request_username
}))
if username == request.user.username or\
request.user.has_perm('odk_logger.change_xform', xform):
if request.POST.get('description'):
xform.description = request.POST['description']
elif request.POST.get('title'):
xform.title = request.POST['title']
elif request.POST.get('toggle_shared'):
if request.POST['toggle_shared'] == 'data':
xform.shared_data = not xform.shared_data
elif request.POST['toggle_shared'] == 'form':
xform.shared = not xform.shared
elif request.POST['toggle_shared'] == 'active':
xform.downloadable = not xform.downloadable
elif request.POST['toggle_shared'] == 'crowd':
if xform.is_crowd_form:
xform.is_crowd_form = False
else:
xform.is_crowd_form = True
xform.shared = True
xform.shared_data = True
elif request.POST.get('form-license'):
MetaData.form_license(xform, request.POST['form-license'])
elif request.POST.get('data-license'):
MetaData.data_license(xform, request.POST['data-license'])
elif request.POST.get('source') or request.FILES.get('source'):
MetaData.source(xform, request.POST.get('source'),
request.FILES.get('source'))
elif request.FILES.get('media'):
MetaData.media_upload(xform, request.FILES.get('media'))
elif request.POST.get('map_name'):
mapbox_layer = MapboxLayerForm(request.POST)
if mapbox_layer.is_valid():
MetaData.mapbox_layer_upload(xform, mapbox_layer.cleaned_data)
elif request.FILES:
MetaData.supporting_docs(xform, request.FILES['doc'])
xform.update()
if request.is_ajax():
return HttpResponse(_(u'Updated succeeded.'))
else:
return HttpResponseRedirect(reverse(show, kwargs={
'username': username,
'id_string': id_string
}))
return HttpResponseForbidden(_(u'Update failed.'))
示例14: edit
# 需要导入模块: from main.models import MetaData [as 别名]
# 或者: from main.models.MetaData import media_upload [as 别名]
#.........这里部分代码省略.........
_("Active status for '%(id_string)s' updated from '%(old_shared)s' to '%(new_shared)s'.") %\
{
'id_string': xform.id_string,
'old_shared': _("shared") if xform.downloadable else _("not shared"),
'new_shared': _("shared") if not xform.downloadable else _("not shared")
}, audit, request)
xform.downloadable = not xform.downloadable
elif request.POST['toggle_shared'] == 'crowd':
audit = {
'xform': xform.id_string
}
audit_log(Actions.FORM_UPDATED, request.user, owner,
_("Crowdform status for '%(id_string)s' updated from '%(old_status)s' to '%(new_status)s'.") %\
{
'id_string': xform.id_string,
'old_status': _("crowdform") if not xform.is_crowd_form else _("not crowdform"),
'new_status': _("crowdform") if xform.is_crowd_form else _("not crowdform"),
}, audit, request)
if xform.is_crowd_form:
xform.is_crowd_form = False
else:
xform.is_crowd_form = True
xform.shared = True
xform.shared_data = True
elif request.POST.get('form-license'):
audit = {
'xform': xform.id_string
}
audit_log(Actions.FORM_UPDATED, request.user, owner,
_("Form License for '%(id_string)s' updated to '%(form_license)s'.") %\
{
'id_string': xform.id_string,
'form_license': request.POST['form-license'],
}, audit, request)
MetaData.form_license(xform, request.POST['form-license'])
elif request.POST.get('data-license'):
audit = {
'xform': xform.id_string
}
audit_log(Actions.FORM_UPDATED, request.user, owner,
_("Data license for '%(id_string)s' updated to '%(data_license)s'.") %\
{
'id_string': xform.id_string,
'data_license': request.POST['data-license'],
}, audit, request)
MetaData.data_license(xform, request.POST['data-license'])
elif request.POST.get('source') or request.FILES.get('source'):
audit = {
'xform': xform.id_string
}
audit_log(Actions.FORM_UPDATED, request.user, owner,
_("Source for '%(id_string)s' updated to '%(source)s'.") %\
{
'id_string': xform.id_string,
'source': request.POST.get('source'),
}, audit, request)
MetaData.source(xform, request.POST.get('source'),
request.FILES.get('source'))
elif request.FILES.get('media'):
audit = {
'xform': xform.id_string
}
audit_log(Actions.FORM_UPDATED, request.user, owner,
_("Media added to '%(id_string)s'.") %\
{
'id_string': xform.id_string
}, audit, request)
MetaData.media_upload(xform, request.FILES.get('media'))
elif request.POST.get('map_name'):
mapbox_layer = MapboxLayerForm(request.POST)
if mapbox_layer.is_valid():
audit = {
'xform': xform.id_string
}
audit_log(Actions.FORM_UPDATED, request.user, owner,
_("Map layer added to '%(id_string)s'.") %\
{
'id_string': xform.id_string
}, audit, request)
MetaData.mapbox_layer_upload(xform, mapbox_layer.cleaned_data)
elif request.FILES:
audit = {
'xform': xform.id_string
}
audit_log(Actions.FORM_UPDATED, request.user, owner,
_("Supporting document added to '%(id_string)s'.") %\
{
'id_string': xform.id_string
}, audit, request)
MetaData.supporting_docs(xform, request.FILES['doc'])
xform.update()
if request.is_ajax():
return HttpResponse(_(u'Updated succeeded.'))
else:
return HttpResponseRedirect(reverse(show, kwargs={
'username': username,
'id_string': id_string
}))
return HttpResponseForbidden(_(u'Update failed.'))