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


Python models.Tag类代码示例

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


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

示例1: tag_helper

def tag_helper(data, name_field, dataset, tag):
    mps = MapPoint.objects.filter(dataset_id=dataset)
    tags = Tag.objects.filter(dataset_id=dataset).filter(tag=tag)
    if tags.count() > 1:
        appr_tags = tags.filter(approved=True)
        if appr_tags.count() > 0:
            tags = appr_tags
        tag = tags[0]
    elif tags.count() == 0:
        tag = Tag(dataset_id=dataset, tag=tag, approved=True)
        tag.save()
    else:
        tag = tags[0]

    regex = re.compile('[%s]' % re.escape(string.punctuation))
    for item in data:
        name = regex.sub(r'[\'\'\.-]*', item[name_field])
        print name
        for mp in mps.filter(name__iregex=name):
            print mp.name
            t = TagIndiv(tag=tag, mapelement=mp)
            try:
                t.save()
            except IntegrityError:
                # violate unique restraint so just don't save it
                pass
开发者ID:CSnap,项目名称:SGIS-backend,代码行数:26,代码来源:load.py

示例2: get

 def get(self, name = ''):
     objs = Tag.get_tag_page_posts(name, 1)
     
     catobj = Tag.get_tag_by_name(name)
     if catobj:
         pass
     else:
         self.redirect(BASE_URL)
         return
     
     allpost =  catobj.id_num
     allpage = allpost/EACH_PAGE_POST_NUM
     if allpost%EACH_PAGE_POST_NUM:
         allpage += 1
         
     output = self.render('index.html', {
         'title': "%s - %s"%( catobj.name, SITE_TITLE),
         'keywords':catobj.name,
         'description':SITE_DECR,
         'objs': objs,
         'cats': Category.get_all_cat_name(),
         'tags': Tag.get_hot_tag_name(),
         'page': 1,
         'allpage': allpage,
         'listtype': 'tag',
         'name': name,
         'namemd5': md5(name.encode('utf-8')).hexdigest(),
         'comments': Comment.get_recent_comments(),
         'links':Link.get_all_links(),
     },layout='_layout.html')
     self.write(output)
     return output
开发者ID:wing1000,项目名称:wb3,代码行数:32,代码来源:blog.py

示例3: upload_new_question

def upload_new_question(question_source, question, tags):
    new_question = Question(question = question, question_source=question_source)
    new_question.save()
    tags_final = []

    for tag in tags:
        try:
            search_tag = Tag.objects.get(tag=tag)
            tags_final.append(search_tag)
            continue
        except Tag.DoesNotExist:
            new_tag = Tag(tag=tag)
            new_tag.save()
            tags_final.append(new_tag)
            continue
        continue
    
    for tag in tags_final:
        print tag.tag

    for tag in tags_final:
        tag.questions.append(new_question)
        tag.save()
        continue

    return new_question.id
开发者ID:YNCHacks,项目名称:Qanda,代码行数:26,代码来源:views.py

示例4: setUp

 def setUp(self):
     # Create a few Authors.
     self.au1 = Author(name="Author 1")
     self.au1.save()
     self.au2 = Author(name="Author 2")
     self.au2.save()
     # Create a couple of Articles.
     self.a1 = Article(headline="Article 1", pub_date=datetime(2005, 7, 26), author=self.au1)
     self.a1.save()
     self.a2 = Article(headline="Article 2", pub_date=datetime(2005, 7, 27), author=self.au1)
     self.a2.save()
     self.a3 = Article(headline="Article 3", pub_date=datetime(2005, 7, 27), author=self.au1)
     self.a3.save()
     self.a4 = Article(headline="Article 4", pub_date=datetime(2005, 7, 28), author=self.au1)
     self.a4.save()
     self.a5 = Article(headline="Article 5", pub_date=datetime(2005, 8, 1, 9, 0), author=self.au2)
     self.a5.save()
     self.a6 = Article(headline="Article 6", pub_date=datetime(2005, 8, 1, 8, 0), author=self.au2)
     self.a6.save()
     self.a7 = Article(headline="Article 7", pub_date=datetime(2005, 7, 27), author=self.au2)
     self.a7.save()
     # Create a few Tags.
     self.t1 = Tag(name="Tag 1")
     self.t1.save()
     self.t1.articles.add(self.a1, self.a2, self.a3)
     self.t2 = Tag(name="Tag 2")
     self.t2.save()
     self.t2.articles.add(self.a3, self.a4, self.a5)
     self.t3 = Tag(name="Tag 3")
     self.t3.save()
     self.t3.articles.add(self.a5, self.a6, self.a7)
开发者ID:JWW81,项目名称:stochss,代码行数:31,代码来源:tests.py

示例5: tag_handler

def tag_handler(tag_id):
    if request.method == 'GET':
        tag = Tag.get(tag_id)
        if tag is not None:
            return jsonify(tag=[tag.serialize])
        else:
            raise InvalidUsage('Not Found', status_code=404)
    if request.method == 'PUT':
        tag = Tag.get(tag_id)
        if tag is not None:
            name = request.args.get('name')
            description = request.args.get('description')
            updated_tag = tag.update(name, description)
            return jsonify(tag=[updated_tag.serialize])
        else:
            raise InvalidUsage('Not Found', status_code=404)
    if request.method == 'DELETE':
        tag = Tag.get(tag_id)
        if tag is not None:
            deleted = tag.delete()
            if deleted:
                return jsonify(status='OK')
            else:
                raise InvalidUsage('Unknown Error', status_code=520)
        else:
            raise InvalidUsage('Not Found', status_code=404)
开发者ID:jonanone,项目名称:favmapp-api,代码行数:26,代码来源:api.py

示例6: get_all_tag

def get_all_tag():
    resp = Resp()
    tag_columns = Tag.get_columns()
    tag_columns.remove("instances")
    result = Tag.get_all(*tag_columns)
    resp.data = result
    return resp
开发者ID:i19,项目名称:tagger,代码行数:7,代码来源:web.py

示例7: ask_display

def ask_display(request):
        if not request.user.is_authenticated():
            raise PermissionDenied

        if request.method == 'POST':

            request_title = request.POST.get('title')
            request_text = request.POST.get('text')
            request_tags = request.POST.get('tags')
            
            if request_title == '' or request_text == '':
                return render(request, 'ask.html', {'page_title': 'New Question', 'errors': '1'})
            
            new_question = Question(title = request_title, 
                date = datetime.datetime.now(), 
                author = UserProfile.objects.get(user_account = request.user),
                text = request_text)
            
            new_question.save()
            
            for tag_str in request_tags.split(','):
                if Tag.objects.filter(name = tag_str).exists():
                    tag = Tag.objects.get(name = tag_str)
                    new_question.tags.add(tag)
                else:
                    new_tag = Tag(name = tag_str)
                    new_tag.save()
                    new_question.tags.add(new_tag)
            
            return HttpResponseRedirect('/question/{}'.format(new_question.id))
            
        return render(request, 'ask.html', {'page_title': 'New Question', 'errors': '0'})
开发者ID:TimeEscaper,项目名称:Ask_AI_TP-mail.ru,代码行数:32,代码来源:views.py

示例8: post_new_post

def post_new_post():
    title = request.forms.get('title').decode('utf-8')
    slug = request.forms.get('slug').decode('utf-8')
    post = request.forms.get('post')
    tags = request.forms.get('tags').decode('utf-8')
    category = request.forms.get('category').decode('utf-8')
    post_type = request.forms.get('postype')
    set_time = request.forms.get('setime')
    if set_time != '1':
        t = [int(tt) for tt in set_time.split('-')]
        d = datetime.datetime(*t)
        published = d
    else:
        published = datetime.datetime.now()

    if post_type == 'HTML':
        is_html = 1
        content = post.decode('utf-8')
        markdown = u'html'
    else:
        is_html = 0
        markdown = post.decode('utf-8')
        content = to_markdown(markdown)
    category = Category.get(name=category)
    post = Post.create(title=title, slug=slug.strip(), content=content,
                       markdown=markdown, tags=tags, category=category,
                       is_html=is_html, published=published, comm_count=0)
    for tag in post.tags_list():
        Tag.create(name=tag.strip(), post_id=post.id)
    redirect("/%s" % slug)
开发者ID:iTriumph,项目名称:MiniAkio,代码行数:30,代码来源:blog.py

示例9: post_update_post

def post_update_post(id):
    postid = request.forms.get('postid')
    title = request.forms.get('title').decode('utf-8')
    slug = request.forms.get('slug').decode('utf-8')
    post = request.forms.get('post')
    tags = request.forms.get('tags').decode('utf-8')
    category = request.forms.get('category').decode('utf-8')
    post_type = request.forms.get('postype')
    if post_type == 'HTML':
        is_html = 1
        content = post.decode('utf-8')
        markdown = u'html'
    else:
        is_html = 0
        markdown = post.decode('utf-8')
        content = to_markdown(markdown)
    category = Category.get(name=category)
    Post.update(title=title, slug=slug, content=content, markdown=markdown,
                tags=tags, category=category,
                is_html=is_html).where(id=postid).execute()
    tag_list = set(tags.split(","))
    for tag in tag_list:
        try:
            Tag.get(name=tag.strip(), post_id=postid)
        except Post.DoesNotExist:
            Tag.create(name=tag.strip(), post_id=postid)
    redirect("/%s" % slug)
开发者ID:iTriumph,项目名称:MiniAkio,代码行数:27,代码来源:blog.py

示例10: test_update

    def test_update(self):
        order = Order(name='Dummy Order')
        order.save()

        for i in range(2):
            item = Item(name='Item %i' % i, sku=str(i) * 13, price=D('9.99'), order=order, status=0)
            item.save()

        tag = Tag(name='Test', content_object=order)
        tag.save()

        res = self.client.get('/inlines/1/')

        self.assertEqual(res.status_code, 200)
        order = Order.objects.get(id=1)

        self.assertEquals(2, order.item_set.count())
        self.assertEquals('Item 0', order.item_set.all()[0].name)

        data = {
            'name': u'Dummy Order',
            'item_set-TOTAL_FORMS': u'4',
            'item_set-INITIAL_FORMS': u'2',
            'item_set-MAX_NUM_FORMS': u'',
            'item_set-0-name': 'Bubble Bath',
            'item_set-0-sku': '1234567890123',
            'item_set-0-price': D('9.99'),
            'item_set-0-status': 0,
            'item_set-0-order': 1,
            'item_set-0-id': 1,
            'item_set-1-name': 'Bubble Bath',
            'item_set-1-sku': '1234567890123',
            'item_set-1-price': D('9.99'),
            'item_set-1-status': 0,
            'item_set-1-order': 1,
            'item_set-1-id': 2,
            'item_set-2-name': 'Bubble Bath',
            'item_set-2-sku': '1234567890123',
            'item_set-2-price': D('9.99'),
            'item_set-2-status': 0,
            'item_set-2-order': 1,
            'item_set-3-DELETE': True,
            'tests-tag-content_type-object_id-TOTAL_FORMS': 3,
            'tests-tag-content_type-object_id-INITIAL_FORMS': 1,
            'tests-tag-content_type-object_id-MAX_NUM_FORMS': u'',
            'tests-tag-content_type-object_id-0-name': u'Test',
            'tests-tag-content_type-object_id-0-id': 1,
            'tests-tag-content_type-object_id-0-DELETE': True,
            'tests-tag-content_type-object_id-1-name': u'Test 2',
            'tests-tag-content_type-object_id-2-name': u'Test 3',
        }

        res = self.client.post('/inlines/1/', data, follow=True)
        self.assertEqual(res.status_code, 200)

        order = Order.objects.get(id=1)

        self.assertEquals(3, order.item_set.count())
        self.assertEquals(2, Tag.objects.count())
        self.assertEquals('Bubble Bath', order.item_set.all()[0].name)
开发者ID:joshdrake,项目名称:django-extra-views,代码行数:60,代码来源:tests.py

示例11: test_update

    def test_update(self):
        order = Order(name="Dummy Order")
        order.save()

        for i in range(2):
            item = Item(name="Item %i" % i, sku=str(i) * 13, price=D("9.99"), order=order, status=0)
            item.save()

        tag = Tag(name="Test", content_object=order)
        tag.save()

        res = self.client.get("/inlines/1/")

        self.assertEqual(res.status_code, 200)
        order = Order.objects.get(id=1)

        self.assertEquals(2, order.item_set.count())
        self.assertEquals("Item 0", order.item_set.all()[0].name)

        data = {
            "name": u"Dummy Order",
            "item_set-TOTAL_FORMS": u"4",
            "item_set-INITIAL_FORMS": u"2",
            "item_set-MAX_NUM_FORMS": u"",
            "item_set-0-name": "Bubble Bath",
            "item_set-0-sku": "1234567890123",
            "item_set-0-price": D("9.99"),
            "item_set-0-status": 0,
            "item_set-0-order": 1,
            "item_set-0-id": 1,
            "item_set-1-name": "Bubble Bath",
            "item_set-1-sku": "1234567890123",
            "item_set-1-price": D("9.99"),
            "item_set-1-status": 0,
            "item_set-1-order": 1,
            "item_set-1-id": 2,
            "item_set-2-name": "Bubble Bath",
            "item_set-2-sku": "1234567890123",
            "item_set-2-price": D("9.99"),
            "item_set-2-status": 0,
            "item_set-2-order": 1,
            "item_set-3-DELETE": True,
            "tests-tag-content_type-object_id-TOTAL_FORMS": 3,
            "tests-tag-content_type-object_id-INITIAL_FORMS": 1,
            "tests-tag-content_type-object_id-MAX_NUM_FORMS": u"",
            "tests-tag-content_type-object_id-0-name": u"Test",
            "tests-tag-content_type-object_id-0-id": 1,
            "tests-tag-content_type-object_id-0-DELETE": True,
            "tests-tag-content_type-object_id-1-name": u"Test 2",
            "tests-tag-content_type-object_id-2-name": u"Test 3",
        }

        res = self.client.post("/inlines/1/", data, follow=True)
        self.assertEqual(res.status_code, 200)

        order = Order.objects.get(id=1)

        self.assertEquals(3, order.item_set.count())
        self.assertEquals(2, Tag.objects.count())
        self.assertEquals("Bubble Bath", order.item_set.all()[0].name)
开发者ID:MechanisM,项目名称:django-extra-views,代码行数:60,代码来源:tests.py

示例12: parse_page

    def parse_page(self, response):
        hxs = HtmlXPathSelector(response)
        title = hxs.select('//h1[@class="title"]/text()').extract()
        if title and isinstance(title, list):
            title = title[0]

        url = response.url
        tags = hxs.select('//dl[@id="viewExtCati"]/dd/a/text()').extract()
        items = hxs.select('//dd[@class="relative"]/div/a/@href').extract()
        try:
            pattern_items = [re.search(pattern, item) for item in items]
            related_items = [item.group(1) for item in pattern_items if item]
        except Exception as err:
            print(err)
            return
        try:
            num = response.request.meta['view_num']
        except Exception as err:
            print(err)
            return

        tag = Tag(name=title, url=url, num=num, tags=tags, related_items=related_items)
        try:
            print("parse title %s, view num: %s" %(title, num))
            tag.save()
        except Exception as err:
            print(err)
            return
开发者ID:chenchiyuan,项目名称:tags_spider,代码行数:28,代码来源:spider.py

示例13: post

    def post(self):
        update = self.request.get('update', False)
        cate_name = self.request.get('cate_name')
        tags_list = self.request.get_all('tags_name', [])
        title = self.request.get('title')
        blog = self.request.get('blog')
        if not blog:
            self.response.write('blog content empty!')

        cate = Category.query(Category.title==cate_name).get()
        if not cate:
            cate = Category(title=cate_name)
            cate.put()
        print tags_list
        tags = Tag.query(Tag.title.IN(tags_list)).fetch()
        tags_old = [tag.title for tag in tags]
        tags_new = []
        for tag in tags_list:
            if tag not in tags_old:
                tag = Tag(title=tag)
                tag.put()
                tags_new.append(tag)
        print tags
        print tags_new
        tags += tags_new
        print tags
        print '==='
        print dir(tags[0])
        tags = [tag.key for tag in tags]

        blog = Blog(title=title, text=blog, category=cate.key, tags=tags)
        blog.put()
        self.response.write('blog publish success')
        self.response.set_status(200)
开发者ID:hackrole,项目名称:gblog,代码行数:34,代码来源:blog.py

示例14: AlbumTest

class AlbumTest(TestCase):
    def setUp(self):
        self.user = User(username='sholmes', email='[email protected]',
                         first_name='Sherlock', last_name="Holmes",
                         password='watson')
        self.user.full_clean()
        self.user.save()
        self.photo = Photo(owner=self.user,
                           image='images/test.png',
                           name='test',
                           caption='testing')
        self.photo.clean()
        self.photo.save()
        self.tag = Tag(name='test tag', owner=self.user)
        self.tag.clean()
        self.tag.save()
        self.photo.tags.add(self.tag)
        self.album = Album(owner=self.user,
                           name='test album')
        self.album.clean()
        self.album.save()
        self.album.photos.add(self.photo)

    def test_id_creation(self):
        self.assertIsNotNone(self.album.id)

    def test_owner_entry(self):
        self.assertEqual(self.album.name, 'test album')

    def test_name_entry(self):
        self.assertEqual(self.photo.name, 'test')

    def test_album_to_photo_association(self):
        photos = Photo.objects.filter(album=self.album.id)
        self.assertEqual(photos[0].name, 'test')
开发者ID:jwhite007,项目名称:Photorize,代码行数:35,代码来源:test_models.py

示例15: editarticle

def editarticle(request,aid):
    article=Article.objects.get(id=aid)
    maincat=MainCat.objects.all()
    nart,cart,rart,cm,tg=getthree()
    if request.method=='POST':
        title=request.POST['title']
        tags=request.POST['tag']
        cat=request.POST['cat']
        content=request.POST['content']
        tags=tags.split(',')
        tagm=[]
        
        for i in tags:
            a=Tag.objects.filter(tag=i)
            if a:
                tagm.append(a[0])
            else:
                t=Tag(tag=i)
                t.save()
                tagm.append(t)
        article.user=request.user
        article.title=title
        article.content=content
        if cat.find('mc')>0:
            maincat=MainCat.objects.get(id=cat[:cat.find('m')])
            article.maincat=maincat
        elif cat.find('-')==-1:
            dcat=DetailCat.objects.get(id=cat)
            article.maincat=dcat.maincat
            article.detailcat=dcat
        else:
            pass
        article.save()
        article.tag=tagm
        article.save()
        return redirect(getarticle,article.id)
    
    #日历
    today=today=datetime.datetime.now()
    s=calendar.HTMLCalendar(6)
    cals=list(s.itermonthdays2(today.year,today.month))
    tdarts=Article.objects.values('id','createtime').filter(createtime__year=today.year,createtime__month=today.month).order_by('createtime') #列表字典[{'createtime': datetime.datetime(2014, 4, 6, 4, 36, 32, 896000, tzinfo=<UTC>)},
    tdart=set([i['createtime'].day for i in tdarts])

    tmpq=Article.objects.exclude(createtime__year=today.year,createtime__month=today.month)
    premon=tmpq.filter(createtime__lt=today).order_by('-createtime')[:1]
    aftmon=tmpq.filter(createtime__gt=today).order_by('createtime')[:1]
    
    tt=[]
    for i in cals:
        tt.append(list(i))
    ttt=[]   
    for a in tt:
        for i in tdart:
            if a[0] == i:
                a.append(1)
        if len(a)==2:
            a.append(0)    
        ttt.append(a)
    return render_to_response('new.htm',locals(),context_instance=RequestContext(request))
开发者ID:xiaoxiao777,项目名称:django_blog,代码行数:60,代码来源:views.py


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