本文整理汇总了Python中utils.user_auth.has_permission函数的典型用法代码示例。如果您正苦于以下问题:Python has_permission函数的具体用法?Python has_permission怎么用?Python has_permission使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了has_permission函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_export
def create_export(request, username, id_string, export_type):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
query = request.POST.get("query")
force_xlsx = request.POST.get('xlsx') == 'true'
try:
create_async_export(xform, export_type, query, force_xlsx)
except Export.ExportTypeError:
return HttpResponseBadRequest(
_("%s is not a valid export type" % export_type))
else:
audit = {
"xform": xform.id_string,
"export_type": export_type
}
audit_log(Actions.EXPORT_CREATED, request.user, owner,
_("Created %(export_type)s export on '%(id_string)s'.") %\
{
'export_type': export_type.upper(),
'id_string': xform.id_string,
}, audit, request)
return HttpResponseRedirect(reverse(
export_list,
kwargs={
"username": username,
"id_string": id_string,
"export_type": export_type
})
)
开发者ID:larryweya,项目名称:formhub,代码行数:33,代码来源:views.py
示例2: kml_export
def kml_export(request, username, id_string):
# read the locations from the database
context = RequestContext(request)
context.message = "HELLO!!"
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
helper_auth_helper(request)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
context.data = kml_export_data(id_string, user=owner)
response = \
render_to_response("survey.kml", context_instance=context,
mimetype="application/vnd.google-earth.kml+xml")
response['Content-Disposition'] = \
disposition_ext_and_date(id_string, 'kml')
audit = {
"xform": xform.id_string,
"export_type": Export.KML_EXPORT
}
audit_log(
Actions.EXPORT_CREATED, request.user, owner,
_("Created KML export on '%(id_string)s'.") %
{
'id_string': xform.id_string,
}, audit, request)
# log download as well
audit_log(
Actions.EXPORT_DOWNLOADED, request.user, owner,
_("Downloaded KML export on '%(id_string)s'.") %
{
'id_string': xform.id_string,
}, audit, request)
return response
开发者ID:ACTillage,项目名称:formhub,代码行数:33,代码来源:views.py
示例3: export_download
def export_download(request, username, id_string, export_type, filename):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
helper_auth_helper(request)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
# find the export entry in the db
export = get_object_or_404(Export, xform=xform, filename=filename)
if export_type == Export.GDOC_EXPORT and export.export_url is not None:
return HttpResponseRedirect(export.export_url)
ext, mime_type = export_def_from_filename(export.filename)
audit = {
"xform": xform.id_string,
"export_type": export.export_type
}
audit_log(Actions.EXPORT_DOWNLOADED, request.user, owner,
_("Downloaded %(export_type)s export '%(filename)s' on '%(id_string)s'.") %\
{
'export_type': export.export_type.upper(),
'filename': export.filename,
'id_string': xform.id_string,
}, audit, request)
if request.GET.get('raw'):
id_string = None
basename = os.path.splitext(export.filename)[0]
response = response_with_mimetype_and_name(
mime_type, name=basename, extension=ext,
file_path=export.filepath, show_date=False)
return response
开发者ID:larryweya,项目名称:formhub,代码行数:33,代码来源:views.py
示例4: map_view
def map_view(request, username, id_string):
xform = XForm.objects.get(user__username=username, id_string=id_string)
owner = User.objects.get(username=username)
if not has_permission(xform, owner, request):
return HttpResponseForbidden('Not shared.')
context = RequestContext(request)
context.content_user = owner
context.xform = xform
context.profile, created = UserProfile.objects.get_or_create(user=owner)
points = ParsedInstance.objects.values('lat', 'lng', 'instance').filter(
instance__user=owner,
instance__xform__id_string=id_string,
lat__isnull=False,
lng__isnull=False)
center = {
'lat': round_down_geopoint(average([p['lat'] for p in points])),
'lng': round_down_geopoint(average([p['lng'] for p in points])),
}
def round_down_point(p):
return {
'lat': round_down_geopoint(p['lat']),
'lng': round_down_geopoint(p['lng']),
'instance': p['instance']
}
context.points = json.dumps([round_down_point(p) for p in list(points)])
context.center = json.dumps(center)
context.form_view = True
return render_to_response('map.html', context_instance=context)
开发者ID:TomCoder,项目名称:formhub,代码行数:28,代码来源:views.py
示例5: export_progress
def export_progress(request, username, id_string, export_type):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
# find the export entry in the db
export_ids = request.GET.getlist('export_ids')
exports = Export.objects.filter(xform=xform, id__in=export_ids)
statuses = []
for export in exports:
status = {
'complete': False,
'url': None,
'filename': None,
'export_id': export.id
}
if export.status == Export.SUCCESSFUL:
status['url'] = reverse(export_download, kwargs={
'username': owner.username,
'id_string': xform.id_string,
'export_type': export.export_type,
'filename': export.filename
})
status['filename'] = export.filename
# mark as complete if it either failed or succeeded but NOT pending
if export.status == Export.SUCCESSFUL or export.status == Export.FAILED:
status['complete'] = True
statuses.append(status)
return HttpResponse(simplejson.dumps(statuses), mimetype='application/json')
开发者ID:muazmohamed,项目名称:formhub,代码行数:32,代码来源:views.py
示例6: xls_export
def xls_export(request, username, id_string):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u"Not shared."))
query = request.GET.get("query")
force_xlsx = request.GET.get("xlsx") == "true"
xls_df_builder = XLSDataFrameBuilder(username, id_string, query)
excel_defs = {
"xls": {"suffix": ".xls", "mime_type": "vnd.ms-excel"},
"xlsx": {"suffix": ".xlsx", "mime_type": "vnd.openxmlformats"}, # TODO: check xlsx mime type
}
ext = "xls" if not force_xlsx else "xlsx"
if xls_df_builder.exceeds_xls_limits:
ext = "xlsx"
try:
temp_file = NamedTemporaryFile(suffix=excel_defs[ext]["suffix"])
xls_df_builder.export_to(temp_file.name)
if request.GET.get("raw"):
id_string = None
response = response_with_mimetype_and_name(excel_defs[ext]["mime_type"], id_string, extension=ext)
response.write(temp_file.read())
temp_file.seek(0, os.SEEK_END)
response["Content-Length"] = temp_file.tell()
temp_file.close()
return response
except NoRecordsFoundError:
return HttpResponse(_("No records found to export"))
开发者ID:Nuredin,项目名称:formhub,代码行数:29,代码来源:views.py
示例7: awc_pdf_export
def awc_pdf_export(request, username, id_string):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
helper_auth_helper(request)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
permit_nums = request.GET.getlist('permit')
submission_type = request.GET.get('submissionType', '')
observations = request.GET.get('observations', None)
if observations:
observations = ["uuid:" + x for x in observations.strip().split(",")]
if not observations or len(observations) < 1 or len(observations) > 5:
return HttpResponseBadRequest("Provide between 1 and 5 observations")
if len(permit_nums) == 0:
return HttpResponseBadRequest("Must provide at least one permit")
pdf = generate_pdf(id_string, submission_type, observations,
user=owner, permit_nums=permit_nums) #TODO - Get full name. Also, observer or user?
response = HttpResponse(pdf, mimetype="application/pdf")
response['Content-Disposition'] = disposition_ext_and_date(
'-'.join(permit_nums), 'pdf')
response['Content-Length'] = len(pdf)
return response
开发者ID:Ecotrust,项目名称:formhub,代码行数:26,代码来源:views.py
示例8: enter_data
def enter_data(request, username, id_string):
owner = User.objects.get(username=username)
xform = get_object_or_404(XForm, user__username=username, id_string=id_string)
if not has_permission(xform, owner, request):
return HttpResponseForbidden("Not shared.")
if not hasattr(settings, "TOUCHFORMS_URL"):
return HttpResponseRedirect(reverse("main.views.show", kwargs={"username": username, "id_string": id_string}))
url = settings.TOUCHFORMS_URL
register_openers()
response = None
with tempfile.TemporaryFile() as tmp:
tmp.write(xform.xml.encode("utf-8"))
tmp.seek(0)
values = {"file": tmp, "format": "json", "uuid": xform.uuid}
data, headers = multipart_encode(values)
headers["User-Agent"] = "formhub"
req = urllib2.Request(url, data, headers)
try:
response = urllib2.urlopen(req)
response = json.loads(response.read())
context = RequestContext(request)
owner = User.objects.get(username=username)
context.profile, created = UserProfile.objects.get_or_create(user=owner)
context.xform = xform
context.content_user = owner
context.form_view = True
context.touchforms = response["url"]
return render_to_response("form_entry.html", context_instance=context)
# return HttpResponseRedirect(response['url'])
except urllib2.URLError:
pass # this will happen if we could not connect to touchforms
return HttpResponseRedirect(reverse("main.views.show", kwargs={"username": username, "id_string": id_string}))
开发者ID:mattlangeman,项目名称:formhub,代码行数:32,代码来源:views.py
示例9: google_xls_export
def google_xls_export(request, username, id_string):
token = None
if request.user.is_authenticated():
try:
ts = TokenStorageModel.objects.get(id=request.user)
except TokenStorageModel.DoesNotExist:
pass
else:
token = ts.token
elif request.session.get("access_token"):
token = request.session.get("access_token")
if token is None:
request.session["google_redirect_url"] = reverse(
google_xls_export, kwargs={"username": username, "id_string": id_string}
)
return HttpResponseRedirect(redirect_uri)
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u"Not shared."))
valid, dd = dd_for_params(id_string, owner, request)
if not valid:
return dd
ddw = XlsWriter()
tmp = NamedTemporaryFile(delete=False)
ddw.set_file(tmp)
ddw.set_data_dictionary(dd)
temp_file = ddw.save_workbook_to_file()
temp_file.close()
url = google_export_xls(tmp.name, xform.title, token, blob=True)
os.unlink(tmp.name)
return HttpResponseRedirect(url)
开发者ID:Nuredin,项目名称:formhub,代码行数:32,代码来源:views.py
示例10: map_view
def map_view(request, username, id_string):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u"Not shared."))
context = RequestContext(request)
context.content_user = owner
context.xform = xform
context.profile, created = UserProfile.objects.get_or_create(user=owner)
points = ParsedInstance.objects.values("lat", "lng", "instance").filter(
instance__user=owner, instance__xform__id_string=id_string, lat__isnull=False, lng__isnull=False
)
center = {
"lat": round_down_geopoint(average([p["lat"] for p in points])),
"lng": round_down_geopoint(average([p["lng"] for p in points])),
}
def round_down_point(p):
return {"lat": round_down_geopoint(p["lat"]), "lng": round_down_geopoint(p["lng"]), "instance": p["instance"]}
context.center = json.dumps(center)
context.form_view = True
context.jsonform_url = reverse(download_jsonform, kwargs={"username": username, "id_string": id_string})
context.mongo_api_url = reverse(main.views.api, kwargs={"username": username, "id_string": id_string})
context.mapbox_layer = MetaData.mapbox_layer_upload(xform)
return render_to_response("map.html", context_instance=context)
开发者ID:Nuredin,项目名称:formhub,代码行数:26,代码来源:views.py
示例11: delete_export
def delete_export(request, username, id_string, export_type):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
export_id = request.POST.get('export_id')
# find the export entry in the db
export = get_object_or_404(Export, id=export_id)
export.delete()
audit = {
"xform": xform.id_string,
"export_type": export.export_type
}
audit_log(
Actions.EXPORT_DOWNLOADED, request.user, owner,
_("Deleted %(export_type)s export '%(filename)s'"
" on '%(id_string)s'.") %
{
'export_type': export.export_type.upper(),
'filename': export.filename,
'id_string': xform.id_string,
}, audit, request)
return HttpResponseRedirect(reverse(
export_list,
kwargs={
"username": username,
"id_string": id_string,
"export_type": export_type
}))
开发者ID:ACTillage,项目名称:formhub,代码行数:32,代码来源:views.py
示例12: export_list
def export_list(request, username, id_string, export_type):
if export_type == Export.GDOC_EXPORT:
redirect_url = reverse(
export_list,
kwargs={
'username': username, 'id_string': id_string,
'export_type': export_type})
token = _get_google_token(request, redirect_url)
if isinstance(token, HttpResponse):
return token
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
if should_create_new_export(xform, export_type):
try:
create_async_export(
xform, export_type, query=None, force_xlsx=True)
except Export.ExportTypeError:
return HttpResponseBadRequest(
_("%s is not a valid export type" % export_type))
context = RequestContext(request)
context.username = owner.username
context.xform = xform
# TODO: better output e.g. Excel instead of XLS
context.export_type = export_type
context.export_type_name = Export.EXPORT_TYPE_DICT[export_type]
exports = Export.objects.filter(xform=xform, export_type=export_type)\
.order_by('-created_on')
context.exports = exports
return render_to_response('export_list.html', context_instance=context)
开发者ID:ACTillage,项目名称:formhub,代码行数:33,代码来源:views.py
示例13: zip_export
def zip_export(request, username, id_string):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
helper_auth_helper(request)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
if request.GET.get('raw'):
id_string = None
attachments = Attachment.objects.filter(instance__xform=xform)
zip_file = create_attachments_zipfile(attachments)
audit = {
"xform": xform.id_string,
"export_type": Export.ZIP_EXPORT
}
audit_log(
Actions.EXPORT_CREATED, request.user, owner,
_("Created ZIP export on '%(id_string)s'.") %
{
'id_string': xform.id_string,
}, audit, request)
# log download as well
audit_log(
Actions.EXPORT_DOWNLOADED, request.user, owner,
_("Downloaded ZIP export on '%(id_string)s'.") %
{
'id_string': xform.id_string,
}, audit, request)
if request.GET.get('raw'):
id_string = None
response = response_with_mimetype_and_name('zip', id_string,
file_path=zip_file,
use_local_filesystem=True)
return response
开发者ID:ACTillage,项目名称:formhub,代码行数:33,代码来源:views.py
示例14: zip_export
def zip_export(request, username, id_string):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
dd = DataDictionary.objects.get(id_string=id_string,
user=owner)
if request.GET.get('raw'):
id_string = None
# create zip_file
tmp = NamedTemporaryFile()
z = zipfile.ZipFile(tmp, 'w', zipfile.ZIP_DEFLATED)
photos = image_urls_for_form(xform)
for photo in photos:
f = NamedTemporaryFile()
req = urllib2.Request(photo)
f.write(urllib2.urlopen(req).read())
f.seek(0)
z.write(f.name, urlparse(photo).path[1:])
f.close()
z.close()
if request.GET.get('raw'):
id_string = None
response = response_with_mimetype_and_name('zip', id_string,
file_path=tmp.name,
use_local_filesystem=True)
return response
开发者ID:ingenieroariel,项目名称:formhub,代码行数:27,代码来源:views.py
示例15: download_xlsform
def download_xlsform(request, username, id_string):
xform = get_object_or_404(XForm,
user__username=username, id_string=id_string)
owner = User.objects.get(username=username)
helper_auth_helper(request)
if not has_permission(xform, owner, request, xform.shared):
return HttpResponseForbidden('Not shared.')
file_path = xform.xls.name
default_storage = get_storage_class()()
if default_storage.exists(file_path):
audit = {
"xform": xform.id_string
}
audit_log(
Actions.FORM_XLS_DOWNLOADED, request.user, xform.user,
_("Downloaded XLS file for form '%(id_string)s'.") %
{
"id_string": xform.id_string
}, audit, request)
split_path = file_path.split(os.extsep)
extension = 'xls'
if len(split_path) > 1:
extension = split_path[len(split_path) - 1]
response = response_with_mimetype_and_name(
'vnd.ms-excel', id_string, show_date=False, extension=extension,
file_path=file_path)
return response
else:
messages.add_message(request, messages.WARNING,
_(u'No XLS file for your form '
u'<strong>%(id)s</strong>')
% {'id': id_string})
return HttpResponseRedirect("/%s" % username)
开发者ID:Mbosco,项目名称:formhub,代码行数:33,代码来源:views.py
示例16: data_export
def data_export(request, username, id_string, export_type):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
helper_auth_helper(request)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
query = request.GET.get("query")
extension = export_type
# check if we should force xlsx
force_xlsx = request.GET.get('xls') != 'true'
if export_type == Export.XLS_EXPORT and force_xlsx:
extension = 'xlsx'
audit = {
"xform": xform.id_string,
"export_type": export_type
}
# check if we need to re-generate,
# we always re-generate if a filter is specified
if should_create_new_export(xform, export_type) or query:
try:
export = generate_export(
export_type, extension, username, id_string, None, query)
audit_log(
Actions.EXPORT_CREATED, request.user, owner,
_("Created %(export_type)s export on '%(id_string)s'.") %
{
'id_string': xform.id_string,
'export_type': export_type.upper()
}, audit, request)
except NoRecordsFoundError:
return HttpResponseNotFound(_("No records found to export"))
else:
export = newset_export_for(xform, export_type)
# log download as well
audit_log(
Actions.EXPORT_DOWNLOADED, request.user, owner,
_("Downloaded %(export_type)s export on '%(id_string)s'.") %
{
'id_string': xform.id_string,
'export_type': export_type.upper()
}, audit, request)
if not export.filename:
# tends to happen when using newset_export_for.
return HttpResponseNotFound("File does not exist!")
# get extension from file_path, exporter could modify to
# xlsx if it exceeds limits
path, ext = os.path.splitext(export.filename)
ext = ext[1:]
if request.GET.get('raw'):
id_string = None
response = response_with_mimetype_and_name(
Export.EXPORT_MIMES[ext], id_string, extension=ext,
file_path=export.filepath)
return response
开发者ID:rjawahar,项目名称:formhub,代码行数:58,代码来源:views.py
示例17: download_jsonform
def download_jsonform(request, username, id_string):
owner = User.objects.get(username=username)
xform = XForm.objects.get(user__username=username, id_string=id_string)
if not has_permission(xform, owner, request, xform.shared):
return HttpResponseForbidden('Not shared.')
response = response_with_mimetype_and_name('json', id_string,
show_date=False)
response.content = xform.json
return response
开发者ID:TomCoder,项目名称:formhub,代码行数:9,代码来源:views.py
示例18: data_view
def data_view(request, username, id_string):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u"Not shared."))
context = RequestContext(request)
context.mongo_api_url = reverse(main.views.api, kwargs={"username": username, "id_string": id_string})
context.jsonform_url = reverse(download_jsonform, kwargs={"username": username, "id_string": id_string})
return render_to_response("data_view.html", context_instance=context)
开发者ID:Nuredin,项目名称:formhub,代码行数:10,代码来源:views.py
示例19: map_view
def map_view(request, username, id_string, template='map.html'):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, id_string=id_string, user=owner)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
context = RequestContext(request)
context.content_user = owner
context.xform = xform
context.profile, created = UserProfile.objects.get_or_create(user=owner)
points = ParsedInstance.objects.values('lat', 'lng', 'instance').filter(
instance__user=owner,
instance__xform__id_string=id_string,
lat__isnull=False,
lng__isnull=False)
center = {
'lat': round_down_geopoint(average([p['lat'] for p in points])),
'lng': round_down_geopoint(average([p['lng'] for p in points])),
}
def round_down_point(p):
return {
'lat': round_down_geopoint(p['lat']),
'lng': round_down_geopoint(p['lng']),
'instance': p['instance']
}
context.center = json.dumps(center)
context.form_view = True
context.jsonform_url = reverse(download_jsonform,
kwargs={"username": username,
"id_string": id_string})
context.enketo_edit_url = reverse('edit_data',
kwargs={"username": username,
"id_string": id_string,
"data_id": 0})
context.enketo_add_url = reverse('enter_data',
kwargs={"username": username,
"id_string": id_string})
context.enketo_add_with_url = reverse('add_submission_with',
kwargs={"username": username,
"id_string": id_string})
context.mongo_api_url = reverse('mongo_view_api',
kwargs={"username": username,
"id_string": id_string})
context.delete_data_url = reverse('delete_data',
kwargs={"username": username,
"id_string": id_string})
context.mapbox_layer = MetaData.mapbox_layer_upload(xform)
audit = {
"xform": xform.id_string
}
audit_log(Actions.FORM_MAP_VIEWED, request.user, owner,
_("Requested map on '%(id_string)s'.")
% {'id_string': xform.id_string}, audit, request)
return render_to_response(template, context_instance=context)
开发者ID:Ecotrust,项目名称:formhub,代码行数:55,代码来源:views.py
示例20: enketo_preview
def enketo_preview(request, username, id_string):
xform = get_object_or_404(XForm, user__username=username, id_string=id_string)
owner = xform.user
if not has_permission(xform, owner, request, xform.shared):
return HttpResponseForbidden(_(u"Not shared."))
enekto_preview_url = "%(enketo_url)s?server=%(profile_url)s&id=%(id_string)s" % {
"enketo_url": settings.ENKETO_PREVIEW_URL,
"profile_url": request.build_absolute_uri(reverse(profile, kwargs={"username": owner.username})),
"id_string": xform.id_string,
}
return HttpResponseRedirect(enekto_preview_url)
开发者ID:vernondcole,项目名称:formhub,代码行数:11,代码来源:views.py
注:本文中的utils.user_auth.has_permission函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论