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


Python context_processors.additional_user_info函数代码示例

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


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

示例1: get_context_data

    def get_context_data(self, **kwargs):
        context = super(ReportsListView, self).get_context_data(**kwargs)
        cc_filter_list = []
        user_filter_list = []

        user_data = additional_user_info(self.request)

        report = self.request.GET.get('report', None)

        thematic_list = ThematicArea.objects.all().order_by('name')
        user_list = User.objects.filter(is_superuser=False).order_by('username')
        # mantain in user filter list only users from the same CCS (CC's in the network) as request.user
        for user in user_list:
            user_cc = user.profile.get_attribute('cc')
            if user_cc == user_data['user_cc'] or user_cc in user_data['ccs']:
                user_filter_list.append(user)

        cc_filter_list = user_data['ccs']
        # remove duplications from list
        cc_filter_list = list(set(cc_filter_list))
        cc_filter_list.sort()

        show_advaced_filters = self.request.GET.get('apply_filters', False)

        context['cc_filter_list'] = cc_filter_list
        context['user_filter_list'] = user_filter_list
        context['thematic_list'] = thematic_list
        context['show_advaced_filters'] = show_advaced_filters
        context['title'] = u'export'
        context['params'] = self.request.GET

        return context
开发者ID:wilsonmoura,项目名称:fi-admin,代码行数:32,代码来源:views.py

示例2: get_queryset

    def get_queryset(self):
        user_data = additional_user_info(self.request)
        user_role = user_data['service_role'].get('DirIns')

        # getting action parameter
        self.actions = {}
        for key in ACTIONS.keys():
            self.actions[key] = self.request.GET.get(key, ACTIONS[key])


        # search filter
        search = self.actions['s']
        search_filter = Q(name__icontains=search) | Q(cc_code__icontains=search) | Q(acronym__icontains=search)

        object_list = self.model.objects.filter(search_filter)

        if self.actions['filter_status'] != '':
            object_list = object_list.filter(status=self.actions['filter_status'])

        if self.actions['order'] == "-":
            object_list = object_list.order_by("%s%s" % (self.actions["order"], self.actions["orderby"]))

        # filter by institution of user
        if self.actions['filter_owner'] != "*":
            object_list = object_list.filter(cc_code=user_data['user_cc'])

        return object_list
开发者ID:bireme,项目名称:fi-admin,代码行数:27,代码来源:views.py

示例3: get_context_data

    def get_context_data(self, **kwargs):
        context = super(InstUpdate, self).get_context_data(**kwargs)

        user_data = additional_user_info(self.request)
        user_role = user_data['service_role'].get('DirIns')
        user_id = self.request.user.id
        if self.object:
            user_data['is_owner'] = True if self.object.created_by == self.request.user else False

        context['user_data'] = user_data
        context['user_role'] = user_role

        # create flag that control if user have permission to edit the reference
        context['user_can_edit'] = True if not self.object or self.object.cooperative_center_code in ['BR1.1', user_data['user_cc']] else False
        if user_role == 'doc':
            context['user_can_change_status'] = False
        else:
            context['user_can_change_status'] = True

        context['settings'] = settings
        context['help_fields'] = get_help_fields('institution')

        if self.object:
            c_type = ContentType.objects.get_for_model(self.get_object())
            context['c_type'] = c_type

        if self.request.method == 'GET':
            context['formset_person'] = PersonFormSet(instance=self.object)
            context['formset_phone'] = PhoneFormSet(instance=self.object)
            context['formset_email'] = EmailFormSet(instance=self.object)
            context['formset_url'] = URLFormSet(instance=self.object)
            context['formset_adm'] = AdmFormSet(instance=self.object)
            context['formset_unitlevel'] = UnitLevelFormSet(instance=self.object)

        return context
开发者ID:bireme,项目名称:fi-admin,代码行数:35,代码来源:views.py

示例4: list_events

def list_events(request):

    user = request.user
    output = {}
    delete_id = request.POST.get('delete_id')

    if delete_id:
        delete_event(request, delete_id)

    # getting action parameters
    actions = {}
    for key in ACTIONS.keys():
        if request.REQUEST.get(key):
            actions[key] = request.REQUEST.get(key)
        else:
            actions[key] = ACTIONS[key]

    page = 1
    if actions['page'] and actions['page'] != '':
        page = actions['page']

    user_data = additional_user_info(request)
    events = Event.objects.filter(title__icontains=actions['s'])

    if actions['filter_status'] != '':
        events = events.filter(status=actions['filter_status'])

    if actions['filter_thematic'] != '':
        actions['filter_thematic'] = int(actions['filter_thematic'])
        events = events.filter(thematics__thematic_area=actions['filter_thematic'])


    events = events.order_by(actions["orderby"])
    if actions['order'] == "-":
        events = events.order_by("%s%s" % (actions["order"], actions["orderby"]))

    if actions['filter_owner'] == "network":        
        events = events.filter(cooperative_center_code__in=user_data['ccs'])
    elif actions['filter_owner'] != "*":
        events = events.filter(created_by=request.user)
    else:
        events = events.all()

    # populate thematic list for filter
    thematic_list = ThematicArea.objects.all().order_by('name')

    # pagination
    pagination = {}
    paginator = Paginator(events, settings.ITEMS_PER_PAGE)
    pagination['paginator'] = paginator
    pagination['page'] = paginator.page(page)
    events = pagination['page'].object_list

    output['events'] = events
    output['thematic_list'] = thematic_list
    output['actions'] = actions
    output['pagination'] = pagination
    output['user_data'] = user_data

    return render_to_response('events/events.html', output, context_instance=RequestContext(request))
开发者ID:menezesre,项目名称:fi-admin,代码行数:60,代码来源:views.py

示例5: form_valid

    def form_valid(self, form):
        formset_person = PersonFormSet(self.request.POST, instance=self.object)
        formset_phone = PhoneFormSet(self.request.POST, instance=self.object)
        formset_email = EmailFormSet(self.request.POST, instance=self.object)
        formset_url = URLFormSet(self.request.POST, instance=self.object)
        formset_unitlevel = UnitLevelFormSet(self.request.POST, instance=self.object)
        formset_adm = AdmFormSet(self.request.POST, instance=self.object)

        # run all validation before for display formset errors at form
        form_valid = form.is_valid()

        formset_person_valid = formset_person.is_valid()
        formset_phone_valid = formset_phone.is_valid()
        formset_email_valid = formset_email.is_valid()
        formset_url_valid = formset_url.is_valid()
        formset_unitlevel_valid = formset_unitlevel.is_valid()
        formset_adm_valid = formset_adm.is_valid()

        user_data = additional_user_info(self.request)

        if (form_valid and formset_person_valid and formset_phone_valid and
            formset_email_valid and formset_url_valid and formset_unitlevel_valid and
            formset_adm_valid):

                self.object = form.save()

                formset_person.instance = self.object
                formset_person.save()

                formset_phone.instance = self.object
                formset_phone.save()

                formset_email.instance = self.object
                formset_email.save()

                formset_url.instance = self.object
                formset_url.save()

                formset_unitlevel.instance = self.object
                formset_unitlevel.save()

                formset_adm.instance = self.object
                formset_adm.save()

                # update solr index
                form.save()
                # save many-to-many relation fields
                form.save_m2m()

                return HttpResponseRedirect(self.get_success_url())
        else:
            return self.render_to_response(
                           self.get_context_data(form=form,
                                                 formset_person=formset_person,
                                                 formset_phone=formset_phone,
                                                 formset_email=formset_email,
                                                 formset_url=formset_url,
                                                 formset_adm=formset_adm,
                                                 formset_unitlevel=formset_unitlevel))
开发者ID:bireme,项目名称:fi-admin,代码行数:59,代码来源:views.py

示例6: get_form_kwargs

    def get_form_kwargs(self):
        kwargs = super(InstUpdate, self).get_form_kwargs()

        user_data = additional_user_info(self.request)

        additional_form_parameters = {}
        additional_form_parameters['user_data'] = user_data

        kwargs.update(additional_form_parameters)

        return kwargs
开发者ID:bireme,项目名称:fi-admin,代码行数:11,代码来源:views.py

示例7: dashboard

def dashboard(request):
    output = {}

    current_user = request.user
    recent_actions = LogEntry.objects.filter(user=current_user)[:20]
    user_data = additional_user_info(request)
    user_roles = ['']
    user_roles.extend([role for role in user_data['service_role'].values()])

    # retrive text blocks
    text_blocks = TextBlock.objects.filter(slot='dashboard', user_profile__in=user_roles).order_by('order')

    output['recent_actions'] = recent_actions
    output['text_blocks'] = text_blocks

    return render_to_response('main/index.html', output, context_instance=RequestContext(request))
开发者ID:wilsonmoura,项目名称:fi-admin,代码行数:16,代码来源:views.py

示例8: delete_error_report

def delete_error_report(request, error_report_id):

    user = request.user
    error_report = get_object_or_404(ErrorReport, id=error_report_id)
    output = {}

    user_data = additional_user_info(request)

    if error_report.created_by_id != user.id:
        return HttpResponse('Unauthorized', status=401)

    error_report.delete()

    output['alert'] = _("Report deleted.")
    output['alerttype'] = "alert-success"

    return render_to_response('error_reporting/list.html', output, context_instance=RequestContext(request))
开发者ID:bireme,项目名称:fi-admin,代码行数:17,代码来源:views.py

示例9: create_event_from_suggestion

def create_event_from_suggestion(request, suggestion_id):

    user = request.user
    suggestion = get_object_or_404(SuggestEvent, id=suggestion_id)
    output = {}

    user_data = additional_user_info(request)

    event = Event(title=suggestion.title, start_date=suggestion.start_date,
        end_date=suggestion.end_date, link=suggestion.link, city=suggestion.city, created_by=request.user)
    event.save();

    suggestion.status = 1
    suggestion.save();

    output['alert'] = _("Event created.")
    output['alerttype'] = "alert-success"

    return redirect('events.views.create_edit_event', event_id=event.id)
开发者ID:bireme,项目名称:fi-admin,代码行数:19,代码来源:views.py

示例10: delete_resource

def delete_resource(request, resource_id):

    user = request.user
    resource = get_object_or_404(Resource, id=resource_id)
    c_type = ContentType.objects.get_for_model(Resource)
    output = {}

    user_data = additional_user_info(request)

    if resource.created_by_id != user.id:
        return HttpResponse('Unauthorized', status=401)

    resource.delete()

    # delete associated data
    Descriptor.objects.filter(object_id=resource_id, content_type=c_type).delete()
    Keyword.objects.filter(object_id=resource_id, content_type=c_type).delete()
    ResourceThematic.objects.filter(object_id=resource_id, content_type=c_type).delete()

    output['alert'] = _("Resource deleted.")
    output['alerttype'] = "alert-success"

    return render_to_response('main/resources.html', output, context_instance=RequestContext(request))
开发者ID:menezesre,项目名称:fi-admin,代码行数:23,代码来源:views.py

示例11: create_resource_from_suggestion

def create_resource_from_suggestion(request, suggestion_id):

    user = request.user
    suggestion = get_object_or_404(SuggestResource, id=suggestion_id)
    output = {}

    user_data = additional_user_info(request)

    resource = Resource(title=suggestion.title, link=suggestion.link,
        abstract=suggestion.abstract, created_by=request.user)
    resource.save();

    for tag in suggestion.keywords.split(','):
            keyword = Keyword(content_object=resource, text=tag.strip(), user_recomendation=True)
            keyword.save()

    suggestion.status = 1
    suggestion.save();

    output['alert'] = _("Resource created.")
    output['alerttype'] = "alert-success"

    return redirect('main.views.create_edit_resource', resource_id=resource.id)
开发者ID:bireme,项目名称:fi-admin,代码行数:23,代码来源:views.py

示例12: create_edit_resource

def create_edit_resource(request, **kwargs):

    resource_id = kwargs.get('resource_id')
    resource = None
    form = None
    form_error_report = None
    formset_descriptor = None
    formset_thematic = None
    formset_keyword  = None
    descriptor_list  = None
    keyword_list     = None
    thematic_list    = None
    valid_for_publication = True
    output = {}

    if resource_id:
        resource = get_object_or_404(Resource, id=resource_id)
    else:
        resource = Resource(created_by=request.user)
        output['is_new'] = True

    user_data = additional_user_info(request)
    user_data['is_owner'] = True if resource.created_by_id == request.user.id else False
    user_role = user_data['service_role'].get('LIS')

    ct = ContentType.objects.get_for_model(resource)

    # save/update
    if request.POST:
        form = ResourceForm(request.POST, request.FILES, instance=resource, user=request.user, user_data=user_data)
        formset_descriptor = DescriptorFormSet(request.POST, instance=resource)
        formset_keyword    = KeywordFormSet(request.POST, instance=resource)
        formset_thematic   = ResourceThematicFormSet(request.POST, instance=resource)

        # run all validation before for display formset errors at form
        form_valid = form.is_valid()
        formset_descriptor_valid = formset_descriptor.is_valid()        
        formset_keyword_valid  = formset_keyword.is_valid()
        formset_thematic_valid = formset_thematic.is_valid()

        # for status = admitted check  if the resource have at least one descriptor and one thematica area
        valid_for_publication = is_valid_for_publication(form, 
            [formset_descriptor, formset_keyword, formset_thematic])

        if (form_valid and formset_descriptor_valid and formset_keyword_valid
                and formset_thematic_valid and valid_for_publication):

            if not resource.id:
                resource = form.save()
            
            formset_descriptor.save()
            formset_keyword.save()
            formset_thematic.save()

            # update solr index
            form.save()
            form.save_m2m()

            output['alert'] = _("Resource successfully edited.")
            output['alerttype'] = "alert-success"

            return redirect('main.views.list_resources')
    # new/edit
    else:
        form = ResourceForm(instance=resource, user_data=user_data)

        form_error_report = ErrorReportForm()

        # if documentalist create a formset with descriptors created by the user
        if user_role == 'doc':
            descriptor_list = Descriptor.objects.filter(object_id=resource.id, content_type=ct).exclude(created_by_id=request.user.id, status=0)
            keyword_list = Keyword.objects.filter(object_id=resource.id, content_type=ct).exclude(created_by_id=request.user.id, status=0)
            thematic_list = ResourceThematic.objects.filter(object_id=resource.id, content_type=ct).exclude(created_by_id=request.user.id, status=0)

            pending_descriptor_from_user = Descriptor.objects.filter(created_by_id=request.user.id, status=0)
            pending_keyword_from_user = Keyword.objects.filter(created_by_id=request.user.id, status=0)
            pending_thematic_from_user = ResourceThematic.objects.filter(created_by_id=request.user.id, status=0)

            formset_descriptor = DescriptorFormSet(instance=resource, queryset=pending_descriptor_from_user)
            formset_keyword  = KeywordFormSet(instance=resource, queryset=pending_keyword_from_user)
            formset_thematic = ResourceThematicFormSet(instance=resource, queryset=pending_thematic_from_user)
        else:
            formset_descriptor = DescriptorFormSet(instance=resource)
            formset_keyword  = KeywordFormSet(instance=resource)            
            formset_thematic = ResourceThematicFormSet(instance=resource)

    output['form'] = form
    output['formset_descriptor'] = formset_descriptor
    output['formset_keyword']  = formset_keyword
    output['formset_thematic'] = formset_thematic
    output['form_error_report'] = form_error_report
    output['valid_for_publication'] = valid_for_publication

    output['content_type'] = ct.id

    output['resource'] = resource
    output['descriptor_list'] = descriptor_list
    output['keyword_list'] = keyword_list
    output['thematic_list'] = thematic_list
    output['settings'] = settings
#.........这里部分代码省略.........
开发者ID:menezesre,项目名称:fi-admin,代码行数:101,代码来源:views.py


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