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

Python shortcuts.render_to_resp函数代码示例

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

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



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

示例1: locations_import_preview

def locations_import_preview(request, id, template_name='locations/import-map-fields.html'):
    """
    This will generate a form based on the uploaded CSV for field mapping.
    A preview will be generated based on the mapping given.
    """
    locport = get_object_or_404(LocationImport, pk=id)

    if request.method == 'POST':
        form = ImportMapForm(request.POST, locport=locport)

        if form.is_valid():
            # Show the user a preview based on the mapping
            cleaned_data = form.cleaned_data
            #file_path = os.path.join(settings.MEDIA_ROOT, locport.get_file().file.name)
            file_path = locport.get_file().file.name
            locations, stats = parse_locs_from_csv(file_path, cleaned_data)

            # return the form to use it for the confirm view
            template_name = 'locations/import-preview.html'
            return render_to_resp(request=request, template_name=template_name, context={
                'locations': locations,
                'stats': stats,
                'locport': locport,
                'form': form,
                'now': datetime.now(),
            })

    else:
        form = ImportMapForm(locport=locport)

    return render_to_resp(request=request, template_name=template_name, context={
        'form': form,
        'locport': locport,
        'now': datetime.now(),
        })
开发者ID:tendenci,项目名称:tendenci,代码行数:35,代码来源:views.py


示例2: view_ticket

def view_ticket(request):
    ticket_req = request.GET.get('ticket', '')
    ticket = False
    email = request.GET.get('email', '')
    error_message = ''

    if ticket_req and email:
        parts = ticket_req.split('-')
        queue = '-'.join(parts[0:-1])
        ticket_id = parts[-1]
        try:
            ticket = Ticket.objects.get(id=ticket_id, queue__slug__iexact=queue, submitter_email__iexact=email)
        except:
            ticket = False
            error_message = _('Invalid ticket ID or e-mail address. Please try again.')

        if ticket:

            if request.user.is_staff:
                redirect_url = reverse('helpdesk_view', args=[ticket_id])
                if 'close' in request.GET:
                    redirect_url += '?close'
                return HttpResponseRedirect(redirect_url)

            if 'close' in request.GET and ticket.status == Ticket.RESOLVED_STATUS:
                from tendenci.apps.helpdesk.views.staff import update_ticket
                # Trick the update_ticket() view into thinking it's being called with
                # a valid POST.
                request.POST = {
                    'new_status': Ticket.CLOSED_STATUS,
                    'public': 1,
                    'title': ticket.title,
                    'comment': _('Submitter accepted resolution and closed ticket'),
                    }
                if ticket.assigned_to:
                    request.POST['owner'] = ticket.assigned_to.id
                request.GET = {}

                return update_ticket(request, ticket_id, public=True)

            # redirect user back to this ticket if possible.
            redirect_url = ''
            if helpdesk_settings.HELPDESK_NAVIGATION_ENABLED:
                redirect_url = reverse('helpdesk_view', args=[ticket_id])

            return render_to_resp(request=request, template_name='helpdesk/public_view_ticket.html',
                context={
                    'ticket': ticket,
                    'helpdesk_settings': helpdesk_settings,
                    'next': redirect_url,
                })

    return render_to_resp(request=request, template_name='helpdesk/public_view_form.html',
        context={
            'ticket': ticket,
            'email': email,
            'error_message': error_message,
            'helpdesk_settings': helpdesk_settings,
        })
开发者ID:tendenci,项目名称:tendenci,代码行数:59,代码来源:public.py


示例3: homepage

def homepage(request):
    if not request.user.is_authenticated and helpdesk_settings.HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT:
        return HttpResponseRedirect(reverse('auth_login') + "?next=" + request.path)

    if (request.user.is_staff or (request.user.is_authenticated and helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE)):
        try:
            if getattr(request.user.usersettings.settings, 'login_view_ticketlist', False):
                return HttpResponseRedirect(reverse('helpdesk_list'))
            else:
                if request.user.is_staff:
                    return HttpResponseRedirect(reverse('helpdesk_dashboard'))
                else:
                    return HttpResponseRedirect(reverse('helpdesk_submit'))
        except UserSettings.DoesNotExist:
            return HttpResponseRedirect(reverse('helpdesk_dashboard'))

    if request.method == 'POST':
        form = PublicTicketForm(request.POST, request.FILES)
        form.fields['queue'].choices = [('', '--------')] + [[q.id, q.title] for q in Queue.objects.filter(allow_public_submission=True)]
        if form.is_valid():
            if text_is_spam(form.cleaned_data['body'], request):
                # This submission is spam. Let's not save it.
                return render_to_resp(request=request, template_name='helpdesk/public_spam.html')
            else:
                ticket = form.save()
                return HttpResponseRedirect('%s?ticket=%s&email=%s'% (
                    reverse('helpdesk_public_view'),
                    ticket.ticket_for_url,
                    requests.utils.quote(ticket.submitter_email))
                    )
    else:
        try:
            queue = Queue.objects.get(slug=request.GET.get('queue', None))
        except Queue.DoesNotExist:
            queue = None
        initial_data = {}
        if queue:
            initial_data['queue'] = queue.id

        if request.user.is_authenticated and request.user.email:
            initial_data['submitter_email'] = request.user.email

        form = PublicTicketForm(initial=initial_data)
        form.fields['queue'].choices = [('', '--------')] + [[q.id, q.title] for q in Queue.objects.filter(allow_public_submission=True)]

    knowledgebase_categories = KBCategory.objects.all()

    return render_to_resp(request=request, template_name='helpdesk/public_homepage.html',
        context={
            'form': form,
            'helpdesk_settings': helpdesk_settings,
            'kb_categories': knowledgebase_categories
        })
开发者ID:tendenci,项目名称:tendenci,代码行数:53,代码来源:public.py


示例4: item

def item(request, item):
    item = get_object_or_404(KBItem, pk=item)
    return render_to_resp(request=request, template_name='helpdesk/kb_item.html',
        context={
            'item': item,
            'helpdesk_settings': helpdesk_settings,
        })
开发者ID:tendenci,项目名称:tendenci,代码行数:7,代码来源:kb.py


示例5: delete

def delete(request, id, template_name="committees/delete.html"):
    committee = get_object_or_404(Committee, pk=id)

    if not has_perm(request.user, 'committees.delete_committee'):
        raise Http403

    if request.method == "POST":
        EventLog.objects.log(instance=committee)
        messages.add_message(request, messages.SUCCESS, 'Successfully deleted %s' % committee)

        # send notification to administrators
        recipients = get_notice_recipients('module', 'committees', 'committeerecipients')
        if recipients:
            if notification:
                extra_context = {
                    'object': committee,
                    'request': request,
                }
                notification.send_emails(recipients, 'committee_deleted', extra_context)

        committee.delete()
        return HttpResponseRedirect(reverse('committees.search'))

    return render_to_resp(request=request, template_name=template_name,
        context={'committee': committee})
开发者ID:tendenci,项目名称:tendenci,代码行数:25,代码来源:views.py


示例6: locations_import_upload

def locations_import_upload(request, template_name='locations/import-upload-file.html'):
    """
    This is the upload view for the location imports.
    This will upload the location import file and then redirect the user
    to the import mapping/preview page of the import file
    """
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():

            locport = LocationImport.objects.create(creator=request.user)
            csv = File.objects.save_files_for_instance(request, locport)[0]
            file_path = str(csv.file.name)
            import_valid, import_errs = is_import_valid(file_path)

            if not import_valid:
                for err in import_errs:
                    messages.add_message(request, messages.ERROR, err)
                locport.delete()
                return redirect('locations_import_upload_file')
            EventLog.objects.log()
            # reset the password_promt session
            del request.session['password_promt']
            return redirect('locations_import_preview', locport.id)
    else:
        form = UploadForm()

    return render_to_resp(request=request, template_name=template_name, context={
            'form': form,
            'now': datetime.now(),
        })
开发者ID:tendenci,项目名称:tendenci,代码行数:31,代码来源:views.py


示例7: user_upload_process

def user_upload_process(request, sid,
                template_name="imports/users_process.html"):
    if not request.user.profile.is_superuser:
        raise Http403   # admin only page

    sid = str(sid)
    import_dict = get_user_import_settings(request, sid)
    if not import_dict:
        return HttpResponseRedirect(reverse('import.user_upload_add'))

    import_dict['folder_name'] = IMPORT_FOLDER_NAME
    import_dict['id'] = sid

    if not default_storage.exists(os.path.join(import_dict['folder_name'],
                                               import_dict['file_name'])):
        return HttpResponseRedirect(reverse('import.user_upload_add'))

    #reset group - delete all members in the group
    if import_dict['clear_group_membership'] and import_dict['group']:
        GroupMembership.objects.filter(group=import_dict['group']).delete()

    d = request.session[sid]
    d.update({
        'is_completed': False,
        'count_insert': 0,
        'count_update': 0,
        'total_done': 0
    })

    request.session[sid] = d
    d = None

    return render_to_resp(request=request, template_name=template_name,
        context=import_dict)
开发者ID:tendenci,项目名称:tendenci,代码行数:34,代码来源:views.py


示例8: directory_export

def directory_export(request, template_name="directories/export.html"):
    """Export Directories"""
    if not request.user.profile.is_superuser:
        raise Http403

    form = DirectoryExportForm(request.POST or None)

    if request.method == "POST" and form.is_valid():
        export_fields = form.cleaned_data['export_fields']
        export_status_detail = form.cleaned_data['export_status_detail']
        identifier = int(time.time())
        temp_file_path = 'export/directories/%s_temp.csv' % identifier
        default_storage.save(temp_file_path, ContentFile(''))

        # start the process
        subprocess.Popen([python_executable(), "manage.py",
                          "directory_export_process",
                          '--export_fields=%s' % export_fields,
                          '--export_status_detail=%s' % export_status_detail,
                          '--identifier=%s' % identifier,
                          '--user=%s' % request.user.id])
        # log an event
        EventLog.objects.log()
        return HttpResponseRedirect(reverse('directory.export_status', args=[identifier]))

    context = {'form': form}
    return render_to_resp(request=request, template_name=template_name, context=context)
开发者ID:tendenci,项目名称:tendenci,代码行数:27,代码来源:views.py


示例9: _export_page

def _export_page(request):
    ctx = {}
    ctx.update(get_app_permissions(request))

    form = None
    if request.method == 'POST':
        form = DatabaseDumpForm(request.POST)
        if form.is_valid():
            print("Form submitted is valid!")
            if can_create_dump():
                new_obj = DatabaseDumpFile()
                new_obj.author = request.user
                new_obj.export_format = form.cleaned_data['format']
                new_obj.save()
                subprocess.Popen([python_executable(), "manage.py",
                              "create_database_dump",
                              str(request.user.pk), form.cleaned_data['format'], str(new_obj.pk) ])
                messages.add_message(request, messages.INFO, "Success! The system is now generating your export file. Please reload in a few seconds to update the list.")
            else:
                messages.add_message(request, messages.ERROR, "Cannot create file. You have already reached the limit of existing dump files. Please delete old unused exports and try again.")
    else:
        form = DatabaseDumpForm()

    # get all active DB Dump Files
    # if current existing DB Dump Files are less than the limit, enable form submission
    db_objs = DatabaseDumpFile.objects.filter(~Q(status='expired'))

    ctx['objects'] = db_objs
    if can_create_dump():
        ctx['enable_form'] = True

    ctx['form'] = form
    return render_to_resp(request=request, template_name="explorer/export_page.html", context=ctx)
开发者ID:tendenci,项目名称:tendenci,代码行数:33,代码来源:views.py


示例10: detail

def detail(request, slug=None, hash=None, template_name="articles/view.html"):
    if not slug and not hash:
        return HttpResponseRedirect(reverse('articles'))

    if hash:
        version = get_object_or_404(Version, hash=hash)
        current_article = get_object_or_404(Article, pk=version.object_id)
        article = version.get_version_object()
        msg_string = 'You are viewing a previous version of this article. View the <a href="%s%s">Current Version</a>.' % (get_setting('site', 'global', 'siteurl'), current_article.get_absolute_url())
        messages.add_message(request, messages.WARNING, _(msg_string))
    else:
        article = get_object_or_404(Article, slug=slug)

    # non-admin can not view the non-active content
    # status=0 has been taken care of in the has_perm function
    if (article.status_detail).lower() != 'active' and (not request.user.profile.is_superuser):
        raise Http403

    if not article.release_dt_local and article.release_dt:
        article.assign_release_dt_local()

    if not article.release_dt_local or article.release_dt_local >= datetime.now():
        if not any([
            has_perm(request.user, 'articles.view_article'),
            request.user == article.owner,
            request.user == article.creator
            ]):
            raise Http403

    if has_view_perm(request.user, 'articles.view_article', article):
        EventLog.objects.log(instance=article)
        return render_to_resp(request=request, template_name=template_name,
            context={'article': article})
    else:
        raise Http403
开发者ID:tendenci,项目名称:tendenci,代码行数:35,代码来源:views.py


示例11: technology

def technology(request, id, template_name="case_studies/search.html"):
    "List of case studies by technology"
    technology = get_object_or_404(Technology, pk=id)
    query = '"technology:%s"' % technology

    case_studies = CaseStudy.objects.search(query, user=request.user)

    EventLog.objects.log()

    return render_to_resp(request=request, template_name=template_name,
        context={'technology':technology, 'case_studies': case_studies})

    EventLog.objects.log()

    return render_to_resp(request=request, template_name=template_name,
        context={'technology':technology, 'case_studies': case_studies})
开发者ID:tendenci,项目名称:tendenci,代码行数:16,代码来源:views.py


示例12: add

def add(request, form_class=ContactForm, template_name="contacts/add.html"):
    if has_perm(request.user,'contacts.add_contact'):

        if request.method == "POST":
            form = form_class(request.POST)
            if form.is_valid():
                contact = form.save(commit=False)
                # set up the user information
                contact.creator = request.user
                contact.creator_username = request.user.username
                contact.owner = request.user
                contact.owner_username = request.user.username
                contact.allow_anonymous_view = False
                contact.save()

                ObjectPermission.objects.assign(contact.creator, contact)

                return HttpResponseRedirect(reverse('contact', args=[contact.pk]))
        else:
            form = form_class()
            print(form_class())

        return render_to_resp(request=request, template_name=template_name,
            context={'form':form})
    else:
        raise Http403
开发者ID:tendenci,项目名称:tendenci,代码行数:26,代码来源:views.py


示例13: export

def export(request, template_name="help_files/export.html"):
    """Export Help Files"""

    if not request.user.is_superuser:
        raise Http403

    if request.method == 'POST':
        # initilize initial values
        fields = [
            'slug',
            'topics',
            'question',
            'answer',
            'level',
            'is_faq',
            'is_featured',
            'is_video',
            'syndicate',
            'view_totals',
        ]
        export_id = run_export_task('help_files', 'helpfile', fields)
        EventLog.objects.log()
        return redirect('export.status', export_id)

    return render_to_resp(request=request, template_name=template_name, context={
    })
开发者ID:tendenci,项目名称:tendenci,代码行数:26,代码来源:views.py


示例14: api

def api(request, method):
    """
    Regardless of any other paramaters, we provide a help screen
    to the user if they requested one.

    If the user isn't looking for help, then we enforce a few conditions:
        * The request must be sent via HTTP POST
        * The request must contain a 'user' and 'password' which
          must be valid users
        * The method must match one of the public methods of the API class.

    """

    if method == 'help':
        return render_to_resp(request=request, template_name='helpdesk/help_api.html')

    if request.method != 'POST':
        return api_return(STATUS_ERROR_BADMETHOD)

    # TODO: Move away from having the username & password in every request.
    request.user = authenticate(
        request=request,
        username=request.POST.get('user', False),
        password=request.POST.get('password'),
        )

    if request.user is None:
        return api_return(STATUS_ERROR_PERMISSIONS)

    api = API(request)
    if hasattr(api, 'api_public_%s' % method):
        return getattr(api, 'api_public_%s' % method)()

    return api_return(STATUS_ERROR)
开发者ID:tendenci,项目名称:tendenci,代码行数:34,代码来源:api.py


示例15: edit_meta

def edit_meta(request, id, form_class=MetaForm, template_name="directories/edit-meta.html"):
    directory = get_object_or_404(Directory, pk=id)

    if not has_perm(request.user, 'directories.change_directory', directory):
        raise Http403

    defaults = {
        'title': directory.get_title(),
        'description': directory.get_description(),
        'keywords': directory.get_keywords(),
        'canonical_url': directory.get_canonical_url(),
    }
    directory.meta = MetaTags(**defaults)

    if request.method == "POST":
        form = form_class(request.POST, instance=directory.meta)
        if form.is_valid():
            directory.meta = form.save() # save meta
            directory.save() # save relationship
            msg_string = 'Successfully updated meta for %s' % directory
            messages.add_message(request, messages.SUCCESS, _(msg_string))

            return HttpResponseRedirect(reverse('directory', args=[directory.slug]))
    else:
        form = form_class(instance=directory.meta)

    return render_to_resp(request=request, template_name=template_name,
        context={'directory': directory, 'form':form})
开发者ID:tendenci,项目名称:tendenci,代码行数:28,代码来源:views.py


示例16: campaign_delete

def campaign_delete(request, campaign_id, template_name="campaign_monitor/campaigns/delete.html"):
    campaign = get_object_or_404(Campaign, campaign_id=campaign_id)

    if not has_perm(request.user,'campaign_monitor.delete_campaign'):
        raise Http403

    if request.method == "POST":

        try:
            CSC(auth=auth, campaign_id=campaign.campaign_id).delete()
        except BadRequest as e:
            msg_string = 'Bad Request %s: %s' % (e.data.Code, e.data.Message)
            messages.add_message(request, messages.ERROR, _(msg_string))
            return redirect(campaign)
        except Exception as e:
            msg_string = 'Error: %s' % e
            messages.add_message(request, messages.ERROR, _(msg_string))
            return redirect(campaign)

        campaign.delete()
        messages.add_message(request, messages.SUCCESS, _('Successfully deleted campaign.'))
        return redirect("campaign_monitor.campaign_index")

    return render_to_resp(request=request, template_name=template_name,
            context={'campaign': campaign})
开发者ID:tendenci,项目名称:tendenci,代码行数:25,代码来源:views.py


示例17: change_language

def change_language(request):
    return_to = ''
    if 'return_to' in request.GET:
        return_to = request.GET['return_to']

    return render_to_resp(request=request, template_name='helpdesk/public_change_language.html',
        context={'next': return_to})
开发者ID:tendenci,项目名称:tendenci,代码行数:7,代码来源:public.py


示例18: view

def view(request, id, template_name="emails/view.html"):
    email = get_object_or_404(Email, pk=id)

    if not email.allow_view_by(request.user): raise Http403

    return render_to_resp(request=request, template_name=template_name,
        context={'email':email})
开发者ID:tendenci,项目名称:tendenci,代码行数:7,代码来源:views.py


示例19: add

def add(request, form_class=FormForm, template_name="forms/add.html"):
    if not has_perm(request.user,'forms.add_form'):
        raise Http403

    PricingFormSet = inlineformset_factory(Form, Pricing, form=PricingForm, extra=2, can_delete=False)

    formset = PricingFormSet()
    if request.method == "POST":
        form = form_class(request.POST, user=request.user)
        if form.is_valid():
            form_instance = form.save(commit=False)
            # save form and associated pricings
            form_instance = update_perms_and_save(request, form, form_instance)
            formset = PricingFormSet(request.POST, instance=form_instance)
            if formset.is_valid():
                # update_perms_and_save does not appear to consider ManyToManyFields
                for method in form.cleaned_data['payment_methods']:
                    form_instance.payment_methods.add(method)

                formset.save()

                messages.add_message(request, messages.SUCCESS, _('Successfully added %(f)s' % {'f':form_instance}))
                return HttpResponseRedirect(reverse('form_field_update', args=[form_instance.pk]))
    else:
        form = form_class(user=request.user)

    return render_to_resp(request=request, template_name=template_name, context={
        'form':form,
        'formset': formset,
    })
开发者ID:tendenci,项目名称:tendenci,代码行数:30,代码来源:views.py


示例20: nearest

def nearest(request, template_name="locations/nearest.html"):
    locations = []
    lat, lng = None, None
    query = request.GET.get('q')
    filters = get_query_filters(request.user, 'locations.view_location')

    if query:
        lat, lng = get_coordinates(address=query)

    all_locations = Location.objects.filter(filters).distinct()
    if not request.user.is_anonymous:
        all_locations = all_locations.select_related()

    if all((lat,lng)):
        for location in all_locations:
            location.distance = location.get_distance2(lat, lng)
            if location.distance is not None:
                locations.append(location)
            locations.sort(key=lambda x: x.distance)

    EventLog.objects.log()

    return render_to_resp(request=request, template_name=template_name, context={
        'locations':locations,
        'origin': {'lat':lat,'lng':lng},
        })
开发者ID:tendenci,项目名称:tendenci,代码行数:26,代码来源:views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python shortcuts.render_to_response函数代码示例发布时间:2022-05-27
下一篇:
Python utils.get_setting函数代码示例发布时间: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