本文整理汇总了Python中utils.user_auth.helper_auth_helper函数的典型用法代码示例。如果您正苦于以下问题:Python helper_auth_helper函数的具体用法?Python helper_auth_helper怎么用?Python helper_auth_helper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了helper_auth_helper函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
示例2: 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
示例3: 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)
示例4: 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
示例5: 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
示例6: 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
示例7: download_jsonform
def download_jsonform(request, username, id_string):
owner = get_object_or_404(User, username=username)
xform = get_object_or_404(XForm, user__username=username,
id_string=id_string)
helper_auth_helper(request)
if not has_permission(xform, owner, request, xform.shared):
return HttpResponseForbidden(_(u'Not shared.'))
response = response_with_mimetype_and_name('json', id_string,
show_date=False)
if 'callback' in request.GET and request.GET.get('callback') != '':
callback = request.GET.get('callback')
response.content = "%s(%s)" % (callback, xform.json)
else:
response.content = xform.json
return response
示例8: yukon_xls_export
def yukon_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)
helper_auth_helper(request)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
site_nums = request.GET.getlist('site')
if len(site_nums) != 1:
return HttpResponseBadRequest("Must provide a single site id")
xls = generate_yukon_xls(id_string, user=owner, site_nums=site_nums)
response = HttpResponse(xls, mimetype="application/vnd.ms-excel")
response['Content-Disposition'] = disposition_ext_and_date(
'-'.join(site_nums), 'xls')
return response
示例9: frp_xls_export
def frp_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)
helper_auth_helper(request)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
permit_nums = request.GET.getlist('permit')
biol_date = request.GET.get('biologistContactDate', '')
if len(permit_nums) != 1:
return HttpResponseBadRequest("Must provide a single permit")
pdf = generate_frp_xls(id_string, biol_date,
user=owner, permit_nums=permit_nums)
response = HttpResponse(pdf, mimetype="application/vnd.ms-excel")
response['Content-Disposition'] = disposition_ext_and_date(
'-'.join(permit_nums), 'xls')
return response
示例10: api
def api(request, username=None, id_string=None):
"""
Returns all results as JSON. If a parameter string is passed,
it takes the 'query' parameter, converts this string to a dictionary, an
that is then used as a MongoDB query string.
NOTE: only a specific set of operators are allow, currently $or and $and.
Please send a request if you'd like another operator to be enabled.
NOTE: Your query must be valid JSON, double check it here,
http://json.parser.online.fr/
E.g. api?query='{"last_name": "Smith"}'
"""
if request.method == "OPTIONS":
response = HttpResponse()
add_cors_headers(response)
return response
helper_auth_helper(request)
helper_auth_helper(request)
xform, owner = check_and_set_user_and_form(username, id_string, request)
if not xform:
return HttpResponseForbidden(_(u'Not shared.'))
try:
args = {
'username': username,
'id_string': id_string,
'query': request.GET.get('query'),
'fields': request.GET.get('fields'),
'sort': request.GET.get('sort')
}
if 'start' in request.GET:
args["start"] = int(request.GET.get('start'))
if 'limit' in request.GET:
args["limit"] = int(request.GET.get('limit'))
if 'count' in request.GET:
args["count"] = True if int(request.GET.get('count')) > 0\
else False
cursor = ParsedInstance.query_mongo(**args)
except ValueError, e:
return HttpResponseBadRequest(e.__str__())
示例11: 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.'))
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()
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=tmp.name,
use_local_filesystem=True)
return response
示例12: 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)
helper_auth_helper(request)
if not has_permission(xform, owner, request):
return HttpResponseForbidden(_(u'Not shared.'))
query = request.GET.get("query")
force_xlsx = request.GET.get('xlsx') == 'true'
ext = 'xls' if not force_xlsx else 'xlsx'
try:
export = generate_export(
Export.XLS_EXPORT, ext, username, id_string, None, query)
except NoRecordsFoundError:
return HttpResponse(_("No records found to export"))
else:
audit = {
"xform": xform.id_string,
"export_type": Export.XLS_EXPORT
}
audit_log(Actions.EXPORT_CREATED, request.user, owner,
_("Created XLS 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 XLS export on '%(id_string)s'.") %\
{
'id_string': xform.id_string,
}, audit, request)
# 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
示例13: api
def api(request, username=None, id_string=None):
"""
Returns all results as JSON. If a parameter string is passed,
it takes the 'query' parameter, converts this string to a dictionary, an
that is then used as a MongoDB query string.
NOTE: only a specific set of operators are allow, currently $or and $and.
Please send a request if you'd like another operator to be enabled.
NOTE: Your query must be valid JSON, double check it here,
http://json.parser.online.fr/
E.g. api?query='{"last_name": "Smith"}'
"""
helper_auth_helper(request)
xform, owner = check_and_set_user_and_form(username, id_string, request)
if not xform:
return HttpResponseForbidden(_(u"Not shared."))
try:
args = {
"username": username,
"id_string": id_string,
"query": request.GET.get("query"),
"fields": request.GET.get("fields"),
"sort": request.GET.get("sort"),
}
if "start" in request.GET:
args["start"] = int(request.GET.get("start"))
if "limit" in request.GET:
args["limit"] = int(request.GET.get("limit"))
if "count" in request.GET:
args["count"] = True if int(request.GET.get("count")) > 0 else False
cursor = ParsedInstance.query_mongo(**args)
except ValueError, e:
return HttpResponseBadRequest(e.__str__())
示例14: csv_export
def csv_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.'))
query = request.GET.get("query")
ext = Export.CSV_EXPORT
try:
export = generate_export(
Export.CSV_EXPORT, ext, username, id_string, None, query)
except NoRecordsFoundError:
return HttpResponse(_("No records found to export"))
else:
audit = {
"xform": xform.id_string,
"export_type": Export.CSV_EXPORT
}
audit_log(Actions.EXPORT_CREATED, request.user, owner,
_("Created CSV 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 CSV 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(
Export.EXPORT_MIMES[ext], id_string, extension=ext,
file_path=export.filepath)
return response
示例15: formList
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")