当前位置: 首页>>代码示例>>Python>>正文


Python request.QueryDict类代码示例

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


在下文中一共展示了QueryDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_server_group

    def add_server_group(request):
        response = BaseResponse()
        try:
            response.error = {}
            print(request.body)
            post_dict = QueryDict(request.body, encoding='utf-8')

            add_group_app_id = post_dict.get('add_group_app_id')
            add_group_name = post_dict.get('add_group_name')
            add_group_yaml_path = post_dict.get('add_group_yaml_path')
            add_group_type = post_dict.get('add_group_type')

            add_to_db = repository_models.AppGroups(
                name=add_group_name,
                yaml_path=add_group_yaml_path,
                # app_id = repository_models.Applications.objects.get(id=add_group_app_id)
                group_type=add_group_type,
            )

            add_to_db.save()
            add_to_db.app_id.add(repository_models.Applications.objects.get(id=add_group_app_id))

        except Exception as e:
            print(Exception, e)
            response.status = False
            response.message = str(e)
        return response
开发者ID:abuve,项目名称:JointerServer,代码行数:27,代码来源:group_config.py

示例2: encode_data

def encode_data(data, content_type=None):
    # type: (Any, Optional[text_type]) -> Any
    # content_type of None means django's test client's default content type
    # if content_type is None, return data as it is
    if content_type is None:
        if data is None:
            return {}
        else:
            return data
    elif content_type.startswith('application/json'):
        if data is None:
            raise BadDataError("empty_json")
        try:
            return force_text(json.dumps(data, cls=DjangoJSONEncoder))
        except ValueError:
            raise BadDataError("invalid_format")
    elif content_type.startswith(FORM_CONTENT_TYPE):
        if data is None or data == "":
            return ""
        elif isinstance(data, dict):
            form_data = QueryDict(mutable=True)
            for key, value in six.iteritems(data):
                if isinstance(value, Sequence) and not(isinstance(value, text_type)):
                    form_data.setlist(str(key), value)
                else:
                    form_data[key] = value
            return form_data.urlencode()
        else:
            raise BadDataError("invalid_format")
    else:
        raise ContentTypeError(content_type)
开发者ID:sharmaeklavya2,项目名称:poller,代码行数:31,代码来源:testing.py

示例3: data_create

    def data_create(request):
        response = BaseResponse()
        try:
            post_data = QueryDict(request.body, encoding='utf-8')
            role_name = post_data.get('role_name')
            role_memo = post_data.get('role_memo')
            permission_list = post_data.getlist('permission_list')

            # 创建role
            data_obj = USER_CENTER_MODELS.Roles(
                name=role_name,
                memo=role_memo,
            )
            data_obj.save()

            # 关联permission
            for obj_id in permission_list:
                data_obj.permissions.add(obj_id)

        except Exception as e:
            print(Exception, e)
            response.status = False
            response.message = str(e)

        return response
开发者ID:abuve,项目名称:JointerServer,代码行数:25,代码来源:roles.py

示例4: do

    def do(self, action_context, view, email, *args, **kwargs):
        # Reset token
        user = action_context.extra_context.get('user')
        if user:
            refresh_password_reset_token(user)
            url = reverse('auth:reset-password', kwargs={
                'user_id': user.id,
                'uuid': str(user.password_reset_token)})

            # Prepare the full url (get the domain from the asked
            # wiggum entrypoint)
            domain = action_context.request.META.get('HTTP_HOST')
            scheme = 'http' if settings.DEBUG else "https"

            # Get redirection uri
            params = QueryDict(mutable=True)
            redirect_uri = action_context.extra_context.get("redirect_uri")
            if redirect_uri:
                params[settings.REDIRECT_URL_VALID_PARAMS[0]] = redirect_uri

            url = urllib.parse.ParseResult(scheme=scheme,
                                           netloc=domain,
                                           path=url,
                                           params="",
                                           query=params.urlencode(),
                                           fragment="").geturl()

            action_context.extra_context['pass_reset_url'] = url
            logger.debug("Password recover url created: {0}".format(url))
        return super().do(action_context, view, email, *args, **kwargs)
开发者ID:Endika,项目名称:wiggum,代码行数:30,代码来源:recover_pass_request.py

示例5: update_urlmaps_groups

    def update_urlmaps_groups(request):
        response = BaseResponse()
        try:
            response.error = {}
            post_dict = QueryDict(request.body, encoding='utf-8')
            urlmaps_id = post_dict.get('urlmaps_id')
            instance_list = post_dict.getlist('instance_list')
            group_type = post_dict.get('group_type')

            urlmaps_obj = repository_models.UrlConfigHandler.objects.get(id=urlmaps_id)

            if group_type == 'cloud':
                urlmaps_obj.cloud.clear()
                for instance_id in instance_list:
                    urlmaps_obj.cloud.add(CMDB_MODELS.Asset.objects.get(id=instance_id))
            elif group_type == 'forward':
                urlmaps_obj.forward.clear()
                for instance_id in instance_list:
                    urlmaps_obj.forward.add(CMDB_MODELS.Asset.objects.get(id=instance_id))
            elif group_type == 'docker':
                urlmaps_obj.docker.clear()
                for instance_id in instance_list:
                    urlmaps_obj.docker.add(CMDB_MODELS.DockerInstance.objects.get(id=instance_id))

        except Exception as e:
            print(Exception, e)
            response.status = False
            response.message = str(e)
        return response
开发者ID:abuve,项目名称:JointerServer,代码行数:29,代码来源:urlmaps_config.py

示例6: get

    def get(self, request, *args, **kwargs):
        args_dict = request.GET.copy()
        args_dict.update({
            "test_suite_pk": kwargs["pk"],
            "measure_name": kwargs["mname"]
        })

        cmd = [
            settings.PYTHON_EXE,
            os.path.join(settings.BASE_DIR, "bin", "plot_png.py"),
            args_dict.urlencode(safe='/%')
        ]

        print "Plot png: %s" % cmd[-1]

        result = subprocess.check_output(cmd, env=os.environ.copy()).strip()

        qdict = QueryDict(result)
        fname = qdict.get("fname")
        alarm = qdict.get("alarm")

        if fname and fname != "":
            f = open(fname, 'rb')
            response = HttpResponse(f.read(), 'image/png')
            f.close()
            m_path = reverse(
                'appmonitor:measure', args=[kwargs["pk"], kwargs["mname"]]
            )
            response.set_cookie("alarm_state", alarm, path=m_path)
            return response
        else:
            f = open('appmonitor/static/appmonitor/nodata.png', 'rb')
            response = HttpResponse(f.read(), 'image/png')
            f.close()
            return response
开发者ID:magenta-aps,项目名称:aalborg-monitor,代码行数:35,代码来源:views.py

示例7: get_form_kwargs

 def get_form_kwargs(self):
     kwargs = super(RegistrationView, self).get_form_kwargs()
     self.ax = self.request.session['ax']
     if not self.ax:
         self.ax = RegistrationView.get_ax(self.request.POST)
     if self.ax:
         ax_data = {
                 'first_name' : self.ax['firstname'].split(maxsplit=1)[0] if 'firstname' in self.ax.keys() else None,
                 'last_name' : self.ax['lastname'] if 'lastname' in self.ax.keys() else None,
                 'gender' : self.ax['gender'] if 'gender' in self.ax.keys() else None,
                 'street' : self.ax['address'] if 'address' in self.ax.keys() else None,
                 'town' : self.ax['city'] if 'city' in self.ax.keys() else None,
                 'zip' : self.ax['postal_code'] if 'postal_code' in self.ax.keys() else None,
                 'birthday_day' : self.ax['birth_day'] if 'birth_day' in self.ax.keys() else None,
                 'birthday_month' : self.ax['birth_month'] if 'birth_month' in self.ax.keys() else None,
                 'birthday_year' : self.ax['birth_year'] if 'birth_year' in self.ax.keys() else None
         }
         data = QueryDict('', mutable=True)
         data.update(ax_data)
         if 'data' in kwargs.keys():
             data.update(kwargs['data'])
         kwargs['data'] = data
         kwargs.update({'eid' : True})
         self.eid = True
     else:
         kwargs.update({'eid' : False})
     self.request.session['ax'] = self.ax
     return kwargs
开发者ID:dsarkozi,项目名称:care4care-sdp-grp4,代码行数:28,代码来源:RegistrationView.py

示例8: add_data

    def add_data(request):
        response = BaseResponse()
        try:
            response.error = []
            post_dict = QueryDict(request.body, encoding='utf-8')

            idc_name = post_dict.get('idc_name')
            idc_floor = post_dict.get('idc_floor')
            idc_phone = post_dict.get('idc_phone')
            idc_address = post_dict.get('idc_address')

            add_to_db = CMDB_MODELS.IDC(
                name=idc_name,
                floor=idc_floor,
                phone=idc_phone,
                idc_address = idc_address,

            )
            add_to_db.save()

        except Exception as e:
            print(Exception, e)
            response.status = False
            response.message = str(e)
        return response
开发者ID:abuve,项目名称:JointerServer,代码行数:25,代码来源:idc.py

示例9: auto_publish

def auto_publish(request, category_id=3):
    with open("/home/david/htdocs/feedback_django/example/spirit/topic/json/O.json","r",encoding='UTF-8') as file:
        jsonContent = json.load(file)
        # print(jsonContent['course'][0])
        
        # <QueryDict: {'comment': ['fuck'], 'category': ['5'], 'csrfmiddlewaretoken': ['TrhHjnBCe5pAHjeSKGN4n3kbY3m7SvXh'], 'title': ['auto']}>
        jsondict = {'category': ['3'], 'comment': ['this is test'],
            'csrfmiddlewaretoken': ['TrhHjnBCe5pAHjeSKGN4n3kbY3m7SvXh'], 'title':  ['json works']}
        qdict = QueryDict('',mutable=True)
        qdict.update(jsondict)

    if category_id:
        get_object_or_404(Category.objects.visible(),
                          pk=category_id)

    form = TopicForm(user=request.user, data=qdict)
    cform = CommentForm(user=request.user, data=qdict)
    print(form)
    print(form.is_valid())
    print(cform.is_valid())
    if all([form.is_valid(), cform.is_valid()]):  # TODO: test!
        # wrap in transaction.atomic?
        topic = form.save()
        cform.topic = topic
        comment = cform.save()
        comment_posted(comment=comment, mentions=cform.mentions)
        return redirect(topic.get_absolute_url())

    context = {
        'form': form,
        'cform': cform
    }
    return render(request, 'spirit/topic/publish.html', context)
开发者ID:david30907d,项目名称:feedback_django,代码行数:33,代码来源:views.py

示例10: dict_to_querydict

def dict_to_querydict(dict_data):
    qdict = QueryDict('', mutable=True)
    for key, value in dict_data.items():
        if isinstance(value, list):
            qdict.setlist(key, value)
        else:
            qdict[key] = value
    return qdict
开发者ID:codeforamerica,项目名称:intake,代码行数:8,代码来源:test_edit_form_service.py

示例11: encode_query

def encode_query(querydict):
    """
    Encode a querydict as form params, using '+'' for ' '.
    """
    if not isinstance(querydict, QueryDict):
        temp = querydict
        querydict = QueryDict('', mutable=True)
        querydict.update(temp)
    return querydict.urlencode(': ').replace(' ', '+')
开发者ID:harvard-lil,项目名称:nuremberg,代码行数:9,代码来源:search_url.py

示例12: query_string_from_dict

def query_string_from_dict(qs_dict):
    qs_prepared_dict = OrderedDict()
    for key, val in qs_dict.items():
        if isinstance(val, list):
            val = '[%s]' % ','.join([force_text(v) for v in val])
        qs_prepared_dict[key] = val

    qdict = QueryDict('').copy()
    qdict.update(qs_prepared_dict)
    return qdict.urlencode()
开发者ID:matllubos,项目名称:django-chamber,代码行数:10,代码来源:http.py

示例13: update_params

    def update_params(param_str, **kwargs):
        query_dict = QueryDict(param_str, True)

        for key, val in kwargs.iteritems():
            if val:
                query_dict[key] = val
            else:
                query_dict.pop(key) if query_dict.has_key(key) else None

        return UrlHelper.format_params(query_dict)
开发者ID:lzp401,项目名称:srtracker,代码行数:10,代码来源:support.py

示例14: delete_data

 def delete_data(request):
     response = BaseResponse()
     try:
         recv_data = QueryDict(request.body, encoding='utf-8')
         project_id = recv_data.get("project_id")
         repository_models.ProjectInfo.objects.get(id=project_id).delete()
         response.message = '删除成功'
     except Exception as e:
         response.status = False
         response.message = str(e)
     return response
开发者ID:abuve,项目名称:JointerServer,代码行数:11,代码来源:project.py

示例15: render

 def render(self, context):
     if not len(self.args) or "=" in self.args[0]:
         querydict = QueryDict("", mutable=True)
     else:
         first = self.args[0]
         self.args = self.args[1:]
         querydict = Variable(first).resolve(context).copy()
     for pair in self.args:
         k, v = [Variable(p).resolve(context) for p in pair.split("=")]
         querydict[k] = v
     return querydict.urlencode()
开发者ID:uranusjr,项目名称:uranusjr.com,代码行数:11,代码来源:base_tags.py


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