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

Python sphutils.sph_reverse函数代码示例

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

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



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

示例1: render

 def render(self, context):
     from django.core.urlresolvers import reverse, NoReverseMatch
     args = [arg.resolve(context) for arg in self.args]
     kwargs = dict([(smart_str(k,'ascii'), v.resolve(context))
                    for k, v in self.kwargs.items()])
     
     url = ''
     try:
         url = sph_reverse(self.view_name,
                           args=args, kwargs=kwargs)
     except NoReverseMatch, e:
         if settings.SETTINGS_MODULE:
             project_name = settings.SETTINGS_MODULE.split('.')[0]
             try:
                 url = sph_reverse(project_name + '.' + self.view_name,
                                    args=args, kwargs=kwargs)
             except NoReverseMatch:
                 if self.asvar is None:
                     # Re-raise the original exception, not the one with
                     # the path relative to the project. This makes a
                     # better error message.
                     raise e
         else:
             if self.asvar is None:
                 raise e
开发者ID:pigletto,项目名称:sct-communitytools,代码行数:25,代码来源:sph_extras.py


示例2: catchup

def catchup(request, group, category_id):
    if category_id == '0':
        ThreadLastVisit.objects.filter(user = request.user).delete() 
        CategoryLastVisit.objects.filter(user = request.user).update(lastvisit = datetime.today(), oldlastvisit = None)
        req = HttpResponseRedirect(sph_reverse('sphboard-index'))
    else:
        category = get_object_or_404(Category, pk = category_id )
        category.catchup(request.session, request.user)
        req = HttpResponseRedirect( sph_reverse('sphene.sphboard.views.showCategory' , kwargs = {'category_id': category_id } ) )

    req.sph_lastmodified = True
    return req
开发者ID:eviljoel,项目名称:BARcamp-Chicago-Website,代码行数:12,代码来源:views.py


示例3: test_move_cat1_p2_to_cat2

    def test_move_cat1_p2_to_cat2(self):
        """
             Test moving post p2 from category cat1 directly into category cat2.

             Expected output is to have new thread (created from post p2) in category cat2.
             Thread cat1_p1 in category c1 will have less posts now
        """
        mv1url = self.cat1_p2.get_absolute_moveposturl()
        self.assertEqual(mv1url, sph_reverse('move_post_1', kwargs={'post_id':self.cat1_p2.pk}))

        # check first step
        response = self.client.get(mv1url, {})
        self.assertEqual(response.status_code, 200)

        # check second step (category is selected)
        mv2url = sph_reverse('move_post_2', kwargs={'post_id':self.cat1_p2.pk,
                                                    'category_id':self.cat2.pk})
        response = self.client.get(mv2url, {})
        self.assertEqual(response.status_code, 200)

        # check step 3 (with GET) - annotation form for post moved into category
        mv3url = sph_reverse('move_post_3', kwargs={'post_id':self.cat1_p2.pk,
                                                        'category_id':self.cat2.pk})
        response = self.client.get(mv3url, {})
        self.assertEqual(response.status_code, 200)

        # submit annotation form and move the post!
        self.assertEqual(self.cat2.threadCount(), 1)
        response = self.client.post(mv3url, {'body':'test body'})
        self.assertEqual(response.status_code, 302)

        # get fresh instance of moved post
        p2 = Post.objects.get(pk=self.cat1_p2.pk)

        # check if success message was created
        self.assertEqual(self.superuser.message_set.count(), 1)
        # check if new thread exists in category cat2
        self.assertEqual(self.cat2.threadCount(), 2)
        # check if post p2 was removed form thread p1
        self.assertEqual(self.cat1_p1.postCount(), 2)
        # check if post p2 is now new thread in category cat2
        self.assertEqual(p2.get_thread(), p2)
        # check if ThreadInformation for post p1 was updated
        ti = self.cat1_p1.get_threadinformation()
        self.assertEqual(ti.post_count, 2)
        # check if number of ThreadInformation objects has been changed
        self.assertEqual(ThreadInformation.objects.all().count(), 3)
        # check ThreadInformation for new thread
        ti2 = p2.get_threadinformation()
        self.assertEqual(ti2.post_count, 1)
开发者ID:hmm,项目名称:sct-communitytools,代码行数:50,代码来源:tests.py


示例4: profile

def profile(request, group, user_id):
    user = get_object_or_404(User, pk = user_id)
    has_edit_permission = False
    profile_edit_url = None

    requester = request.user
    
    if user == requester or \
        (requester and requester.is_authenticated() and requester.is_superuser):
        has_edit_permission = True
        profile_edit_url = sph_reverse( 'sphene.community.views.profile_edit', (), { 'user_id': user.id, })

    ret = profile_display.send(None, request = request,
                               user = user, )

    additionalprofile = ''
    blocks = list()
    for listener in ret:
        if listener[1]:
            response = listener[1]

            if isinstance( response, dict ):
                blocks.append(response['block'])
                response = response['additionalprofile']

            additionalprofile += response
    
    return render_to_response( 'sphene/community/profile.html',
                               { 'profile_user': user,
                                 'profile_blocks': blocks,
                                 'has_edit_permission': has_edit_permission,
                                 'profile_edit_url': profile_edit_url,
                                 'additionalprofile': mark_safe( additionalprofile ),
                                 },
                               context_instance = RequestContext( request ))
开发者ID:hmm,项目名称:sct-communitytools,代码行数:35,代码来源:views.py


示例5: admin_post_delete

def admin_post_delete(request, group, user_id, post_id):
    post = get_object_or_404(Post, author=user_id, pk=post_id)
    if not post.allow_hiding():
        raise PermissionDenied()
    post.hide()
    messages.success(request,  message = ugettext(u'Post deleted') )
    return HttpResponseRedirect(sph_reverse('sphboard_admin_user_posts' , kwargs = {'user_id': user_id } ))
开发者ID:hmm,项目名称:sct-communitytools,代码行数:7,代码来源:views.py


示例6: toggle_monitor

def toggle_monitor(request, group, monitortype, object_id, monitor_user_id=None):
    if not request.user.is_authenticated():
        raise PermissionDenied()
    obj = None
    if monitortype == 'group':
        obj = group
        object_id = 0
    elif monitortype == 'category':
        obj = Category.objects.get( pk = object_id )
    elif monitortype == 'thread':
        obj = Post.objects.get( pk = object_id )

    new_monitor = None
    if monitor_user_id:
        monitor_user = User.objects.get(pk=monitor_user_id)
        new_monitor = obj.toggle_monitor(user=monitor_user)
    else:
        new_monitor = obj.toggle_monitor()

    if new_monitor:
        messages.success(request,  message = ugettext(u'Successfully created email notification monitor.') )
    else:
        messages.success(request,  message = ugettext(u'Removed email notification monitor.') )

    if 'next' in request.GET:
        return HttpResponseRedirect( request.GET['next'] )
    if monitortype == 'group':
        return HttpResponseRedirect(sph_reverse('sphboard-index'))
    return HttpResponseRedirect(obj.get_absolute_url())
开发者ID:hmm,项目名称:sct-communitytools,代码行数:29,代码来源:views.py


示例7: inner

    def inner(*args, **kwargs):
        from sphene.community.sphutils import sph_reverse
        # Find urlconf ...
        bits = func(*args, **kwargs)
        viewname, args, kwargs = bits

        return sph_reverse(viewname, args=args, kwargs=kwargs)
开发者ID:ShaastraWebops,项目名称:Shaastra-2011-Website,代码行数:7,代码来源:sphpermalink.py


示例8: save_post

    def save_post(self, newpost, data):
        super(BlogCategoryType, self).save_post(newpost, data)
        if newpost.thread is not None:
            return
        try:
            ext = newpost.blogpostextension_set.get()
        except BlogPostExtension.DoesNotExist:
            ext = BlogPostExtension( post = newpost, )


        ext.slug = data['slug']
        ext.status = data['status']
        ext.save()

        tag_set_labels( newpost, data['tags'] )

        if newpost.is_new_post:
            try:
                config = BlogCategoryConfig.objects.get( \
                    category = self.category)

                if config.enable_googleblogping:
                    # If enabled, ping google blogsearch.
                    import urllib
                    url = self.category.group.get_baseurl()
                    blog_feed_url = sph_reverse('sphblog-feeds', urlconf=get_current_urlconf(), kwargs = { 'category_id': self.category.id })
                    pingurl = 'http://blogsearch.google.com/ping?%s' % \
                        urllib.urlencode( \
                        { 'name': self.category.name,
                          'url': ''.join((url, self.category.get_absolute_url()),),
                          'changesURL': ''.join((url, blog_feed_url),) } )
                    urllib.urlopen( pingurl )

            except BlogCategoryConfig.DoesNotExist:
                pass
开发者ID:hpoul,项目名称:sct-communitytools,代码行数:35,代码来源:categorytypes.py


示例9: edit_poll

def edit_poll(request, group, poll_id):
    poll = get_object_or_404(Poll, pk = poll_id)
    if not poll.allow_editing():
        raise PermissionDenied()

    postdata = None
    if request.method == 'POST':
        postdata = request.POST

    form = PollForm(postdata, instance = poll)
    choiceforms = [ PollChoiceForm( postdata,
                                    prefix = 'choice_%d' % choice.id,
                                    instance = choice,
                                    ) for choice in poll.pollchoice_set.all() ]

    if request.method == 'POST' and form.is_valid() \
            and not [ True for choiceform in choiceforms if not choiceform.is_valid() ]:
        form.save()
        for choiceform in choiceforms:
            choiceform.save()

        return HttpResponseRedirect(sph_reverse('sphene.sphboard.views.showThread',
                                                kwargs = { 'thread_id': poll.post.get_thread().id }))

    return sph_render_to_response('sphene/sphboard/edit_poll.html',
                                  { 'form': form,
                                    'choiceforms': choiceforms,
                                    })
开发者ID:sunilpatelmca,项目名称:dishnine,代码行数:28,代码来源:views.py


示例10: sph_publicemailaddress

def sph_publicemailaddress(value):
    if get_sph_setting('community_email_anonymous_require_captcha'):
        # as a security constraint we don't return the public email
        # address if the user is not logged in.
        if not get_current_user().is_authenticated:
            validated = get_current_request().session.get('sph_email_captcha_validated', 0)

            # if the timeout is reached or the captcha was never entered
            # provide a link for the user to enter the captcha.
            if validated < time() - get_sph_setting('community_email_anonymous_require_captcha_timeout'):
                return mark_safe('<a href="%s">%s</a>' % (
                sph_reverse('sph_reveal_emailaddress', kwargs={'user_id': value.id, }), _('Reveal this emailaddress')))

    if get_sph_setting('community_email_show_only_public'):
        try:
            return CommunityUserProfile.objects.get(user=value, ).public_emailaddress
        except CommunityUserProfile.DoesNotExist:
            pass
        return ''

    try:
        profile = CommunityUserProfile.objects.get(user=value, )
    except CommunityUserProfile.DoesNotExist:
        return "n/a"  # value.email
    return profile.public_emailaddress or value.email
开发者ID:hpoul,项目名称:sct-communitytools,代码行数:25,代码来源:sph_extras.py


示例11: render

    def render(self, context):
        from django.urls import reverse, NoReverseMatch
        args = [arg.resolve(context) for arg in self.args]
        kwargs = {k: v.resolve(context) for k, v in self.kwargs.items()}
        view_name = self.view_name.resolve(context)
        if view_name == '':
            log.error('Error while resolving sph_url2 for %r / %s', self.view_name, self.view_name)
            return ''

        try:
            current_app = context.request.current_app
        except AttributeError:
            try:
                current_app = context.request.resolver_match.namespace
            except AttributeError:
                current_app = None
        # Try to look up the URL. If it fails, raise NoReverseMatch unless the
        # {% url ... as var %} construct is used, in which case return nothing.
        url = ''
        try:
            url = sph_reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
        except NoReverseMatch:
            if self.asvar is None:
                raise

        if self.asvar:
            context[self.asvar] = url
            return ''
        else:
            if context.autoescape:
                url = conditional_escape(url)
            return url
开发者ID:hpoul,项目名称:sct-communitytools,代码行数:32,代码来源:sph_extras.py


示例12: edit_poll

def edit_poll(request, group, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    if not poll.allow_editing():
        raise PermissionDenied()

    postdata = None
    if request.method == "POST":
        postdata = request.POST

    form = PollForm(postdata, instance=poll)
    choiceforms = [
        PollChoiceForm(postdata, prefix="choice_%d" % choice.id, instance=choice)
        for choice in poll.pollchoice_set.all()
    ]

    if (
        request.method == "POST"
        and form.is_valid()
        and not [True for choiceform in choiceforms if not choiceform.is_valid()]
    ):
        form.save()
        for choiceform in choiceforms:
            choiceform.save()

        return HttpResponseRedirect(
            sph_reverse("sphene.sphboard.views.showThread", kwargs={"thread_id": poll.post.get_thread().id})
        )

    return sph_render_to_response("sphene/sphboard/edit_poll.html", {"form": form, "choiceforms": choiceforms})
开发者ID:ShaastraWebops,项目名称:Shaastra-2011-Website,代码行数:29,代码来源:views.py


示例13: get_absolute_url_for_category

 def get_absolute_url_for_category(self):
     try:
         blog_url = sph_reverse('sphblog_category_index', kwargs = { 'category_id': self.category.id })
         return blog_url
     except Exception, e:
         #print "err.. argl %s" % str(e)
         return None
开发者ID:ShaastraWebops,项目名称:Shaastra-2011-Website,代码行数:7,代码来源:categorytypes.py


示例14: test_move_cat1_p1_to_cat2_p1

    def test_move_cat1_p1_to_cat2_p1(self):
        """
             Test moving post cat1_p1 (root post of thread!) from thread cat1_p1 into thread cat2_p1.

             Expected output is to have thread cat2_p1 updated and containing 2 posts.
             Thread cat1_p1 should be updated too as it now contains only 2 posts
        """
        mv3url = sph_reverse('move_post_3', kwargs={'post_id':self.cat1_p1.pk,
                                                    'category_id':self.cat1.pk,
                                                    'thread_id':self.cat2_p1.pk})
        # submit annotation form and move the post!
        self.assertEqual(self.cat1.threadCount(), 1)
        response = self.client.post(mv3url, {'body':'test body'})
        self.assertEqual(response.status_code, 302)

        # get fresh instances of posts
        cat1_p1 = Post.objects.get(pk=self.cat1_p1.pk)
        cat1_p2 = Post.objects.get(pk=self.cat1_p2.pk)
        cat2_p1 = Post.objects.get(pk=self.cat2_p1.pk)

        # check if success message was created
        self.assertEqual(self.superuser.message_set.count(), 1)
        # check if thread cat2_p1 was updated
        ti = cat2_p1.get_threadinformation()
        self.assertEqual(ti.post_count, 2)
        # check if ThreadInformation for post p2 was created properly
        ti = cat1_p2.get_threadinformation()
        self.assertEqual(ti.post_count, 2)
        self.assertEqual(ti.category, self.cat1)
        # check if post cat1_p1 is now in thread cat2_p1
        self.assertEqual(cat1_p1.get_thread(), cat2_p1)
        # check if post cat1_p1 was added at the end of thread
        self.assertEqual(cat2_p1.get_latest_post(), cat1_p1)
开发者ID:hmm,项目名称:sct-communitytools,代码行数:33,代码来源:tests.py


示例15: test_move_cat2_p1_to_cat1

    def test_move_cat2_p1_to_cat1(self):
        """
             Test moving post p1 from category cat2 directly into category cat1.

             Expected output is to have new thread (created from post cat2_p1) in category c1.
             Old ThreadInformation object from cat2 should be removed.
        """
        mv3url = sph_reverse('move_post_3', kwargs={'post_id':self.cat2_p1.pk,
                                                    'category_id':self.cat1.pk})
        # submit annotation form and move the post!
        self.assertEqual(self.cat1.threadCount(), 1)
        response = self.client.post(mv3url, {'body':'test body'})
        self.assertEqual(response.status_code, 302)

        # get fresh instances of posts
        cat2_p1 = Post.objects.get(pk=self.cat2_p1.pk)

        # check if success message was created
        self.assertEqual(self.superuser.message_set.count(), 1)
        # check if new thread exists in cat1
        self.assertEqual(self.cat1.threadCount(), 2)
        # check if no threads left in cat2
        self.assertEqual(self.cat2.threadCount(), 0)
        # check if post cat2_p1 is thread
        self.assertEqual(cat2_p1.get_thread(), cat2_p1)
        # check if ThreadInformation for post cat2_p1 was created properly
        ti = cat2_p1.get_threadinformation()
        self.assertEqual(ti.post_count, 1)
        self.assertEqual(ti.category, self.cat1)
开发者ID:hmm,项目名称:sct-communitytools,代码行数:29,代码来源:tests.py


示例16: test_move_cat1_p1_to_cat2

    def test_move_cat1_p1_to_cat2(self):
        """
             Test moving post p1 (root post of thread!) from category cat1 directly
             into category cat2.

             Expected output is to have new thread (created from post p1) in category cat2
             and new thread in category cat1 created from second post in former p1 thread.
             Old ThreadInformation object for thread p1 should be removed.
             Two new ThreadInformation objects will be crated
        """
        mv3url = sph_reverse('move_post_3', kwargs={'post_id':self.cat1_p1.pk,
                                                    'category_id':self.cat2.pk})
        # submit annotation form and move the post!
        self.assertEqual(self.cat2.threadCount(), 1)
        response = self.client.post(mv3url, {'body':'test body'})
        self.assertEqual(response.status_code, 302)

        # get fresh instances of posts
        p1 = Post.objects.get(pk=self.cat1_p1.pk)
        p2 = Post.objects.get(pk=self.cat1_p2.pk)

        # check if success message was created
        self.assertEqual(self.superuser.message_set.count(), 1)
        # check if new thread exists in category cat2
        self.assertEqual(self.cat2.threadCount(), 2)
        # check if post p2 is now thread
        
        self.assertEqual(p2.get_thread(), p2)
        # check if post p1 is now new thread in category cat2
        self.assertEqual(p1.get_thread(), p1)
        # check if ThreadInformation for post p2 was created properly
        ti = p2.get_threadinformation()
        self.assertEqual(ti.post_count, 2)
        # check if number of ThreadInformation objects has been changed
        self.assertEqual(ThreadInformation.objects.all().count(), 3)
开发者ID:hmm,项目名称:sct-communitytools,代码行数:35,代码来源:tests.py


示例17: sph_url

def sph_url(view):
    req = get_current_request()
    urlconf = getattr(req, 'urlconf', None)
    try:
        return sph_reverse(view)
    except:
        log.exception('Unable to reverse sph_url for view %r' % view)
        return 'NOT FOUND'
开发者ID:pigletto,项目名称:sct-communitytools,代码行数:8,代码来源:sph_extras.py


示例18: register

def register(request, group = None, frm = None, register_template_name = 'sphene/community/register.html', email_sent_template_name = 'sphene/community/register_emailsent.html'):

    if request.method == 'POST':
        form = RegisterEmailAddress(request.POST)
        if form.is_valid():
            regdata = form.cleaned_data
            email_address = regdata['email_address']
            if not group:
                subject = _(u'Email verification required')
            else:
                subject = _(u'Email verification required for site %(site_name)s') % {'site_name': group.get_name()}
            validationcode = cryptString( settings.SECRET_KEY, email_address )
	    if frm:
		mail_context_path = sph_reverse( 'sphene.community.views.register_hash', (), { 'emailHash': validationcode, } ).split('community')[1]
	    else:
		mail_context_path = sph_reverse( 'sphene.community.views.register_hash', (), { 'emailHash': validationcode, } )
	    
            mail_context = RequestContext(request,
                                          {
                    'email': email_address,
                    'baseurl': group.baseurl,
                    'path': mail_context_path,
                    'validationcode': validationcode,
                    'group': group,
                    })
            text_part = loader.get_template('sphene/community/accounts/account_verification_email.txt') \
                .render(mail_context)
            html_part = loader.get_template('sphene/community/accounts/account_verification_email.html') \
                .render(mail_context)

            msg = EmailMultiAlternatives(subject, text_part, None, [email_address])
            msg.attach_alternative(html_part, "text/html")
            msg.send()

            return render_to_response( email_sent_template_name,
                                       { 'email': email_address,
                                         },
                                       context_instance = RequestContext(request) )
        pass
    else:
        form = RegisterEmailAddress()

    return render_to_response( register_template_name,
                               { 'form': form },
                               context_instance = RequestContext(request) )
开发者ID:sunilpatelmca,项目名称:dishnine,代码行数:45,代码来源:views.py


示例19: admin_posts_delete

def admin_posts_delete(request, group, user_id):
    posts = Post.objects.filter(author=user_id)
    if posts:
        if not posts[0].allow_hiding():
            raise PermissionDenied()
        for post in posts:
            post.hide()
        messages.success(request,  message = ugettext(u'All posts deleted') )
    else:
        messages.success(request,  message = ugettext(u'No posts to delete') )
    return HttpResponseRedirect(sph_reverse('sphboard_admin_user_posts' , kwargs = {'user_id': user_id } ))
开发者ID:hmm,项目名称:sct-communitytools,代码行数:11,代码来源:views.py


示例20: admin_permission_rolegroup_list

def admin_permission_rolegroup_list(request, group):
    if request.method == 'POST':
        name = request.POST['name']
        if name:
            RoleGroup(group = group,
                      name = name).save()
            return HttpResponseRedirect(sph_reverse('community_admin_permission_rolegroup_list'))
    rolegroups = RoleGroup.objects.filter( group = group )
    return render_to_response( 'sphene/community/admin/permission/rolegroup_list.html',
                               { 'rolegroups': rolegroups, },
                               context_instance = RequestContext(request) )
开发者ID:sunilpatelmca,项目名称:dishnine,代码行数:11,代码来源:views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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