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

Python models.TaggedItem类代码示例

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

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



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

示例1: get_tag_cloud

def get_tag_cloud(model, queryset, tags_filter=None):
    if tags_filter is None:
        tags_filter = set()
        for item in queryset.all():
            tags_filter.update(item.tags.all())

    tags_filter = set([tag.id for tag in tags_filter])
    tags = set(TaggedItem.objects.filter(
        content_type__model=model.__name__.lower()
    ).values_list('tag_id', flat=True))

    if tags_filter is not None:
        tags = tags.intersection(tags_filter)
    tag_ids = list(tags)

    kwargs = TaggedItem.bulk_lookup_kwargs(queryset)
    kwargs['tag_id__in'] = tag_ids
    counted_tags = dict(TaggedItem.objects
                                  .filter(**kwargs)
                                  .values('tag')
                                  .annotate(count=models.Count('tag'))
                                  .values_list('tag', 'count'))
    tags = TaggedItem.tag_model().objects.filter(pk__in=counted_tags.keys())
    for tag in tags:
        tag.count = counted_tags[tag.pk]
    return sorted(tags, key=lambda x: -x.count)
开发者ID:okfish,项目名称:django-oscar-news,代码行数:26,代码来源:models.py


示例2: _delete_and_recreate_tags

def _delete_and_recreate_tags(slug):
    source_demo = Submission.objects.using("default").get(slug=slug)
    destination_demo = Submission.objects.using("new").get(slug=slug)
    source_type, destination_type = _get_demo_content_types()

    source_tags = source_demo.taggit_tags.all()
    source_tags_names = [tag.name for tag in source_tags]
    destination_tags = destination_demo.taggit_tags.using("new").all()
    destination_tags_names = [tag.name for tag in destination_tags]

    if source_tags_names == destination_tags_names:
        logger.info(
            "%s: Found %s matching tag(s): %s" % (source_demo.slug, len(destination_tags), destination_tags_names)
        )
        return destination_tags
    else:
        dest_demo_tagged_items = TaggedItem.objects.using("new").filter(
            tag__in=[tag for tag in destination_tags], object_id=destination_demo.id, content_type=destination_type
        )
        dest_demo_tagged_items.using("new").delete()
        logger.info("%s: Migrating %s tag(s): %s" % (source_demo.slug, len(source_tags), source_tags_names))
        for source_tag in source_tags:
            try:
                destination_tag = Tag.objects.using("new").get(name=source_tag.name)
            except Tag.DoesNotExist:
                destination_tag = Tag(name=source_tag.name)
                destination_tag.save(using="new")
            destination_demo_tag = TaggedItem(
                content_type=destination_type, object_id=destination_demo.id, tag=destination_tag
            )
            destination_demo_tag.save(using="new")
    return destination_tags
开发者ID:jamonation,项目名称:kuma,代码行数:32,代码来源:migrate_demos.py


示例3: entry_tags

	def entry_tags(self):
		"""Returns a :class:`QuerySet` of :class:`.Tag`\ s that are used on any entries in this blog."""
		entry_pks = list(self.entries.values_list('pk', flat=True))
		kwargs = {
			'%s__object_id__in' % TaggedItem.tag_relname(): entry_pks
		}
		return TaggedItem.tags_for(BlogEntry).filter(**kwargs)
开发者ID:MechanisM,项目名称:philo,代码行数:7,代码来源:models.py


示例4: get_tags

    def get_tags(self, request, namespace):
        """
        Get tags with articles count for given namespace string.

        Return list of Tag objects ordered by custom 'num_articles' attribute.
        """
        if (request and hasattr(request, 'toolbar') and
                request.toolbar and request.toolbar.edit_mode):
            articles = self.namespace(namespace)
        else:
            articles = self.published().namespace(namespace)
        if not articles:
            # return empty iterable early not to perform useless requests
            return []
        kwargs = TaggedItem.bulk_lookup_kwargs(articles)

        # aggregate and sort
        counted_tags = dict(TaggedItem.objects
                            .filter(**kwargs)
                            .values('tag')
                            .annotate(tag_count=models.Count('tag'))
                            .values_list('tag', 'tag_count'))

        # and finally get the results
        tags = Tag.objects.filter(pk__in=counted_tags.keys())
        for tag in tags:
            tag.num_articles = counted_tags[tag.pk]
        return sorted(tags, key=attrgetter('num_articles'), reverse=True)
开发者ID:stefanfoulis,项目名称:aldryn-newsblog,代码行数:28,代码来源:managers.py


示例5: tag_cloud

 def tag_cloud(self, other_model=None, queryset=None, published=True):
     from taggit.models import TaggedItem
     tag_ids = self._taglist(other_model, queryset)
     kwargs = {}
     if published:
         kwargs = TaggedItem.bulk_lookup_kwargs(self.model.objects.published())
     kwargs['tag_id__in'] = tag_ids
     counted_tags = dict(TaggedItem.objects
                                   .filter(**kwargs)
                                   .values('tag')
                                   .annotate(count=models.Count('tag'))
                                   .values_list('tag', 'count'))
     tags = TaggedItem.tag_model().objects.filter(pk__in=counted_tags.keys())
     for tag in tags:
         tag.count = counted_tags[tag.pk]
     return sorted(tags, key=lambda x: -x.count)
开发者ID:aleks-sngn,项目名称:djangocms-blog,代码行数:16,代码来源:managers.py


示例6: get_tags

    def get_tags(self, entries=None, language=None):
        """Returns tags used to tag post and its count. Results are ordered by count."""

        if not entries:
            entries = self

        if language:
            entries = entries.filter_by_language(language)
        entries = entries.distinct()
        if not entries:
            return []
        kwargs = TaggedItem.bulk_lookup_kwargs(entries)

        # aggregate and sort
        counted_tags = dict(TaggedItem.objects
                                      .filter(**kwargs)
                                      .values('tag')
                                      .annotate(count=models.Count('tag'))
                                      .values_list('tag', 'count'))

        # and finally get the results
        tags = Tag.objects.filter(pk__in=counted_tags.keys())
        for tag in tags:
            tag.count = counted_tags[tag.pk]
        return sorted(tags, key=lambda x: -x.count)
开发者ID:francofuji,项目名称:aldryn-blog,代码行数:25,代码来源:models.py


示例7: extract_document

    def extract_document(cls, obj_id):
        """Extracts indexable attributes from a Question and its answers."""

        # Note: Need to keep this in sync with
        # tasks.update_question_vote_chunk.
        obj = cls.uncached.values(
            'id', 'title', 'content', 'num_answers', 'solution_id',
            'is_locked', 'created', 'updated', 'num_votes_past_week',
            'creator__username').get(pk=obj_id)

        d = {}
        d['id'] = obj['id']
        d['model'] = cls.get_model_name()
        d['title'] = obj['title']
        d['question_content'] = obj['content']
        d['num_answers'] = obj['num_answers']
        d['is_solved'] = bool(obj['solution_id'])
        d['is_locked'] = obj['is_locked']
        d['has_answers'] = bool(obj['num_answers'])

        # We do this because get_absolute_url is an instance method
        # and we don't want to create an instance because it's a DB
        # hit and expensive. So we do it by hand. get_absolute_url
        # doesn't change much, so this is probably ok.
        d['url'] = reverse('questions.answers',
                           kwargs={'question_id': obj['id']})

        # TODO: Sphinx stores created and updated as seconds since the
        # epoch, so we convert them to that format here so that the
        # search view works correctly. When we ditch Sphinx, we should
        # see if it's faster to filter on ints or whether we should
        # switch them to dates.
        d['created'] = int(time.mktime(obj['created'].timetuple()))
        d['updated'] = int(time.mktime(obj['updated'].timetuple()))

        d['question_creator'] = obj['creator__username']
        d['num_votes'] = (QuestionVote.objects
                          .filter(question=obj['id'])
                          .count())
        d['num_votes_past_week'] = obj['num_votes_past_week']

        d['tag'] = list(TaggedItem.tags_for(
            Question, Question(pk=obj_id)).values_list('name', flat=True))

        answer_values = list(Answer.objects
                                   .filter(question=obj_id)
                                   .values_list('content',
                                                'creator__username'))

        d['answer_content'] = [a[0] for a in answer_values]
        d['answer_creator'] = list(set([a[1] for a in answer_values]))

        if not answer_values:
            d['has_helpful'] = False
        else:
            d['has_helpful'] = Answer.objects.filter(
                question=obj_id).filter(votes__helpful=True).exists()

        d['indexed_on'] = int(time.time())
        return d
开发者ID:Curlified,项目名称:kitsune,代码行数:60,代码来源:models.py


示例8: handle

 def handle(self, *arg, **kwargs):
     print '##########################################################'
     print '### This file is generated by ./manage.py dump_topics. ###'
     print '##########################################################'
     print 'from tower import ugettext as _\n'
     for tag in TaggedItem.tags_for(Document):
         print '_("""{tag}""", "KB Topic")'.format(tag=tag.name)
开发者ID:Akamad007,项目名称:kitsune,代码行数:7,代码来源:dump_topics.py


示例9: set_taggeditems

 def set_taggeditems(self):
     objects = OldTaggedItem.objects.all()
     print objects.count()
     for old_tagitem in objects:
         old_id = old_tagitem.tag_id
         new_id = self.dupemap.get(old_id, old_id)
         new_tags = NewTag.objects.filter(id=new_id)
         if new_tags:
             new_tag = new_tags[0]
             new_tagitem = NewTaggedItem(
                 id=old_tagitem.id,
                 tag=new_tag,
                 content_type=old_tagitem.content_type,
                 object_id=old_tagitem.object_id,
             )
             new_tagitem.save()
     print NewTaggedItem.objects.count()
开发者ID:thatzprem,项目名称:django-nano,代码行数:17,代码来源:migrate_tagging_to_taggit.py


示例10: userfeed_tags

 def userfeed_tags(user):
     '''Return all the UserFeed tags for a user.'''
     #ct = ContentType.objects.get_for_model(UserFeed)
     kwargs = {
         "userfeed__in": UserFeed.objects.filter(user=user)
     }
     tags = TaggedItem.tag_model().objects.filter(**kwargs).distinct()
     return tags
开发者ID:ReadRaven,项目名称:readraven,代码行数:8,代码来源:models.py


示例11: read

 def read(cls, req, slug=None, model=None):
     if model:
         models = [System, Module, Interface, ArchitecturalPattern]
         lookup = dict(zip(map(lambda model: model._meta.object_name.lower(), models), models))
         return TaggedItem.tags_for(lookup[model])
     if slug:
         return map(lambda i: i.content_object, TaggedItem.objects.select_related().filter(tag=Tag.objects.get(slug=slug)))
     else:
         return map(lambda i: dict(name=i['name'], count=i['count'], resource_uri=reverse('api_tag', args=[i['slug']])), Tag.objects.values('name', 'slug').annotate(count=Count('taggit_taggeditem_items')).order_by('-count'))
开发者ID:plalloni,项目名称:macom,代码行数:9,代码来源:handlers.py


示例12: lookups

 def lookups(self, request, model_admin):
   """
   Returns a list of tuples. The first element in each tuple is the coded value
   for the option that will appear in the URL query. The second element is the
   human-readable name for the option that will appear in the right sidebar.
   """
   list = []
   tags = TaggedItem.tags_for(model_admin.model)
   for tag in tags:
     list.append( (tag.name, (tag.name)) )
   return list
开发者ID:erivanio,项目名称:pratosocial,代码行数:11,代码来源:admin.py


示例13: clean

 def clean(self):
     data = self.cleaned_data
     if data['auto']:
         tags = set(data['tags'])
         tags.update([
             tag
             for tag in TaggedItem.tags_for(models.Post)
             if re.search(r'\b%s\b' % tag.name, data['content'], re.I|re.M)
         ])
         data['tags'] = list(tags)
     return data
开发者ID:strakh,项目名称:gnocchi-blog,代码行数:11,代码来源:forms.py


示例14: lookups

    def lookups(self, request, model_admin):
        """
        Returns tuple of tuples (key, value) for available Tag choices.

        :param request: the Request instance.
        :param model_admin: the ModelAdmin instance.
        :rtype: tuple.
        """
        return (
            (tag.id, tag.name)
            for tag in TaggedItem.tags_for(Ticket)
        )
开发者ID:slo-county-planning-and-building,项目名称:metis-backend,代码行数:12,代码来源:admin.py


示例15: forwards

 def forwards(self, orm):
     for entry in orm['checklists.Entry'].objects.all():
         tags = TaggedItem.tags_for(orm['checklists.Entry'], entry)
         for label in [unicode(tag) for tag in tags]:
             names = {}
             # Add localized fields for the SpeciesGroup table
             for language_code, language_name in settings.LANGUAGES:
                 if settings.LANGUAGE_CODE == language_code:
                     names['name_%s' % language_code] = label.capitalize()
                 else:
                     names['name_%s' % language_code] = ''
             tag, created = orm['checklists.EntryTag'].objects.get_or_create(
                 slug=label.lower(),
                 **names
             )
             entry.tags.add(tag)
开发者ID:StuartMacKay,项目名称:checklists,代码行数:16,代码来源:0040_set_entry_status.py


示例16: extract_document

    def extract_document(cls, obj_id):
        """Extracts indexable attributes from a Question and its answers."""
        obj = cls.uncached.values(
            "id",
            "title",
            "content",
            "num_answers",
            "solution_id",
            "is_locked",
            "created",
            "updated",
            "num_votes_past_week",
            "creator__username",
        ).get(pk=obj_id)

        d = {}
        d["id"] = obj["id"]
        d["title"] = obj["title"]
        d["question_content"] = obj["content"]
        d["replies"] = obj["num_answers"]
        d["is_solved"] = bool(obj["solution_id"])
        d["is_locked"] = obj["is_locked"]
        d["has_answers"] = bool(obj["num_answers"])

        # TODO: Sphinx stores created and updated as seconds since the
        # epoch, so we convert them to that format here so that the
        # search view works correctly. When we ditch Sphinx, we should
        # see if it's faster to filter on ints or whether we should
        # switch them to dates.
        d["created"] = int(time.mktime(obj["created"].timetuple()))
        d["updated"] = int(time.mktime(obj["updated"].timetuple()))

        d["question_creator"] = obj["creator__username"]
        d["question_votes"] = obj["num_votes_past_week"]

        d["tag"] = list(TaggedItem.tags_for(Question, Question(pk=obj_id)).values_list("name", flat=True))

        answer_values = list(Answer.objects.filter(question=obj_id).values_list("content", "creator__username"))
        d["answer_content"] = [a[0] for a in answer_values]
        d["answer_creator"] = list(set([a[1] for a in answer_values]))

        if not answer_values:
            d["has_helpful"] = False
        else:
            d["has_helpful"] = Answer.objects.filter(question=obj_id).filter(votes__helpful=True).exists()

        return d
开发者ID:trinaldi,项目名称:kitsune,代码行数:47,代码来源:models.py


示例17: view_tagged_questions

def view_tagged_questions(request, tag_name, tagged_questions_template):
    tag = get_object_or_404(Tag, name=tag_name)
    questions = Question.objects.filter(tags__name__in=[tag_name]).values('id', 'slug', 'title')
    paginator = Paginator(questions, settings.DEFAULT_PAGINATION_COUNT)
    try:
        page = int(request.GET.get('page', 1))
    except ValueError:
        page = 1
    try:
        questions = paginator.page(page)
    except (EmptyPage, InvalidPage):
        questions = paginator.page(paginator.num_pages)
    #FIXME/TODO:This has to be cached at all costs
    all_tags = TaggedItem.tags_for(Question)
    return response(request, tagged_questions_template, {'questions': questions.object_list,
                                                        'tag': tag,
                                                        'all_tags':all_tags})
开发者ID:none-da,项目名称:stud2dotoh,代码行数:17,代码来源:views.py


示例18: _add_tags

def _add_tags(obj, tags_str, creator, content_type_name):
    for tag_name in tags_str.split(','):
        tag_name = tag_name.strip()
        # don't recreate the tag if it already exists
        try:
            t = Tag.objects.get(slug=slugify(tag_name))
        except ObjectDoesNotExist as dne:
            t = Tag()
            t.name = tag_name[:99]
            t.slug = slugify(tag_name)
            t.save()
        ti = TaggedItem()
        ti.tag = t
        ti.object_id = obj.id
        ti.tag_creator = creator
        ti.content_type = ContentType.objects.filter(name=content_type_name)[0]
        ti.save()
开发者ID:makaimc,项目名称:pfisdi,代码行数:17,代码来源:__init__.py


示例19: focus

def focus(request, field, value, template_name="tasks/focus.html"):
    
    group, bridge = group_and_bridge(request)
    if group:
        is_member = group.request.user_is_member()
    else:
        is_member = True
    
    group_by = request.GET.get("group_by")
    filter_only = request.GET.get("filter_only", False)
    tags_list = []
    expanded_tags_list = []
    
    if group:
        tasks = group.content_objects(Task)
    else:
        tasks = Task.objects.filter(object_id=None)
    
    # default filtering
    state_keys = dict(workflow.STATE_CHOICES).keys()
    default_states = set(state_keys).difference(
        # don't show these states
        set(["2", "3"])
    )
    
    # have to store for each prefix because initial data isn't support on the
    # FilterSet
    filter_data = {
        "state": list(default_states),
    }
    filter_data.update(request.GET)
    
    task_filter = TaskFilter(filter_data, queryset=tasks)
    
    if field == "modified":
        try:
            # @@@ this seems hackish and brittle but I couldn't work out another way
            year, month, day = value.split("-")
            # have to int month and day in case zero-padded
            tasks = tasks.filter(modified__year=int(year), modified__month=int(month), modified__day=int(day))
        except:
            tasks = Task.objects.none() # @@@ or throw 404?
    elif field == "state":
        task_filter = None # prevent task filtering
        try:
            state = workflow.REVERSE_STATE_CHOICES[value]
        except KeyError:
            raise Http404
        tasks = tasks.filter(state=state)
    elif field == "assignee":
        if value == "unassigned": # @@@ this means can"t have a username "unassigned":
            tasks = tasks.filter(assignee__isnull=True)
        else:
            try:
                assignee = User.objects.get(username=value)
                tasks = tasks.filter(assignee=assignee)
            except User.DoesNotExist:
                tasks = Task.objects.none() # @@@ or throw 404?
    elif field == "tag":
        tags_list = urllib.unquote_plus(value).split()
        
        task_tags = TaggedItem.tags_for(Task)
        for tag in tags_list:
            if tag.endswith(":*"):
                expanded_tags_list.extend(t.name for t in task_tags.filter(name__startswith=tag[:-1]))
            else:
                expanded_tags_list.append(tag)
        
        tasks = tasks.filter(tags__name__in=expanded_tags_list)
    
    if task_filter is not None:
        # Django will not merge queries that are both not distinct or distinct
        tasks = tasks.distinct() & task_filter.qs
    
    group_by_querydict = request.GET.copy()
    group_by_querydict.pop("group_by", None)
    group_by_querystring = group_by_querydict.urlencode()
    
    ctx = group_context(group, bridge)
    ctx.update({
        "task_filter": task_filter,
        "tasks": tasks,
        "field": field,
        "value": value,
        "group_by": group_by,
        "gbqs": group_by_querystring,
        "is_member": is_member,
        "task_tags": Task.tags.all(),
        "filter_only": filter_only,
        "tags_list": expanded_tags_list,
    })
    
    return render_to_response(template_name, RequestContext(request, ctx))
开发者ID:goldsoft1206,项目名称:code.pinaxproject.com,代码行数:93,代码来源:views.py


示例20: get_context_data

    def get_context_data(self, **kwargs):
        context = super(BlogBaseView, self).get_context_data(**kwargs)
        context['blog_tags'] = TaggedItem.tags_for(Blog).order_by('name')
        context['recent_blog_list'] = Blog.objects.recent_posts()

        return context
开发者ID:almanar,项目名称:glucose-tracker,代码行数:6,代码来源:views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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