• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python shortcuts.return_response_error函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tardis.tardis_portal.shortcuts.return_response_error函数的典型用法代码示例。如果您正苦于以下问题:Python return_response_error函数的具体用法?Python return_response_error怎么用?Python return_response_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了return_response_error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:aaryani,项目名称:aa-migration-test1,代码行数:32,代码来源:views.py


示例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")
开发者ID:IntersectAustralia,项目名称:mytardis,代码行数:32,代码来源:machine.py


示例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')
开发者ID:ANSTO,项目名称:summary_table,代码行数:57,代码来源:views.py


示例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))
开发者ID:keithschulze,项目名称:mytardis,代码行数:52,代码来源:authorisation.py


示例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)
开发者ID:aaryani,项目名称:hpctardis,代码行数:7,代码来源:views.py


示例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)
开发者ID:aaryani,项目名称:hpctardis,代码行数:7,代码来源:views.py


示例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))
开发者ID:IntersectAustralia,项目名称:dc2c,代码行数:29,代码来源:views.py


示例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)
开发者ID:guillaumeprevost,项目名称:mytardis,代码行数:7,代码来源:decorators.py


示例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)
开发者ID:keithschulze,项目名称:mytardis,代码行数:7,代码来源:views.py


示例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)
开发者ID:IntersectAustralia,项目名称:mytardis,代码行数:7,代码来源:images.py


示例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)
开发者ID:IntersectAustralia,项目名称:mytardis,代码行数:7,代码来源:images.py


示例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))
开发者ID:nrmay,项目名称:mytardis,代码行数:34,代码来源:pages.py


示例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')
开发者ID:conkiztador,项目名称:mytardis,代码行数:7,代码来源:views.py


示例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)
        )
开发者ID:mytardis,项目名称:mytardis-seqfac,代码行数:29,代码来源:views.py


示例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)
开发者ID:aaryani,项目名称:hpctardis,代码行数:7,代码来源:views.py


示例16: edit_sample

def edit_sample(request, experiment_id, sample_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
    sample = Sample.objects.get(id=sample_id)
    c['sample_count'] = sample.name
    
    if request.POST:
        form = SampleForm(request.POST, instance=sample, extra=0)
        if form.is_valid():
            full_sample = form.save(experiment_id, commit=False)
            
            full_sample.save_m2m()
            request.POST = {'status': "Sample Created."}
            return _redirect(experiment_id)
        c['status'] = "Errors exist in form."
        c["error"] = 'true'
    else:
        form = SampleForm(instance=sample, extra=0)
    
    c['form'] = form    
    c['status'] = form.errors
    return HttpResponse(render_response_index(request,
                        'tardis_portal/experiment_sample.html', c))
开发者ID:IntersectAustralia,项目名称:dc2c,代码行数:29,代码来源:views.py


示例17: change_group_permissions

def change_group_permissions(request, experiment_id, group_id):

    try:
        group = Group.objects.get(pk=group_id)
    except Group.DoesNotExist:
        return return_response_error(request)

    try:
        experiment = Experiment.objects.get(pk=experiment_id)
    except Experiment.DoesNotExist:
        return return_response_error(request)

    try:
        acl = ObjectACL.objects.get(
            content_type=experiment.get_ct(),
            object_id=experiment.id,
            pluginId='django_group',
            entityId=str(group.id),
            aclOwnershipType=ObjectACL.OWNER_OWNED)
    except ObjectACL.DoesNotExist:
        return return_response_error(request)

    if request.method == 'POST':
        form = ChangeGroupPermissionsForm(request.POST)

        if form.is_valid():
            acl.canRead = form.cleaned_data['canRead']
            acl.canWrite = form.cleaned_data['canWrite']
            acl.canDelete = form.cleaned_data['canDelete']
            acl.effectiveDate = form.cleaned_data['effectiveDate']
            acl.expiryDate = form.cleaned_data['expiryDate']
            acl.save()
            return HttpResponseRedirect('/experiment/control_panel/')

    else:
        form = ChangeGroupPermissionsForm(
            initial={'canRead': acl.canRead,
                     'canWrite': acl.canWrite,
                     'canDelete': acl.canDelete,
                     'effectiveDate': acl.effectiveDate,
                     'expiryDate': acl.expiryDate})

    c = {'form': form,
         'header': "Change Group Permissions for '%s'" % group.name}

    return HttpResponse(render_response_index(
        request, 'tardis_portal/form_template.html', c))
开发者ID:jasonrig,项目名称:mytardis,代码行数:47,代码来源:authorisation.py


示例18: _create_download_response

def _create_download_response(request, datafile_id, disposition='attachment'):  # too complex # noqa
    # Get datafile (and return 404 if absent)
    try:
        datafile = DataFile.objects.get(pk=datafile_id)
    except DataFile.DoesNotExist:
        return return_response_not_found(request)
    # Check users has access to datafile
    if not has_datafile_download_access(request=request,
                                        datafile_id=datafile.id):
        return return_response_error(request)
    # Send an image that can be seen in the browser
    if disposition == 'inline' and datafile.is_image():
        from tardis.tardis_portal.iiif import download_image
        args = (request, datafile.id, 'full', 'full', '0', 'native')
        # Send unconverted image if web-compatible
        if datafile.get_mimetype() in ('image/gif', 'image/jpeg', 'image/png'):
            return download_image(*args)
        # Send converted image
        return download_image(*args, format='png')
    # Send local file
    try:
        verified_only = True
        # Query parameter to allow download of unverified files
        ignore_verif = request.GET.get('ignore_verification_status', '0')
        # Ensure ignore_verification_status=0 etc works as expected
        # a bare ?ignore_verification_status is True
        if ignore_verif.lower() in [u'', u'1', u'true']:
            verified_only = False

        # Get file object for datafile
        file_obj = datafile.get_file(verified_only=verified_only)
        if not file_obj:
            # If file path doesn't resolve, return not found
            if verified_only:
                return render_error_message(request,
                                            "File is unverified, "
                                            "please try again later.",
                                            status=503)
            return return_response_not_found(request)
        wrapper = FileWrapper(file_obj, blksize=65535)
        response = StreamingHttpResponse(wrapper,
                                         content_type=datafile.get_mimetype())
        response['Content-Disposition'] = \
            '%s; filename="%s"' % (disposition, datafile.filename)
        return response
    except IOError:
        # If we can't read the file, return not found
        return return_response_not_found(request)
    except ValueError:  # raised when replica not verified TODO: custom excptn
        redirect = request.META.get('HTTP_REFERER',
                                    'http://%s/' %
                                    request.META.get('HTTP_HOST'))
        message = """The file you are trying to access has not yet been
                     verified. Verification is an automated background process.
                     Please try again later or contact the system
                     administrator if the issue persists."""
        message = ' '.join(message.split())  # removes spaces
        redirect = redirect + '#error:' + message
        return HttpResponseRedirect(redirect)
开发者ID:keithschulze,项目名称:mytardis,代码行数:59,代码来源:download.py


示例19: wrap

 def wrap(request, *args, **kwargs):
     user = request.user
     if not request.user.is_authenticated():
         return HttpResponseRedirect('/login?next=%s' % request.path)
     if not (is_group_admin(request, kwargs['group_id']) or
             user.is_superuser):
         return return_response_error(request)
     return f(request, *args, **kwargs)
开发者ID:keithschulze,项目名称:mytardis,代码行数:8,代码来源:decorators.py


示例20: add_user_to_group

def add_user_to_group(request, group_id, username):

    if username == settings.TOKEN_USERNAME:
        return HttpResponse('User does not exist: %s' % username)

    authMethod = localdb_auth_key
    isAdmin = False

    if 'isAdmin' in request.GET:
        if request.GET['isAdmin'] == 'true':
            isAdmin = True

    try:
        authMethod = request.GET['authMethod']
        if authMethod == localdb_auth_key:
            user = User.objects.get(username=username)
        else:
            user = UserAuthentication.objects.get(
                username=username,
                authenticationMethod=authMethod).userProfile.user
    except User.DoesNotExist:
        return return_response_error(request)
    except UserAuthentication.DoesNotExist:
        return return_response_error(request)

    try:
        group = Group.objects.get(pk=group_id)
    except Group.DoesNotExist:
        return HttpResponse('Group does not exist.')

    if user.groups.filter(name=group.name).count() > 0:
        return HttpResponse('User %s is already member of that group.'
                            % username)

    user.groups.add(group)
    user.save()

    if isAdmin:
        groupadmin = GroupAdmin(user=user, group=group)
        groupadmin.save()

    c = {'user': user, 'group_id': group_id, 'isAdmin': isAdmin}
    return HttpResponse(render_response_index(
        request,
        'tardis_portal/ajax/add_user_to_group_result.html', c))
开发者ID:jasonrig,项目名称:mytardis,代码行数:45,代码来源:authorisation.py



注:本文中的tardis.tardis_portal.shortcuts.return_response_error函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.parse_quantity函数代码示例发布时间:2022-05-27
下一篇:
Python shortcuts.render_response_index函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap