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


Python strings.slugify函数代码示例

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


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

示例1: sync

 def sync(self):
     # Counters
     self.replies = self.post_set.filter(moderated=False).count() - 1
     if self.replies < 0:
         self.replies = 0
     self.replies_reported = self.post_set.filter(reported=True).count()
     self.replies_moderated = self.post_set.filter(moderated=True).count()
     self.replies_deleted = self.post_set.filter(deleted=True).count()
     # First post
     start_post = self.post_set.order_by('id')[0:][0]
     self.start = start_post.date
     self.start_post = start_post
     self.start_poster = start_post.user
     self.start_poster_name = start_post.user_name
     self.start_poster_slug = slugify(start_post.user_name)
     self.start_poster_style = start_post.user.rank.style if start_post.user and start_post.user.rank else ''
     self.upvotes = start_post.upvotes
     self.downvotes = start_post.downvotes
     # Last visible post
     if self.replies > 0:
         last_post = self.post_set.order_by('-id').filter(moderated=False)[0:][0]
     else:
         last_post = start_post
     self.last = last_post.date
     self.last_post = last_post
     self.last_poster = last_post.user
     self.last_poster_name = last_post.user_name
     self.last_poster_slug = slugify(last_post.user_name)
     self.last_poster_style = last_post.user.rank.style if last_post.user and last_post.user.rank else ''
     # Flags
     self.moderated = start_post.moderated
     self.deleted = start_post.deleted
开发者ID:dopestz,项目名称:Misago-1,代码行数:32,代码来源:threadmodel.py

示例2: make_jump

 def make_jump(self):
     username = slugify(self.request.POST.get('username', '').strip())
     if not username:
         messages.error(self.request, _('You have to enter name of user you want to invite to thread.'), 'threads')
         return self.retreat_redirect()
     try:
         user = User.objects.get(username_slug=username)
         acl = user.acl()
         if user in self.thread.participants.all():
             if user.pk == self.request.user.pk:
                 messages.error(self.request, _('You cannot add yourself to this thread.'), 'threads')
             else:
                 messages.info(self.request, _('%(user)s is already participating in this thread.') % {'user': user.username}, 'threads')
         elif not acl.private_threads.can_participate():
             messages.info(self.request, _('%(user)s cannot participate in private threads.') % {'user': user.username}, 'threads')
         elif (not self.request.acl.private_threads.can_invite_ignoring() and
                 not user.allow_pd_invite(self.request.user)):
             messages.info(self.request, _('%(user)s restricts who can invite him to private threads.') % {'user': user.username}, 'threads')
         else:
             self.thread.participants.add(user)
             user.sync_pds = True
             user.save(force_update=True)
             user.email_user(self.request, 'private_thread_invite', _("You've been invited to private thread \"%(thread)s\" by %(user)s") % {'thread': self.thread.name, 'user': self.request.user.username}, {'author': self.request.user, 'thread': self.thread})
             self.thread.set_checkpoint(self.request, 'invited', user)
             messages.success(self.request, _('%(user)s has been added to this thread.') % {'user': user.username}, 'threads')
     except User.DoesNotExist:
         messages.error(self.request, _('User with requested username could not be found.'), 'threads')
     return self.retreat_redirect()
开发者ID:FaceHunter,项目名称:Misago,代码行数:28,代码来源:jumps.py

示例3: clean_invite_users

 def clean_invite_users(self):
     self.users_list = []
     usernames = []
     slugs = [self.request.user.username_slug]
     for username in self.cleaned_data["invite_users"].split(","):
         username = username.strip()
         slug = slugify(username)
         if len(slug) >= 3 and not slug in slugs:
             slugs.append(slug)
             usernames.append(username)
             try:
                 user = User.objects.get(username_slug=slug)
                 if not user.acl(self.request).private_threads.can_participate():
                     raise forms.ValidationError(
                         _("%(user)s cannot participate in private threads.") % {"user": user.username}
                     )
                 if not self.request.acl.private_threads.can_invite_ignoring() and not user.allow_pd_invite(
                     self.request.user
                 ):
                     raise forms.ValidationError(
                         _("%(user)s restricts who can invite him to private threads.") % {"user": user.username}
                     )
                 self.users_list.append(user)
             except User.DoesNotExist:
                 raise forms.ValidationError(_('User "%(username)s" could not be found.') % {"username": username})
         if len(usernames) > 8:
             raise forms.ValidationError(
                 _(
                     "You cannot invite more than 8 members at single time. Post thread and then invite additional members."
                 )
             )
     return ", ".join(usernames)
开发者ID:pzduniak,项目名称:Misago,代码行数:32,代码来源:forms.py

示例4: clean_search_author

 def clean_search_author(self):
     data = self.cleaned_data['search_author']
     if data:
         slug = slugify(data)
         if len(slug) < 3:
             raise forms.ValidationError(_("Author name has to contain at least 3 alpha-numerical characters."))
     return data
开发者ID:0x1330,项目名称:Misago,代码行数:7,代码来源:forms.py

示例5: submit_form

    def submit_form(self, form, target):
        target.name = form.cleaned_data['name']
        target.slug = slugify(form.cleaned_data['name'])
        target.set_description(form.cleaned_data['description'])
        if target.type == 'redirect':
            target.redirect = form.cleaned_data['redirect']
        else:
            target.attrs = form.cleaned_data['attrs']
            target.show_details = form.cleaned_data['show_details']
            target.style = form.cleaned_data['style']
            target.closed = form.cleaned_data['closed']

        if target.type == 'forum':
            target.prune_start = form.cleaned_data['prune_start']
            target.prune_last = form.cleaned_data['prune_last']
            target.pruned_archive = form.cleaned_data['pruned_archive']

        if form.cleaned_data['parent'].pk != target.parent.pk:
            target.move_to(form.cleaned_data['parent'], 'last-child')
            self.request.monitor.increase('acl_version')

        target.save(force_update=True)
        Forum.objects.populate_tree(True)

        if form.cleaned_data['perms']:
            target.copy_permissions(form.cleaned_data['perms'])

        if form.cleaned_data['parent'].pk != target.parent.pk or form.cleaned_data['perms']:
            self.request.monitor.increase('acl_version')

        if self.original_name != target.name:
            target.sync_name()

        return target, Message(_('Changes in forum "%(name)s" have been saved.') % {'name': self.original_name}, 'success')
开发者ID:finid,项目名称:Misago,代码行数:34,代码来源:views.py

示例6: dispatch

    def dispatch(self, request, **kwargs):
        if ((not self.change.thread_name_old or self.thread.name == self.change.thread_name_old)
            and (self.change.post_content == self.post.post)):
            messages.error(request, _("No changes to revert."), 'changelog')
            return redirect(reverse('%s_changelog_diff' % self.type_prefix, kwargs={'thread': self.thread.pk, 'slug': self.thread.slug, 'post': self.post.pk, 'change': self.change.pk}))
        
        self.post.edits += 1
        self.post.edit_user = self.request.user
        self.post.edit_user_name = self.request.user.username
        self.post.edit_user_slug = self.request.user.username_slug
        
        self.post.change_set.create(
                                    forum=self.forum,
                                    thread=self.thread,
                                    post=self.post,
                                    user=request.user,
                                    user_name=request.user.username,
                                    user_slug=request.user.username_slug,
                                    date=timezone.now(),
                                    ip=request.session.get_ip(self.request),
                                    agent=request.META.get('HTTP_USER_AGENT'),
                                    reason=_("Reverted to the state before %(date)s.") % {'date': reldate(self.change.date).lower()},
                                    size=len(self.change.post_content),
                                    change=len(self.change.post_content) - len(self.post.post),
                                    thread_name_old=self.thread.name if self.change.thread_name_old != self.thread.name and self.change.thread_name_old != None else None,
                                    thread_name_new=self.change.thread_name_old if self.change.thread_name_old != self.thread.name else None,
                                    post_content=self.post.post,
                                    )

        if self.change.thread_name_old and self.change.thread_name_old != self.thread.name:
            self.thread.name = self.change.thread_name_old
            self.thread.slug = slugify(self.change.thread_name_old)
            self.thread.save(force_update=True)

            if self.forum.last_thread_id == self.thread.pk:
                self.forum.last_thread_name = self.change.thread_name_old
                self.forum.last_thread_slug = slugify(self.change.thread_name_old)
                self.forum.save(force_update=True)

        if self.change.post_content != self.post.post:
            self.post.post = self.change.post_content
            md, self.post.post_preparsed = post_markdown(self.change.post_content)

        self.post.save(force_update=True)
        
        messages.success(request, _("Post has been reverted to the state before %(date)s.") % {'date': reldate(self.change.date).lower()}, 'threads_%s' % self.post.pk)
        return self.redirect_to_post(self.post)
开发者ID:0x1330,项目名称:Misago,代码行数:47,代码来源:changelog.py

示例7: make_jump

 def make_jump(self):
     username = slugify(self.request.POST.get("username", "").strip())
     if not username:
         self.request.messages.set_flash(
             Message(_("You have to enter name of user you want to invite to thread.")), "error", "threads"
         )
         return self.retreat_redirect()
     try:
         user = User.objects.get(username_slug=username)
         acl = user.acl(self.request)
         if user in self.thread.participants.all():
             if user.pk == self.request.user.pk:
                 self.request.messages.set_flash(
                     Message(_("You cannot add yourself to this thread.")), "error", "threads"
                 )
             else:
                 self.request.messages.set_flash(
                     Message(_("%(user)s is already participating in this thread.") % {"user": user.username}),
                     "info",
                     "threads",
                 )
         elif not acl.private_threads.can_participate():
             self.request.messages.set_flash(
                 Message(_("%(user)s cannot participate in private threads.") % {"user": user.username}),
                 "info",
                 "threads",
             )
         elif not self.request.acl.private_threads.can_invite_ignoring() and not user.allow_pd_invite(
             self.request.user
         ):
             self.request.messages.set_flash(
                 Message(_("%(user)s restricts who can invite him to private threads.") % {"user": user.username}),
                 "info",
                 "threads",
             )
         else:
             self.thread.participants.add(user)
             user.sync_pds = True
             user.save(force_update=True)
             user.email_user(
                 self.request,
                 "private_thread_invite",
                 _('You\'ve been invited to private thread "%(thread)s" by %(user)s')
                 % {"thread": self.thread.name, "user": self.request.user.username},
                 {"author": self.request.user, "thread": self.thread},
             )
             self.thread.set_checkpoint(self.request, "invited", user)
             self.request.messages.set_flash(
                 Message(_("%(user)s has been added to this thread.") % {"user": user.username}),
                 "success",
                 "threads",
             )
     except User.DoesNotExist:
         self.request.messages.set_flash(
             Message(_("User with requested username could not be found.")), "error", "threads"
         )
     return self.retreat_redirect()
开发者ID:nintendos,项目名称:Misago,代码行数:57,代码来源:jumps.py

示例8: submit_form

    def submit_form(self, form, target):
        target.name = form.cleaned_data['name']
        target.slug = slugify(form.cleaned_data['name'])
        target.style = form.cleaned_data['style']
        target.save(force_update=True)

        target.update_forums(form.cleaned_data['forums'])

        return target, Message(_('Changes in prefix "%(name)s" have been saved.') % {'name': self.original_name}, messages.SUCCESS)
开发者ID:dopestz,项目名称:Misago-1,代码行数:9,代码来源:views.py

示例9: post_action_split

 def post_action_split(self, ids):
     for id in ids:
         if id == self.thread.start_post_id:
             raise forms.ValidationError(_("You cannot split first post from thread."))
     message = None
     if self.request.POST.get('do') == 'split':
         form = SplitThreadForm(self.request.POST, request=self.request)
         if form.is_valid():
             new_thread = Thread()
             new_thread.forum = form.cleaned_data['thread_forum']
             new_thread.name = form.cleaned_data['thread_name']
             new_thread.slug = slugify(form.cleaned_data['thread_name'])
             new_thread.start = timezone.now()
             new_thread.last = timezone.now()
             new_thread.start_poster_name = 'n'
             new_thread.start_poster_slug = 'n'
             new_thread.last_poster_name = 'n'
             new_thread.last_poster_slug = 'n'
             new_thread.save(force_insert=True)
             prev_merge = -1
             merge = -1
             for post in self.posts:
                 if post.pk in ids:
                     if prev_merge != post.merge:
                         prev_merge = post.merge
                         merge += 1
                     post.merge = merge
                     post.move_to(new_thread)
                     post.save(force_update=True)
             new_thread.sync()
             new_thread.save(force_update=True)
             self.thread.sync()
             self.thread.save(force_update=True)
             self.forum.sync()
             self.forum.save(force_update=True)
             if new_thread.forum != self.forum:
                 new_thread.forum.sync()
                 new_thread.forum.save(force_update=True)
             self.request.messages.set_flash(Message(_("Selected posts have been split to new thread.")), 'success', 'threads')
             return redirect(reverse(self.type_prefix, kwargs={'thread': new_thread.pk, 'slug': new_thread.slug}))
         message = Message(form.non_field_errors()[0], 'error')
     else:
         form = SplitThreadForm(request=self.request, initial={
                                                               'thread_name': _('[Split] %s') % self.thread.name,
                                                               'thread_forum': self.forum,
                                                               })
     return self.request.theme.render_to_response('%ss/split.html' % self.type_prefix,
                                                  {
                                                   'type_prefix': self.type_prefix,
                                                   'message': message,
                                                   'forum': self.forum,
                                                   'parents': self.parents,
                                                   'thread': self.thread,
                                                   'posts': ids,
                                                   'form': FormLayout(form),
                                                   },
                                                  context_instance=RequestContext(self.request));
开发者ID:Misago,项目名称:Misago,代码行数:57,代码来源:posts.py

示例10: action_merge

    def action_merge(self, ids):
        if len(ids) < 2:
            raise ValidationError(_("You have to pick two or more threads to merge."))
        threads = []
        for thread in self.threads:
            if thread.pk in ids:
                threads.append(thread)
        if self.request.POST.get('origin') == 'merge_form':
            form = MergeThreadsForm(self.request.POST, request=self.request, threads=threads)
            if form.is_valid():
                new_thread = Thread.objects.create(
                                                   forum=form.cleaned_data['new_forum'],
                                                   name=form.cleaned_data['thread_name'],
                                                   slug=slugify(form.cleaned_data['thread_name']),
                                                   start=timezone.now(),
                                                   last=timezone.now()
                                                   )
                merged = []
                for thread in reversed(threads):
                    merged.append(thread.pk)
                    thread.merge_with(new_thread)
                Thread.objects.filter(id__in=merged).delete()
                new_thread.sync()
                new_thread.save(force_update=True)
                new_thread.update_current_dates()
                self.forum.sync()
                self.forum.save(force_update=True)
                if form.cleaned_data['new_forum'].pk != self.forum.pk:
                    form.cleaned_data['new_forum'].sync()
                    form.cleaned_data['new_forum'].save(force_update=True)
                self.request.messages.set_flash(Message(_('Selected threads have been merged into new one.')), 'success', 'threads')
                return None
            self.message = Message(form.non_field_errors()[0], 'error')
        else:
            form = MergeThreadsForm(request=self.request, threads=threads)

        warning = None
        lookback = threads[0].last_post_id
        for thread in threads[1:]:
            if thread.start_post_id < lookback:
                warning = Message(_("Warning: Posting times in one or more of threads that you are going to merge are overlapping. This may result in disturbed flow of merged thread."), 'warning')
                break
            else:
                lookback = thread.last_post_id

        return self.request.theme.render_to_response(('%ss/merge.html' % self.type_prefix),
                                                     {
                                                      'type_prefix': self.type_prefix,
                                                      'message': self.message,
                                                      'warning': warning,
                                                      'forum': self.forum,
                                                      'parents': self.parents,
                                                      'threads': threads,
                                                      'form': FormLayout(form),
                                                      },
                                                     context_instance=RequestContext(self.request));
开发者ID:finid,项目名称:Misago,代码行数:56,代码来源:moderation.py

示例11: submit_form

    def submit_form(self, form, target):
        target.name = form.cleaned_data['name']
        target.slug = slugify(form.cleaned_data['name'])
        target.description = form.cleaned_data['description']
        target.expires_after_minutes = form.cleaned_data['expires_after_minutes']
        target.restrict_posting_replies = form.cleaned_data['restrict_posting_replies']
        target.restrict_posting_threads = form.cleaned_data['restrict_posting_threads']
        target.save(force_update=True)

        return target, Message(_('Changes in warning level "%(name)s" have been saved.') % {'name': self.original_name}, messages.SUCCESS)
开发者ID:FashtimeDotCom,项目名称:Misago,代码行数:10,代码来源:views.py

示例12: post_action_split

 def post_action_split(self, ids):
     for id in ids:
         if id == self.thread.start_post_id:
             raise forms.ValidationError(_("You cannot split first post from thread."))
     message = None
     if self.request.POST.get("do") == "split":
         form = SplitThreadForm(self.request.POST, request=self.request)
         if form.is_valid():
             new_thread = Thread()
             new_thread.forum = form.cleaned_data["thread_forum"]
             new_thread.name = form.cleaned_data["thread_name"]
             new_thread.slug = slugify(form.cleaned_data["thread_name"])
             new_thread.start = timezone.now()
             new_thread.last = timezone.now()
             new_thread.start_poster_name = "n"
             new_thread.start_poster_slug = "n"
             new_thread.last_poster_name = "n"
             new_thread.last_poster_slug = "n"
             new_thread.save(force_insert=True)
             for post in self.posts:
                 if post.pk in ids:
                     post.move_to(new_thread)
                     post.save(force_update=True)
             new_thread.sync()
             new_thread.save(force_update=True)
             self.thread.sync()
             self.thread.save(force_update=True)
             self.forum.sync()
             self.forum.save(force_update=True)
             if new_thread.forum != self.forum:
                 new_thread.forum.sync()
                 new_thread.forum.save(force_update=True)
             messages.success(self.request, _("Selected posts have been split to new thread."), "threads")
             return redirect(reverse(self.type_prefix, kwargs={"thread": new_thread.pk, "slug": new_thread.slug}))
         message = Message(form.non_field_errors()[0], messages.ERROR)
     else:
         form = SplitThreadForm(
             request=self.request,
             initial={"thread_name": _("[Split] %s") % self.thread.name, "thread_forum": self.forum},
         )
     return render_to_response(
         "%ss/split.html" % self.type_prefix,
         {
             "type_prefix": self.type_prefix,
             "message": message,
             "forum": self.forum,
             "parents": self.parents,
             "thread": self.thread,
             "posts": ids,
             "form": form,
         },
         context_instance=RequestContext(self.request),
     )
开发者ID:pzduniak,项目名称:Misago,代码行数:53,代码来源:posts.py

示例13: submit_form

 def submit_form(self, form, target):
     target.name = form.cleaned_data['name']
     target.slug = slugify(form.cleaned_data['name'])
     target.description = form.cleaned_data['description']
     target.style = form.cleaned_data['style']
     target.title = form.cleaned_data['title']
     target.special = form.cleaned_data['special']
     target.as_tab = form.cleaned_data['as_tab']
     target.on_index = form.cleaned_data['on_index']
     target.criteria = form.cleaned_data['criteria']
     target.save(force_update=True)
     return target, Message(_('Changes in rank "%(name)s" have been saved.') % {'name': self.original_name}, 'success')
开发者ID:Misago,项目名称:Misago,代码行数:12,代码来源:views.py

示例14: dispatch

    def dispatch(self, request, **kwargs):
        if ((not self.change.thread_name_old or self.thread.name == self.change.thread_name_old)
            and (self.change.post_content == self.post.post)):
            request.messages.set_flash(Message(_("No changes to revert.")), 'error', 'changelog')
            return redirect(reverse('%s_changelog_diff' % self.type_prefix, kwargs={'thread': self.thread.pk, 'slug': self.thread.slug, 'post': self.post.pk, 'change': self.change.pk}))

        if self.change.thread_name_old and self.change.thread_name_old != self.thread.name:
            self.thread.name = self.change.thread_name_old
            self.thread.slug = slugify(self.change.thread_name_old)
            self.thread.save(force_update=True)

            if self.forum.last_thread_id == self.thread.pk:
                self.forum.last_thread_name = self.change.thread_name_old
                self.forum.last_thread_slug = slugify(self.change.thread_name_old)
                self.forum.save(force_update=True)

        if self.change.post_content != self.post.post:
            self.post.post = self.change.post_content
            md, self.post.post_preparsed = post_markdown(request, self.change.post_content)
            self.post.save(force_update=True)

        request.messages.set_flash(Message(_("Post has been reverted to state from %(date)s.") % {'date': reldate(self.change.date).lower()}), 'success', 'threads_%s' % self.post.pk)
        return self.redirect_to_post(self.post)
开发者ID:Misago,项目名称:Misago,代码行数:23,代码来源:changelog.py

示例15: load

def load():
    Forum(special='private_threads', name='private', slug='private', type='forum').insert_at(None, save=True)
    Forum(special='reports', name='reports', slug='reports', type='forum').insert_at(None, save=True)

    root = Forum(special='root', name='root', slug='root')
    root.insert_at(None, save=True)
    cat = Forum(type='category', name='First Category', slug='first-category')
    cat.insert_at(root, save=True)
    forum = Forum(type='forum', name='First Forum', slug='first-forum', threads=1, posts=1)
    forum.insert_at(cat, save=True)
    Forum(type='redirect', name='Project Homepage', slug='project-homepage', redirect='http://misago-project.org').insert_at(cat, position='last-child', save=True)
    Forum.objects.populate_tree(True)

    now = timezone.now()
    thread = Thread.objects.create(
                                   forum=forum,
                                   name='Welcome to Misago!',
                                   slug=slugify('Welcome to Misago!'),
                                   start=now,
                                   last=now,
                                   )
    post = Post.objects.create(
                               forum=forum,
                               thread=thread,
                               user_name='MisagoProject',
                               ip='127.0.0.1',
                               agent='',
                               post='Welcome to Misago!',
                               post_preparsed='Welcome to Misago!',
                               date=now,
                               )
    thread.start_post = post
    thread.start_poster_name = 'MisagoProject'
    thread.start_poster_slug = 'misagoproject'
    thread.last_post = post
    thread.last_poster_name = 'MisagoProject'
    thread.last_poster_slug = 'misagoproject'
    thread.save(force_update=True)
    forum.last_thread = thread
    forum.last_thread_name = thread.name
    forum.last_thread_slug = thread.slug
    forum.last_thread_date = thread.last
    forum.last_poster = thread.last_poster
    forum.last_poster_name = thread.last_poster_name
    forum.last_poster_slug = thread.last_poster_slug
    forum.save(force_update=True)

    load_monitor_fixture(monitor_fixture)
开发者ID:0x1330,项目名称:Misago,代码行数:48,代码来源:forums.py


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