Exemplo n.º 1
0
 def update(self, data):
     for k, v in list(data.items()):
         if not v and (k == 'description' or k == 'style'):
             v = ''
         if k == 'style' and v:
             v = strip_tags(v)
         setattr(self, k, v)
     self.summary = strip_tags(self.description)
     try:
         orm.commit()
     except:
         pass
     return self
Exemplo n.º 2
0
 def update(self, data):
     for k, v in data.items():
         if not v and (k == 'description' or k == 'style'):
             v = ''
         if k == 'style' and v:
             v = strip_tags(v)
         setattr(self, k, v)
     self.summary = strip_tags(self.description)
     try:
         orm.commit()
     except:
         pass
     return self
Exemplo n.º 3
0
 def validate_content(self, field):
     """ 为了照顾一图流
     """
     if field.data.find('<img class="upload-reply-image"') == -1 and\
        field.data.find('<embed type="application') == -1:
         data = strip_tags(field.data)
         if len(data) < 3:
             raise ValidationError('内容至少 3 字符')
Exemplo n.º 4
0
 def validate_content(self, field):
     """ 为了照顾一图流
     """
     if field.data.find('<img class="upload-topic-image"') == -1 and\
        field.data.find('<embed type="application') == -1:
         data = strip_tags(field.data)
         if len(data) < 3:
             raise ValidationError('内容至少 3 字符')
Exemplo n.º 5
0
 def to_simple_dict(self):
     return dict(
         id=self.id,
         content=self.content,
         clean_content=strip_tags(self.content),
         reply_count=self.reply_count,
         has_image=self.has_img == 'true',
         created_at=self.created_at,
         created=self.created,
     )
Exemplo n.º 6
0
 def to_simple_dict(self):
     return dict(
         id=self.id,
         content=self.content,
         clean_content=strip_tags(self.content),
         reply_count=self.reply_count,
         has_image=self.has_img == 'true',
         created_at=self.created_at,
         created=self.created,
     )
Exemplo n.º 7
0
    def post(self):
        if not self.has_permission:
            return
        user = self.current_user
        name = self.get_argument('name', None)
        name = strip_tags(name)
        if not name:
            return self.send_error_result(msg=u'没有填写专辑名')

        if len(name) >= 10:
            return self.send_error_result(msg=u'专辑名不能超过 10 个字符')

        album = Album(name=name, user_id=user.id).save()
        return self.send_success_result(**album.to_dict())
Exemplo n.º 8
0
 def update(self, data):
     if data.get('nickname') != self.nickname:
         self.edit_nickname_count -= 1
     if data.get('urlname') != self.urlname:
         self.edit_urlname_count -= 1
     for k, v in data.iteritems():
         if not v and k in ['address', 'website', 'description', 'style',
                            'site_style']:
             v = ''
         if v and k in ['style', 'site_style']:
             v = strip_tags(v)
         setattr(self, k, v)
     try:
         orm.commit()
     except:
         pass
     return self
Exemplo n.º 9
0
 def post(self):
     user = self.current_user
     content = self.get_argument('content', None)
     image_ids = self.get_argument('image_ids', None)
     images = []
     if not (content and len(strip_tags(content)) >= 3):
         result = {
             'status': 'error',
             'message': '推文内容至少 3 字符'
         }
         return self.send_result(result, '/timeline')
     tweet = Tweet(content=strip_xss_tags(content), user_id=user.id).save()
     tweet.put_notifier()
     if image_ids:
         image_ids = image_ids.split(',')
         for image_id in image_ids:
             image_id = int(image_id)
             image = Image.get(id=image_id)
             if not image:
                 continue
             image.tweet_id = tweet.id
             images.append({
                 'id': image.id,
                 'path': image.path,
                 'width': image.width,
                 'height': image.height,
             })
     if images:
         tweet.has_img = 'true'
     result = {
         'status': 'success',
         'message': '推文创建成功',
         'content': tweet.content,
         'name': tweet.author.name,
         'nickname': tweet.author.nickname,
         'author_avatar': tweet.author.get_avatar(size=48),
         'author_url': tweet.author.url,
         'author_name': tweet.author.name,
         'author_nickname': tweet.author.nickname,
         'tweet_url': tweet.url,
         'created': tweet.created,
         'id': tweet.id,
         'images': images,
     }
     return self.send_result(result, '/timeline')
Exemplo n.º 10
0
    def save(self, category='create', user=None):
        now = int(time.time())

        if category == 'create':
            self.created_at = now

        if not user:
            user = self.author

        if self.description:
            self.summary = strip_tags(self.description)

        self.updated_at = now
        self.active = now

        if user:
            user.active = now

        return super(Node, self).save()
Exemplo n.º 11
0
    def save(self, category='create', user=None):
        now = int(time.time())

        if category == 'create':
            self.created_at = now

        if not user:
            user = self.author

        if self.description:
            self.summary = strip_tags(self.description)

        self.updated_at = now
        self.active = now

        if user:
            user.active = now

        return super(Node, self).save()
Exemplo n.º 12
0
 def post(self):
     user = self.current_user
     content = self.get_argument('content', None)
     image_ids = self.get_argument('image_ids', None)
     images = []
     if not (content and len(strip_tags(content)) >= 3):
         result = {'status': 'error', 'message': '推文内容至少 3 字符'}
         return self.send_result(result, '/timeline')
     tweet = Tweet(content=strip_xss_tags(content), user_id=user.id).save()
     tweet.put_notifier()
     if image_ids:
         image_ids = image_ids.split(',')
         for image_id in image_ids:
             image_id = int(image_id)
             image = Image.get(id=image_id)
             if not image:
                 continue
             image.tweet_id = tweet.id
             images.append({
                 'id': image.id,
                 'path': image.path,
                 'width': image.width,
                 'height': image.height,
             })
     if images:
         tweet.has_img = 'true'
     result = {
         'status': 'success',
         'message': '推文创建成功',
         'content': tweet.content,
         'name': tweet.author.name,
         'nickname': tweet.author.nickname,
         'author_avatar': tweet.author.get_avatar(size=48),
         'author_url': tweet.author.url,
         'author_name': tweet.author.name,
         'author_nickname': tweet.author.nickname,
         'tweet_url': tweet.url,
         'created': tweet.created,
         'id': tweet.id,
         'images': images,
     }
     return self.send_result(result, '/timeline')