本文整理汇总了Python中tardis.tardis_portal.shortcuts.return_response_error函数的典型用法代码示例。如果您正苦于以下问题:Python return_response_error函数的具体用法?Python return_response_error怎么用?Python return_response_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了return_response_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: experiment_stats
def experiment_stats(request, epn):
"""Get stats about an experiment associated with the given EPN.
:param request: a HTTP Request instance
:type request: :class:`django.http.HttpRequest`
:param epn: the EPN (proposal number) of the experiment to be edited
:type epn: string
:rtype: :class:`django.http.HttpResponse`
"""
if not (request.META['REMOTE_ADDR'] == '114.30.64.13' or request.META['REMOTE_USER'] == 'admin'):
return return_response_error(request)
try:
epn_param = models.ExperimentParameter.objects.get(name__name__exact='EPN', string_value=epn)
experiment_id = epn_param.parameterset.experiment.pk
#experiment = models.Experiment.safe.get(request, experiment_id)
except PermissionDenied:
return return_response_error(request)
except models.ExperimentParameter.DoesNotExist:
return return_response_not_found(request)
# calculate the sum of the datafile sizes
datafile_sizes = models.Dataset_File.objects.filter(dataset__experiment=experiment_id).values_list('size', flat=True)
json_dict = {}
json_dict['total_file_count'] = len(datafile_sizes)
json_dict['total_file_size'] = sum(map(long, datafile_sizes))
response = HttpResponse(json.dumps(json_dict), mimetype='application/json')
response['Pragma'] = 'no-cache'
response['Cache-Control'] = 'no-cache, must-revalidate'
return response
示例2: view_rifcs
def view_rifcs(request, experiment_id):
"""View the rif-cs of an existing experiment.
:param request: a HTTP Request instance
:type request: :class:`django.http.HttpRequest`
:param experiment_id: the ID of the experiment to be viewed
:type experiment_id: string
:rtype: :class:`django.http.HttpResponse`
"""
try:
experiment = Experiment.safe.get(request.user, experiment_id)
except PermissionDenied:
return return_response_error(request)
except Experiment.DoesNotExist:
return return_response_not_found(request)
try:
rifcs_provs = settings.RIFCS_PROVIDERS
except AttributeError:
rifcs_provs = ()
from tardis.tardis_portal.publish.publishservice import PublishService
pservice = PublishService(rifcs_provs, experiment)
context = pservice.get_context()
if context is None:
# return error page or something
return return_response_error(request)
template = pservice.get_template()
return HttpResponse(render_response_index(request,
template, context), content_type="text/xml")
示例3: table
def table(request, experiment_id):
# http://datatables.net/usage/server-side
if len(request.GET) == 0:
return return_response_error(request)
sort_col_index = ''
sort_col_name = ''
sort_desc = ''
try:
if int(request.GET['iSortingCols']) != 1:
return return_response_error(request)
sort_col_index = request.GET['iSortCol_0']
sort_col_name = request.GET['mDataProp_' + sort_col_index]
sort_desc = request.GET['sSortDir_0'] == 'desc'
except:
return return_response_error(request)
experiment = Experiment.objects.get(pk=experiment_id)
parameter_names = ParameterName.objects.filter(datafileparameter__parameterset__dataset_file__dataset__experiment=experiment).distinct()
datafiles = Dataset_File.objects.filter(dataset__experiment=experiment)
if sort_col_name == 'filename':
if sort_desc:
datafiles = datafiles.order_by('-filename')
else:
datafiles = datafiles.order_by('filename')
post_filter = False
else:
datafiles = datafiles.order_by('filename')
post_filter = True
filter = ''
limit = ''
offset = ''
try:
filter = request.GET['sSearch']
limit = int(request.GET['iDisplayLength'])
offset = int(request.GET['iDisplayStart'])
except:
return return_response_error(request)
filtered_datafiles = _filter(datafiles, filter)
dfs = [(x.id, x.filename) for x in filtered_datafiles[offset:offset+limit]]
df_ids = [x[0] for x in dfs]
params_by_file = _params_by_file(df_ids, parameter_names)
rows = _get_rows(dfs, parameter_names, params_by_file, sort_desc, post_filter, sort_col_name)
resp = {}
resp['sEcho'] = int(request.GET['sEcho'])
resp['aaData'] = rows
resp['iTotalRecords'] = datafiles.count()
resp['iTotalDisplayRecords'] = filtered_datafiles.count()
return HttpResponse(json.dumps(resp), mimetype='application/json')
示例4: change_user_permissions
def change_user_permissions(request, experiment_id, username):
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
return return_response_error(request)
try:
experiment = Experiment.objects.get(pk=experiment_id)
except Experiment.DoesNotExist:
return return_response_error(request)
try:
expt_acls = Experiment.safe.user_acls(experiment_id)
acl = None
for eacl in expt_acls:
if eacl.pluginId == 'django_user' and \
eacl.get_related_object().id == user.id:
acl = eacl
#acl = expt_acls.filter(entityId=str(user.id))
if acl is None:
raise ObjectACL.DoesNotExist
owner_acls = [oacl for oacl in expt_acls if oacl.isOwner]
except ObjectACL.DoesNotExist:
return return_response_error(request)
if request.method == 'POST':
form = ChangeUserPermissionsForm(request.POST, instance=acl)
if form.is_valid():
if 'isOwner' in form.changed_data and \
form.cleaned_data['isOwner'] is False and \
len(owner_acls) == 1:
owner = owner_acls[0].get_related_object()
plugin = owner_acls[0].pluginId
if plugin == 'django_user' and owner.id == user.id:
return render_error_message(
request,
'Cannot remove ownership, every experiment must have at '
'least one user owner.', status=409)
form.save()
url = reverse('tardis.tardis_portal.views.control_panel')
return HttpResponseRedirect(url)
else:
form = ChangeUserPermissionsForm(instance=acl)
c = {'form': form,
'header':
"Change User Permissions for '%s'" % user.username}
return HttpResponse(render_response_index(
request, 'tardis_portal/form_template.html', c))
示例5: add_dataset_par
def add_dataset_par(request, dataset_id):
parentObject = Dataset.objects.get(id=dataset_id)
if authz.has_write_permissions(request, parentObject.experiment.id):
return add_par_alt(request, parentObject, otype="dataset",
stype=Schema.DATASET)
else:
return return_response_error(request)
示例6: add_experiment_par
def add_experiment_par(request, experiment_id):
parentObject = Experiment.objects.get(id=experiment_id)
if authz.has_write_permissions(request, parentObject.id):
return add_par_alt(request, parentObject, otype="experiment",
stype=Schema.EXPERIMENT)
else:
return return_response_error(request)
示例7: new_sample
def new_sample(request, experiment_id):
try:
experiment = Experiment.safe.get(request, experiment_id)
except PermissionDenied:
return return_response_error(request)
except Experiment.DoesNotExist:
return return_response_not_found(request)
c = Context()
c['experiment'] = experiment
samples = Sample.objects.filter(experiment=experiment_id)
c['sample_count'] = samples.count() + 1
if request.method == 'POST':
form = SampleForm(request.POST)
if form.is_valid():
sample = form.save(experiment_id, commit=False)
sample.save_m2m()
request.POST = {'status': "Sample Created."}
return _redirect(experiment_id)
c['status'] = "Errors exist in form."
c["error"] = 'true'
else:
form = SampleForm(extra=1)
c['form'] = form
c['status'] = form.errors
return HttpResponse(render_response_index(request,
'tardis_portal/experiment_sample.html', c))
示例8: wrap
def wrap(request, *args, **kwargs):
dataset_id = kwargs['dataset_id']
if not has_dataset_write(request, dataset_id):
if request.is_ajax():
return HttpResponse("")
return return_response_error(request)
return f(request, *args, **kwargs)
示例9: wrap
def wrap(request, *args, **kwargs):
if not request.user.groups.filter(
name=getattr(
settings, 'PUBLICATION_OWNER_GROUP',
default_settings.PUBLICATION_OWNER_GROUP)).exists():
return return_response_error(request)
return f(request, *args, **kwargs)
示例10: load_dataset_image
def load_dataset_image(request, parameter_id):
parameter = DatasetParameter.objects.get(pk=parameter_id)
dataset = parameter.parameterset.dataset
if authz.has_dataset_access(request, dataset.id):
return load_image(request, parameter)
else:
return return_response_error(request)
示例11: load_experiment_image
def load_experiment_image(request, parameter_id):
parameter = ExperimentParameter.objects.get(pk=parameter_id)
experiment_id = parameter.parameterset.experiment.id
if authz.has_experiment_access(request, experiment_id):
return load_image(request, parameter)
else:
return return_response_error(request)
示例12: get
def get(self, request, *args, **kwargs):
"""
The index view, intended to render the front page of the MyTardis site
listing recent experiments.
This default view can be overriden by defining a dictionary INDEX_VIEWS in
settings which maps SITE_ID's or domain names to an alternative view
function (similar to the DATASET_VIEWS or EXPERIMENT_VIEWS overrides).
:param request: a HTTP request object
:type request: :class:`django.http.HttpRequest`
:return: The Django response object
:rtype: :class:`django.http.HttpResponse`
"""
dataset_id = kwargs.get('dataset_id', None)
if dataset_id is None:
return return_response_error(request)
dataset = Dataset.objects.get(id=dataset_id)
if not dataset:
return return_response_not_found(request)
view_override = self.find_custom_view_override(request, dataset)
if view_override is not None:
return view_override
c = self.get_context_data(request, dataset, **kwargs)
template_name = kwargs.get('template_name', None)
if template_name is None:
template_name = self.template_name
return HttpResponse(render_response_index(request, template_name, c))
示例13: _list_related_info
def _list_related_info(request, experiment_id):
if not authz.has_experiment_access(request, experiment_id):
return return_response_error(request)
sets = ExperimentParameterSet.objects.filter(schema__namespace=SCHEMA_URI)
return HttpResponse(json.dumps([_get_dict_from_ps(ps)
for ps in sets]),
content_type='application/json; charset=utf-8')
示例14: get
def get(self, request, *args, **kwargs):
"""
:param request: a HTTP request object
:type request: :class:`django.http.HttpRequest`
:return: The Django response object
:rtype: :class:`django.http.HttpResponse`
"""
dataset_id = kwargs.get('dataset_id', None)
if dataset_id is None:
return return_response_error(request)
dataset = Dataset.objects.get(id=dataset_id)
if not dataset:
return return_response_not_found(request)
c = self.get_context_data(request, dataset, **kwargs)
template_name = kwargs.get('template_name', None)
if template_name is None:
template_name = self.template_name
return HttpResponse(render_response_index(
request,
template_name,
c)
)
示例15: edit_datafile_par
def edit_datafile_par(request, parameterset_id):
parameterset = DatafileParameterSet.objects.get(id=parameterset_id)
if authz.has_write_permissions(request,
parameterset.dataset_file.dataset.experiment.id):
return edit_parameters_alt(request, parameterset, otype="datafile")
else:
return return_response_error(request)