本文整理汇总了Python中utils.log.audit_log函数的典型用法代码示例。如果您正苦于以下问题:Python audit_log函数的具体用法?Python audit_log怎么用?Python audit_log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了audit_log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: link_to_bamboo
def link_to_bamboo(request, username, id_string):
xform = get_object_or_404(XForm,
user__username=username, id_string=id_string)
owner = xform.user
from utils.bamboo import get_new_bamboo_dataset, delete_bamboo_dataset
audit = {
'xform': xform.id_string
}
# try to delete the dataset first (in case it exists)
if xform.bamboo_dataset and delete_bamboo_dataset(xform):
xform.bamboo_dataset = u''
xform.save()
audit_log(Actions.BAMBOO_LINK_DELETED, request.user, owner,
_("Bamboo link deleted on '%(id_string)s'.")
% {'id_string': xform.id_string}, audit, request)
# create a new one from all the data
dataset_id = get_new_bamboo_dataset(xform)
# update XForm
xform.bamboo_dataset = dataset_id
xform.save()
audit_log(Actions.BAMBOO_LINK_CREATED, request.user, owner,
_("Bamboo link created on '%(id_string)s'.") %\
{
'id_string': xform.id_string,
}, audit, request)
return HttpResponseRedirect(reverse(show, kwargs={
'username': username,
'id_string': id_string
}))
示例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
示例3: instance
def instance(request, username, id_string):
import re
if request.META and request.META.get('HTTP_REFERER'):
if re.match(r'.*-0.enketo.*/webform/edit.*', request.META.get('HTTP_REFERER')):
return HttpResponseRedirect('/app/')
xform, is_owner, can_edit, can_view = get_xform_and_perms(
username, id_string, request)
# no access
if not (xform.shared_data or can_view or
request.session.get('public_link') == xform.uuid):
return HttpResponseForbidden(_(u'Not shared.'))
context = RequestContext(request)
audit = {
"xform": xform.id_string,
}
audit_log(
Actions.FORM_DATA_VIEWED, request.user, xform.user,
_("Requested instance view for '%(id_string)s'.") %
{
'id_string': xform.id_string,
}, audit, request)
return render_to_response('instance.html', {
'username': username,
'id_string': id_string,
'xform': xform,
'can_edit': can_edit
}, context_instance=context)
示例4: set_form
def set_form():
form_owner = request.POST.get('username')
id_string = request.POST.get('id_string')
xform = XForm.objects.get(user__username=form_owner,
id_string=id_string)
if len(id_string) > 0 and id_string[0].isdigit():
id_string = '_' + id_string
path = xform.xls.name
if default_storage.exists(path):
xls_file = upload_to(None, '%s%s.xls' % (
id_string, XForm.CLONED_SUFFIX), to_username)
xls_data = default_storage.open(path)
xls_file = default_storage.save(xls_file, xls_data)
context.message = u'%s-%s' % (form_owner, xls_file)
survey = DataDictionary.objects.create(
user=request.user,
xls=xls_file
).survey
# log to cloner's account
audit = {}
audit_log(Actions.FORM_CLONED, request.user, request.user,
_("Cloned form '%(id_string)s'.") %\
{
'id_string': survey.id_string,
}, audit, request)
return {
'type': 'alert-success',
'text': _(u'Successfully cloned %(id_string)s into your '
u'%(profile_url)s') % {
'id_string': survey.id_string,
'profile_url': u'<a href="%s">profile</a>.' %
reverse(profile,
kwargs={'username': to_username})
}
}
示例5: set_form
def set_form():
form_owner = request.POST.get("username")
id_string = request.POST.get("id_string")
xform = XForm.objects.get(user__username=form_owner, id_string=id_string)
if len(id_string) > 0 and id_string[0].isdigit():
id_string = "_" + id_string
path = xform.xls.name
if default_storage.exists(path):
xls_file = upload_to(None, "%s%s.xls" % (id_string, XForm.CLONED_SUFFIX), to_username)
xls_data = default_storage.open(path)
xls_file = default_storage.save(xls_file, xls_data)
context.message = u"%s-%s" % (form_owner, xls_file)
survey = DataDictionary.objects.create(user=request.user, xls=xls_file).survey
# log to cloner's account
audit = {}
audit_log(
Actions.FORM_CLONED,
request.user,
request.user,
_("Cloned form '%(id_string)s'.") % {"id_string": survey.id_string},
audit,
request,
)
clone_form_url = reverse(
show, kwargs={"username": to_username, "id_string": xform.id_string + XForm.CLONED_SUFFIX}
)
return {
"type": "alert-success",
"text": _(u"Successfully cloned to %(form_url)s into your " u"%(profile_url)s")
% {
"form_url": u'<a href="%(url)s">%(id_string)s</a> '
% {"id_string": survey.id_string, "url": clone_form_url},
"profile_url": u'<a href="%s">profile</a>.' % reverse(profile, kwargs={"username": to_username}),
},
}
示例6: set_form
def set_form():
form = QuickConverter(request.POST, request.FILES)
survey = form.publish(request.user).survey
audit = {}
audit_log(
Actions.FORM_PUBLISHED, request.user, content_user,
_("Published form '%(id_string)s'.") %
{
'id_string': survey.id_string,
}, audit, request)
enketo_webform_url = reverse(
enter_data,
kwargs={'username': username, 'id_string': survey.id_string}
)
return {
'type': 'alert-success',
'preview_url': reverse(enketo_preview, kwargs={
'username': username,
'id_string': survey.id_string
}),
'text': _(u'Successfully published %(form_id)s.'
u' <a href="%(form_url)s">Enter Web Form</a>'
u' or <a href="#preview-modal" data-toggle="modal">'
u'Preview Web Form</a>')
% {'form_id': survey.id_string,
'form_url': enketo_webform_url},
'form_o': survey
}
示例7: instance
def instance(request, username, id_string):
xform, is_owner, can_edit, can_view = get_xform_and_perms(
username, id_string, request)
# no access
if not (xform.shared_data or can_view or
request.session.get('public_link') == xform.uuid):
return HttpResponseForbidden(_(u'Not shared.'))
context = RequestContext(request)
audit = {
"xform": xform.id_string,
}
audit_log(
Actions.FORM_DATA_VIEWED, request.user, xform.user,
_("Requested instance view for '%(id_string)s'.") %
{
'id_string': xform.id_string,
}, audit, request)
return render_to_response('instance.html', {
'username': username,
'id_string': id_string,
'xform': xform,
'can_edit': can_edit
}, context_instance=context)
示例8: delete_data
def delete_data(request, username=None, id_string=None):
xform, owner = check_and_set_user_and_form(username, id_string, request)
response_text = u''
if not xform:
return HttpResponseForbidden(_(u'Not shared.'))
data_id = request.POST.get('id')
if not data_id:
return HttpResponseBadRequest(_(u"id must be specified"))
Instance.set_deleted_at(data_id)
audit = {
'xform': xform.id_string
}
audit_log(
Actions.SUBMISSION_DELETED, request.user, owner,
_("Deleted submission with id '%(record_id)s' "
"on '%(id_string)s'.") %
{
'id_string': xform.id_string,
'record_id': data_id
}, audit, request)
response_text = json.dumps({"success": "Deleted data %s" % data_id})
if 'callback' in request.GET and request.GET.get('callback') != '':
callback = request.GET.get('callback')
response_text = ("%s(%s)" % (callback, response_text))
return HttpResponse(response_text, mimetype='application/json')
示例9: 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)
示例10: download_metadata
def download_metadata(request, username, id_string, data_id):
xform = get_object_or_404(XForm,
user__username=username, id_string=id_string)
owner = xform.user
if username == request.user.username or xform.shared:
data = get_object_or_404(MetaData, pk=data_id)
file_path = data.data_file.name
filename, extension = os.path.splitext(file_path.split('/')[-1])
extension = extension.strip('.')
dfs = get_storage_class()()
if dfs.exists(file_path):
audit = {
'xform': xform.id_string
}
audit_log(
Actions.FORM_UPDATED, request.user, owner,
_("Document '%(filename)s' for '%(id_string)s' downloaded.") %
{
'id_string': xform.id_string,
'filename': "%s.%s" % (filename, extension)
}, audit, request)
response = response_with_mimetype_and_name(
data.data_file_type,
filename, extension=extension, show_date=False,
file_path=file_path)
return response
else:
return HttpResponseNotFound()
return HttpResponseForbidden(_(u'Permission denied.'))
示例11: download_media_data
def download_media_data(request, username, id_string, data_id):
xform = get_object_or_404(XForm,
user__username=username, id_string=id_string)
owner = xform.user
data = get_object_or_404(MetaData, id=data_id)
default_storage = get_storage_class()()
if request.GET.get('del', False):
if username == request.user.username:
try:
default_storage.delete(data.data_file.name)
data.delete()
audit = {
'xform': xform.id_string
}
audit_log(Actions.FORM_UPDATED, request.user, owner,
_("Media download '%(filename)s' deleted from '%(id_string)s'.") %\
{
'id_string': xform.id_string,
'filename': os.path.basename(data.data_file.name)
}, audit, request)
return HttpResponseRedirect(reverse(show, kwargs={
'username': username,
'id_string': id_string
}))
except Exception, e:
return HttpResponseServerError()
示例12: 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
}))
示例13: 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
})
)
示例14: 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
示例15: profile_settings
def profile_settings(request, username):
context = RequestContext(request)
content_user = check_and_set_user(request, username)
context.content_user = content_user
profile, created = UserProfile.objects.get_or_create(user=content_user)
if request.method == 'POST':
form = UserProfileForm(request.POST, instance=profile)
if form.is_valid():
# get user
# user.email = cleaned_email
form.instance.user.email = form.cleaned_data['email']
form.instance.user.save()
form.save()
# todo: add string rep. of settings to see what changed
audit = {}
audit_log(
Actions.PROFILE_SETTINGS_UPDATED, request.user, content_user,
_("Profile settings updated."), audit, request)
return HttpResponseRedirect(reverse(
public_profile, kwargs={'username': request.user.username}
))
else:
form = UserProfileForm(
instance=profile, initial={"email": content_user.email})
return render_to_response("settings.html", {'form': form},
context_instance=context)