コード例 #1
0
ファイル: test_models.py プロジェクト: caogecym/muer
 def test_tag(self):
     logger.info('start testing test_tag...')
     post = Post.objects.get(title='test_post')
     user = post.author
     # tag1 no author
     tag1 = Tag(name='cold')
     tag1.save()
     # tag2 with author
     tag2 = Tag(name='science', author=user)
     tag2.save()
     post.tags.add(tag1)
     post.tags.add(tag2)
     self.assertEqual(len(post.tags.all()), 2)
コード例 #2
0
ファイル: consumers.py プロジェクト: taoxinyi/ProCampus
 def add_tag_to_db(self, request_person_id, reply_person_id, tag_list):
     for tag in tag_list:
         query_result = Tag.objects.all().filter(
             from_user_id=request_person_id,
             to_user_id=reply_person_id,
             tag=tag)
         if len(query_result) == 0:
             Tag(from_user_id=request_person_id,
                 to_user_id=reply_person_id,
                 tag=tag).save()
         else:
             query_result.delete()
コード例 #3
0
ファイル: ajax.py プロジェクト: Magnie/parallel
def create_tag(request):
    """
    desc: Create a new tag
    params: str tag_name, array(int tag_id) sub_tags,
    return: bool success, str tag_name, id tag_id
    """
    response = {
        'success': False,
        'tag_name': '',
        'tag_id': -1
    }
    
    # Validate input
    if valid_request(request):
        tag_name = request.POST['tag_name']
        parent_id = request.POST['parent_id']
        post_date = timezone.now()
        
        if tag_name and parent_id:
            # Create new tag and update parent tag with new tag.
            parent_tag = Tag.objects.filter(id=parent_id)
            new_tag = Tag(
                name=tag_name
            )
            new_tag.save()
            
            parent_tag.tags.add(new_tag)
            parent_tag.save()
            
            # Set response
            response['tag_name'] = new_tag.name
            response['tag_id'] = new_tag.id
            
            # Everything was successful!
            response['success'] = True
    
    # Return results
    return JsonResponse(response)
コード例 #4
0
ファイル: test_models.py プロジェクト: caogecym/muer
 def test_tag(self):
     logger.info('start testing test_tag...')
     post = Post.objects.get(title='test_post')
     user = post.author
     # tag1 no author
     tag1 = Tag(name='cold')
     tag1.save()
     # tag2 with author
     tag2 = Tag(name='science', author=user)
     tag2.save()
     post.tags.add(tag1)
     post.tags.add(tag2)
     self.assertEqual(len(post.tags.all()), 2)
コード例 #5
0
def slugify_tag(value):
    return Tag.get_slug(value)
コード例 #6
0
ファイル: extra_tags.py プロジェクト: karoldvl/meltdown-pl
def slugify_tag(value):
    return Tag.get_slug(value)