Beispiel #1
0
def save_data(s3client, field, bucket, key):
    for data in read_fields(s3client, field, bucket, key):
        tag = Tag()
        tag.name = data.strip()
        try:
            tag.save(force_insert=True)
        except IntegrityError:
            pass
Beispiel #2
0
    def post(self):
        """Creates a new tag for the logged in user"""
        user = utils.get_current_user()
        title = self.request.get('title')
        new_title = self.request.get('newTitle') or None
        
        if not user:
            self.error(403)
            return
        
        if not title:
            self.error(400)

        # Create new tag
        if not new_title:
            m = Tag.all().ancestor(user).filter('title_lower =', title.lower()).get()
            
            if m:
                # Not unique
                self.error(409)
                return

            m = Tag(
                parent=user,
                title=title,
                title_lower=title.lower(),
            )
            m.put()

        # Rename Tag
        else:
            m = Tag.all().ancestor(user).filter('title_lower =', new_title.lower()).get()
            if m:
                # Not unique
                self.error(409)
                return

            m = Tag.all().ancestor(user).filter('title_lower =', title.lower()).get()
            if not m:
                # Original tag not found
                self.error(404)
                return

            m.title = new_title
            m.title_lower = new_title.lower()
            m.save()

        self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
        self.response.headers['Access-Control-Allow-Origin'] = '*'
        self.response.out.write('ok')
Beispiel #3
0
def api_article_add(*, request, title, category, tag, content, summary):
    r = web.Response()
    blog = Blogs(title = title, user_id = getWebCookie(request, 'id'), summary = summary, content = content)
    id = yield from blog.save()
    category = urldecode(category)
    category = category[0].split(',')
    tags = tag.split('/')
    if id > 0:
        #文章分类插入
        for i in category:
            blog_category = BlogCategory(blog_id = id, category_id = i)
            blog_category_id = yield from blog_category.save()
        #标签分类插入
        for t in tags:
            t = t.strip()
            tag_title = yield from Tag.findAll('title=?', [t])
            #如果标签存在,则插入博客标签表,若不存在,则两张表都要插入
            if len(tag_title) > 0:
                tag_id = tag_title[0].get('id')
            else:
                tag = Tag(title = t)
                tag_id = yield from tag.save()
            blog_tag = BlogTag(blog_id = id, tag_id = tag_id)
            blog_tag_id = yield from blog_tag.save()
    if id > 0 and blog_category_id > 0 and blog_tag_id > 0:
        result = APIResult(1, '', '发布成功')
    else:
        result = APIResult(0, '', '发布失败')
    return jsonResult(r, result)
Beispiel #4
0
 def addTag(self, noteId, strTag):
     count = Tag.select().where(Tag.tag == strTag).count()
     if (count == 0):
         dbTag = Tag()
         dbTag.creationDate = dbTag.modificationDate = datetime.date.today()
         dbTag.tag = strTag
         dbTag.save()
     else:
         dbTag = Tag.get(Tag.tag == strTag)
         
     note = Note.get(Note.id == noteId)
     noteTag = NoteTag()
     noteTag.note = note
     noteTag.tag = dbTag
     noteTag.creationDate = noteTag.modificationDate = datetime.date.today()
     noteTag.save() 
     
     self.view.execute_script("notesMD.tags = " + RuntimeSettings.getTags())
Beispiel #5
0
def api_article_edit(*, request, id, title, category, tag, content, summary):
    r = web.Response()
    blog = yield from Blogs.findOne(id)
    blog = Blogs(id = id, title = title, summary = summary, content = content, update_time = currentTime(), create_time = blog.get('create_time'), user_id = blog.get('user_id'), view_count = blog.get('view_count'))
    result = yield from blog.update()
    category = urldecode(category)
    category = category[0].split(',')
    tags = tag.split('/')
    blog_category_id = 0
    blog_tag_id = 0
    if result > 0:
        #文章分类插入
        blog_category_sql = 'delete from blog_category where blog_id = ?'
        yield from execute(blog_category_sql, [id])
        blog_tag_sql = 'delete from blog_tag where blog_id = ?'
        yield from execute(blog_tag_sql, [id])

        for i in category:
            blog_category = BlogCategory(blog_id = id, category_id = i)
            blog_category_id = yield from blog_category.save()
        #标签分类插入
        for t in tags:
            t = t.strip()
            tag_title = yield from Tag.findAll('title=?', [t])
            #如果标签存在,则插入博客标签表,若不存在,则两张表都要插入
            if len(tag_title) > 0:
                tag_id = tag_title[0].get('id')
            else:
                tag = Tag(title = t)
                tag_id = yield from tag.save()
            blog_tag = BlogTag(blog_id = id, tag_id = tag_id)
            blog_tag_id = yield from blog_tag.save()
    if int(id) > 0 and int(blog_category_id) > 0 and int(blog_tag_id) > 0:
        result = APIResult(1, '', '修改成功')
    else:
        result = APIResult(0, '', '修改失败')
    return jsonResult(r, result)