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


Python models.Tag类代码示例

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


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

示例1: ask

def ask(request):
    ask_form = AskQuestion(request.POST or None)
    args = {}
    args['form'] = ask_form
    if request.POST and ask_form.is_valid():
        question = Question(text=ask_form.cleaned_data['text'], title=ask_form.cleaned_data['title'])
        tags = ask_form.cleaned_data['tags']

        g = Tag.objects.all()
        getTag = tags.split(', ')

        for tag in getTag:
            counter = 0
            for l in g:
                if l.tag == tag:
                    counter += 1
            if counter == 0:
                t = Tag(tag=tag)
                t.save()


        user = auth.get_user(request)
        question.author = user

        question.save()
        a = g.filter(tag__in=getTag)
        question.tags.add(*a)
        return redirect('questionGet', question_id=question.id)

    else:
        return render(request, 'ask.html', args)
开发者ID:Zanexess,项目名称:AskingHeapProject,代码行数:31,代码来源:views.py

示例2: mutate_and_get_payload

    def mutate_and_get_payload(cls, input, request, info):
        gid_type, gid = from_global_id(input.get('lifeNode'))
        node = LifeNode._meta.model.objects.get(document_id=gid)

        error = has_permission(cls, request, node, 'edit')
        if error:
            return error

        tag_title = input.get('title').strip(' \t\n\r')
        tag_slug = slugify(tag_title)

        try:
            tag = TagModel.objects.get(slug=tag_slug)
        except TagModel.DoesNotExist:
            tag = TagModel(
                title=tag_title,
                slug=tag_slug,
            )
            tag.save(request=request)

        c = CharacteristicModel(
            tag=tag.document,
            lifeNode=node.document,
            value=input.get('value')
        )
        c.save(request=request)

        return CharacteristicAdd(
            lifeNode=node,
            characteristic=Characteristic.Connection.Edge(
                node=c, cursor=offset_to_cursor(0))
        )
开发者ID:naturebismo,项目名称:backend,代码行数:32,代码来源:mutations.py

示例3: add

def add(request, app_label, model, object_id):

    content_type = get_object_or_404(ContentType, app_label=app_label,
                                     model=model)
    model = content_type.model_class()
    object_id = int(object_id)

    item = get_object_or_404(model, id=object_id)
    user = request.user

    new_tags = []

    if request.method == "POST":
        tags = [t.strip() for t in request.POST.get("tags", u"").split(u",")]
        for tag in tags:
            if not item.tags.filter(user=user, slug=slugify(tag)).count():
                tag = Tag(content_type=content_type, object_id=object_id,
                    user=user, name=tag)
                tag.save()
                new_tags.append(tag)

    reindex(item)

    response = {"tags": []}
    for tag in new_tags:
        response["tags"].append(dict(name=tag.name,
                                     id=tag.id,
                                     url=reverse("materials:keyword_index",
                                                 kwargs={"keywords": tag.slug}),
                                     ))

    return response
开发者ID:colinbdclark,项目名称:OER-Commons,代码行数:32,代码来源:views.py

示例4: setUp

    def setUp(self):
        from regions.models import Region
        from pages.models import Page
        from tags.models import Tag, PageTagSet

        self.factory = RequestFactory()

        # Create a new region and associate a domain with it
        self.sf = Region(full_name="San Francisco", slug="sf")
        self.sf.save()
        self.sf.regionsettings.domain = 'fakename.org'
        self.sf.regionsettings.save()

        self.user = User.objects.create_user(
            username='testuser', email='[email protected]', password='fakepassword')
        self.user.save()
       
        # Create a page in the SF region
        p = Page(name='Parks', content='<p>Hi</p>', region=self.sf)
        p.save(user=self.user)
        p.content += "!"
        p.save(user=self.user)

        # Add a tag to the page
        t = Tag(name='park', slug='park', region=self.sf)
        t.save(user=self.user)
        pts = PageTagSet(region=self.sf, page=p)
        pts.save(user=self.user)
        pts.tags.add(t)
        pts.save(user=self.user)
开发者ID:lowiki-org,项目名称:localwiki-backend-server,代码行数:30,代码来源:tests.py

示例5: tagref_create

def tagref_create(request, tag_name):
  """ Create a single tag reference. 
  
  The resource must exist and the reference must be valid, but if the tag
  doesn't exist, then then it is created. 
  """
  try:
    # resource MUST exist
    res_str = request.POST['resource'].strip()
    resource = library.get(res_str)
    # reference must be valid
    ref_str = request.POST['reference']
    ref = resource.reference(ref_str)
  except:
    log.info("User provided bad resource or reference. (res: %s; ref: )", res_str, ref_str)
    raise Http404
  # if tag name doesn't exist, create it
  try:
    t = get_exact_tag(request.user, tag_name)
  except:
    # TODO: move to models
    t = Tag(tag=tag_name, user=request.user)
    t.save()
  log.debug("Saving new tag %s %s %s %s", ref_str, tag_name, t, ref.pretty())
  # TODO: move to models
  new_ref = Reference(tag=t, resource=res_str, reference=ref.pretty(), 
      offset_start=ref.indices().start, offset_end=ref.indices().end, 
      user=request.user)
  new_ref.save()
  return HttpResponseRedirect(reverse('tagref_detail', args=(tag_name, str(new_ref.id))));
开发者ID:Web5design,项目名称:nutritious,代码行数:30,代码来源:views.py

示例6: test_tag_suggestion_missing

 def test_tag_suggestion_missing(self):
     self.assertEqual(Tag.all().count(), 0)
     # Create tags but not all suggestions.
     Reminder(key_name='a-b', title='a b', tags='a b'.split()).put()
     Tag(key_name='a', count=2, suggestions='a-b a-c'.split()).put()
     Tag(key_name='b', count=2, suggestions='b-c'.split()).put()
     self.assertEqual(Tag.all().count(), 2)
     # Check that the missing suggestions are detected.
     response = self.client.get('/consistency/')
     self.assertTrue('tag_suggestion_missing'
                     in response.context['problems'])
     self.assertTrue("Tag a references missing suggestion a-c."
                     in response.content)
     self.assertTrue("Tag b references missing suggestion b-c."
                     in response.content)
     # Simulate button click to fix this problem.
     response = self.client.post('/consistency/', {
             'tag_suggestion_missing': "Create missing"})
     self.assertRedirects(response, '/consistency/')
     # Check that the references are now gone.
     self.assertEqual(Tag.all().count(), 1)
     self.assertEqual(Tag.get_by_key_name('a').count, 1)
     self.assertEqual(len(Tag.get_by_key_name('a').suggestions), 1)
     response = self.client.get('/consistency/')
     self.assertFalse('tag_suggestion_missing'
                      in response.context['problems'])
开发者ID:jcrocholl,项目名称:minderbot,代码行数:26,代码来源:tests.py

示例7: test_suggestion_tag_reverse

 def test_suggestion_tag_reverse(self):
     # Create a suggestion and tags but with a missing reverse reference.
     Reminder(key_name='a-b', title='a b', tags='a b'.split()).put()
     Reminder(key_name='b-c', title='b c', tags='b'.split()).put()
     Tag(key_name='a', suggestions='a-b'.split(), count=0).put()
     Tag(key_name='b', suggestions='b-c'.split(), count=0).put()
     self.assertEqual(Reminder.all().count(), 2)
     self.assertEqual(Tag.all().count(), 2)
     self.assertEqual(len(Tag.get_by_key_name('b').suggestions), 1)
     # Check that the missing tag-reminder reference is detected.
     response = self.client.get('/consistency/')
     self.assertTrue('suggestion_tag_reverse'
                     in response.context['problems'])
     self.assertTrue("Suggestion a-b references b but not reverse."
                     in response.content)
     # Simulate button click to fix this problem.
     response = self.client.post('/consistency/', {
             'suggestion_tag_reverse': "Create reverse references"})
     self.assertRedirects(response, '/consistency/')
     # Check that the tags are now existing.
     self.assertEqual(Reminder.all().count(), 2)
     self.assertEqual(Tag.all().count(), 2)
     self.assertEqual(len(Tag.get_by_key_name('b').suggestions), 2)
     response = self.client.get('/consistency/')
     self.assertFalse('suggestion_tag_reverse'
                      in response.context['problems'])
开发者ID:jcrocholl,项目名称:minderbot,代码行数:26,代码来源:tests.py

示例8: post_save

def post_save(post, args, request):
    post.url = args.get('url')
    post.title = args.get('title')
    post.body = args.get('body')
    post.published_at = args.get('published_at')
    post.save(request=request)

    post.tags.clear()
    from tags.models import Tag
    tags_raw = args.get('tags', '')
    for tag_title in tags_raw.split(','):
        tag_title = tag_title.strip(' \t\n\r')
        tag_slug = slugify(tag_title)

        if len(tag_title) == 0:
            # don't save empty tag
            continue

        try:
            tag = Tag.objects.get(slug=tag_slug)
        except Tag.DoesNotExist:
            tag = Tag(
                title=tag_title,
                slug=tag_slug,
            )
            tag.save(request=request)
        post.tags.add(tag.document)

    return post
开发者ID:naturebismo,项目名称:backend,代码行数:29,代码来源:mutations.py

示例9: submit_suggestion

def submit_suggestion(request, suggestion_form):
    """
    Save a new suggestion in the database.
    """
    slug = suggestion_form.cleaned_data['slug']
    tag_list = suggestion_form.cleaned_data['tags'].split()
    for tag_name in tag_list:
        tag = Tag.get_by_key_name(tag_name)
        if tag is None:
            tag = Tag(key_name=tag_name, count=0)
        tag.suggestions.append(slug)
        tag.count += 1
        tag.put()
    suggestion = Reminder(
        key_name=slug,
        title=suggestion_form.cleaned_data['title'],
        days=suggestion_form.cleaned_data['days'],
        months=suggestion_form.cleaned_data['months'],
        years=suggestion_form.cleaned_data['years'],
        miles=suggestion_form.cleaned_data['miles'],
        kilometers=suggestion_form.cleaned_data['kilometers'],
        tags=tag_list)
    logging.debug(suggestion)
    suggestion.put()
    return HttpResponseRedirect(suggestion.get_absolute_url())
开发者ID:jcrocholl,项目名称:minderbot,代码行数:25,代码来源:views.py

示例10: test_remove_tag_button

 def test_remove_tag_button(self):
     self.client.login(username='[email protected]', password='password')
     tag = Tag(tag_text='f')
     tag.save()
     AddonTag(addon=Addon.objects.get(pk=3615), tag=tag, user_id=999).save()
     r = self.client.get(reverse('addons.detail', args=[3615]))
     doc = pq(r.content)
     assert len(doc('#tags li input.removetag'))
开发者ID:ozten,项目名称:zamboni,代码行数:8,代码来源:test_views.py

示例11: test_bookmarks_get_delete_url_returns_correct_url

def test_bookmarks_get_delete_url_returns_correct_url():
    user = make_users(1)[0]
    tag = Tag(title='Test Tag', slug='test-tag', user=user)
    tag.save()
    Bookmark(title='Test Bookmark', slug='test-bookmark', tag=tag,
             url="http://www.testers.com", user=user).save()
    bookmark = Bookmark.objects.get(pk=1)
    assert bookmark.get_delete_url() == '/bookmarks/delete/test-tag/test-bookmark/'
开发者ID:dansackett,项目名称:mydash,代码行数:8,代码来源:test_models.py

示例12: test_bookmarks_unicode_method_returns_title_correctly

def test_bookmarks_unicode_method_returns_title_correctly():
    user = make_users(1)[0]
    tag = Tag(title='Test Tag', slug='test-tag', user=user)
    tag.save()
    Bookmark(title='Test Bookmark', slug='test-bookmark', tag=tag,
             url="http://www.testers.com", user=user).save()
    bookmark = Bookmark.objects.get(pk=1)
    assert bookmark.__unicode__() == 'Test Bookmark'
开发者ID:dansackett,项目名称:mydash,代码行数:8,代码来源:test_models.py

示例13: create_tag

def create_tag(request):
    name_zh = request.REQUEST.get('name_zh', '')
    description = request.REQUEST.get('desc', '')
    if not name_zh:
        raise Http404()

    Tag.create_tag(name_zh=name_zh, description=description)
    return HttpResponse("Success")
开发者ID:chenchiyuan,项目名称:instant_search,代码行数:8,代码来源:views.py

示例14: test_edit_tag_form_is_valid

def test_edit_tag_form_is_valid():
    user = make_users(1)[0]
    tag = Tag(title='title', user=user)
    tag.save()
    form = EditTagForm({
        'title': 'test',
    }, user=user, instance=tag)
    assert form.is_valid()
开发者ID:dansackett,项目名称:mydash,代码行数:8,代码来源:test_forms.py

示例15: test_edit_tag_form_is_invalid_due_to_no_title

def test_edit_tag_form_is_invalid_due_to_no_title():
    user = make_users(1)[0]
    tag = Tag(title='title', user=user)
    tag.save()
    form = EditTagForm({
        'title': '',
    }, user=user, instance=tag)
    assert not form.is_valid()
    assert ['title'] == form.errors.keys()
开发者ID:dansackett,项目名称:mydash,代码行数:9,代码来源:test_forms.py


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