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


Python TaggedItem.tags_for方法代码示例

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


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

示例1: extract_document

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
    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,代码行数:62,代码来源:models.py

示例2: entry_tags

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
	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,代码行数:9,代码来源:models.py

示例3: handle

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
 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,代码行数:9,代码来源:dump_topics.py

示例4: read

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
 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,代码行数:11,代码来源:handlers.py

示例5: clean

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
 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,代码行数:13,代码来源:forms.py

示例6: lookups

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
 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,代码行数:13,代码来源:admin.py

示例7: lookups

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
    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,代码行数:14,代码来源:admin.py

示例8: forwards

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
 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,代码行数:18,代码来源:0040_set_entry_status.py

示例9: extract_document

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
    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,代码行数:49,代码来源:models.py

示例10: view_tagged_questions

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
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,代码行数:19,代码来源:views.py

示例11: extract_document

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
    def extract_document(cls, obj_id, obj=None):
        """Extracts indexable attributes from a Question and its answers."""
        fields = ['id', 'title', 'content', 'num_answers', 'solution_id',
                  'is_locked', 'created', 'updated', 'num_votes_past_week',
                  'locale']
        composed_fields = ['creator__username']
        all_fields = fields + composed_fields

        if obj is None:
            # Note: Need to keep this in sync with
            # tasks.update_question_vote_chunk.
            obj = cls.uncached.values(*all_fields).get(pk=obj_id)
        else:
            fixed_obj = dict([(field, getattr(obj, field))
                              for field in fields])
            fixed_obj['creator__username'] = obj.creator.username
            obj = fixed_obj

        d = {}
        d['id'] = obj['id']
        d['document_id'] = cls.get_document_id(obj['id'])
        d['model'] = cls.get_model_name()

        # 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']})

        d['indexed_on'] = int(time.time())

        # 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()))

        topics = Topic.uncached.filter(question__id=obj['id'])
        products = Product.uncached.filter(question__id=obj['id'])
        d['topic'] = [t.slug for t in topics]
        d['product'] = [p.slug for p in products]

        d['question_title'] = obj['title']
        d['question_content'] = obj['content']
        d['question_num_answers'] = obj['num_answers']
        d['question_is_solved'] = bool(obj['solution_id'])
        d['question_is_locked'] = obj['is_locked']
        d['question_has_answers'] = bool(obj['num_answers'])

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

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

        d['question_locale'] = obj['locale']

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

        d['question_answer_content'] = [a[0] for a in answer_values]
        d['question_answer_creator'] = list(set(a[1] for a in answer_values))

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

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

示例12: get_context_data

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
    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,代码行数:8,代码来源:views.py

示例13: view_questions

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
def view_questions(request, questions_template):
    questions_count = Question.objects.count()
    #FIXME/TODO:This has to be cached at all costs
    all_tags = TaggedItem.tags_for(Question)
    return response(request, questions_template, {'questions_count':questions_count,
                                                  'all_tags':all_tags})
开发者ID:none-da,项目名称:stud2dotoh,代码行数:8,代码来源:views.py

示例14: extract_document

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
    def extract_document(cls, obj_id, obj=None):
        """Extracts indexable attributes from a Question and its answers."""
        fields = ['id', 'title', 'content', 'num_answers', 'solution_id',
                  'is_locked', 'is_archived', 'created', 'updated',
                  'num_votes_past_week', 'locale', 'product_id', 'topic_id',
                  'is_spam']
        composed_fields = ['creator__username']
        all_fields = fields + composed_fields

        if obj is None:
            # Note: Need to keep this in sync with
            # tasks.update_question_vote_chunk.
            model = cls.get_model()
            obj = model.objects.values(*all_fields).get(pk=obj_id)
        else:
            fixed_obj = dict([(field, getattr(obj, field))
                              for field in fields])
            fixed_obj['creator__username'] = obj.creator.username
            obj = fixed_obj

        if obj['is_spam']:
            raise UnindexMeBro()

        d = {}
        d['id'] = obj['id']
        d['model'] = cls.get_mapping_type_name()

        # 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.details',
                           kwargs={'question_id': obj['id']})

        d['indexed_on'] = int(time.time())

        d['created'] = int(time.mktime(obj['created'].timetuple()))
        d['updated'] = int(time.mktime(obj['updated'].timetuple()))

        topics = Topic.objects.filter(id=obj['topic_id'])
        products = Product.objects.filter(id=obj['product_id'])
        d['topic'] = [t.slug for t in topics]
        d['product'] = [p.slug for p in products]

        d['question_title'] = obj['title']
        d['question_content'] = obj['content']
        d['question_num_answers'] = obj['num_answers']
        d['question_is_solved'] = bool(obj['solution_id'])
        d['question_is_locked'] = obj['is_locked']
        d['question_is_archived'] = obj['is_archived']
        d['question_has_answers'] = bool(obj['num_answers'])

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

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

        d['question_locale'] = obj['locale']

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

        d['question_answer_content'] = [a[0] for a in answer_values]
        d['question_answer_creator'] = list(set(a[1] for a in answer_values))

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

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

示例15: get_queryset

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import tags_for [as 别名]
 def get_queryset(self):
     return TaggedItem.tags_for(Post)
开发者ID:jobscry,项目名称:blog,代码行数:4,代码来源:views.py


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