Exemplo n.º 1
0
 def comment_to_json(self, c):
     data = {
         'id': c.id,
         'thread': {
             'id': c.parent_id,
             'url': c.parent.get_absolute_url(),
         },
         'page': comments.order_to_page(c.order),
         'url': c.get_absolute_url() if c.id else None,
         'title': html.escape(c.title),
         'body': bbcodes.bbcode(c.body),
         'user': self.role_to_json(c.role_id, detailed=True),
         'create_time': c.create_time,
         'edit_right': self.comment_edit_right(c),
         'is_thread': c.is_thread(),
         'edit_time': c.edit_time,
         'editor': self.role_to_json(c.edit_role_id) if c.editor else None,
         'media': c.media,
         'reply_id': c.reply_id,
     }
     comment_signals.to_json.send(self.comment_model,
                                  comment=c,
                                  data=data,
                                  view=self)
     return data
Exemplo n.º 2
0
 def room_to_json(self, thread):
     data = {
         'id':
         thread.pk,
         'title':
         html.escape(thread.title),
         'body':
         bbcodes.bbcode(thread.body),
         'room':
         thread.room,
         'deleted':
         thread.deleted,
         'important':
         thread.important,
         'closed':
         thread.closed,
         'user':
         thread.user.to_json(),
         'moderators': [user.to_json() for user in thread.moderators],
         'accessed_users':
         None if thread.accessed_users is None else
         [user.to_json() for user in thread.accessed_users],
         'threads_count':
         thread.threads_count if thread.room else None,
         'url':
         thread.get_absolute_url(),
     }
     signals.room_to_json.send(self.thread_model,
                               instance=thread,
                               response=data,
                               view=self)
     return data
Exemplo n.º 3
0
def test_smiles(smiles):
    original = '<p><img alt=":angel:" src="/media/wysibb/smiles/angel.gif"'\
        ' style="height:26px; width:27px" title=":angel:" /></p>'
    converted = html_converter.html_to_bb(original)
    result = bbcodes.bbcode(converted)
    assert result == '<img class="sm" src="/media/wysibb/smiles/angel.gif"' \
                     ' title="angel" /><br/>'
Exemplo n.º 4
0
def create_voting(data):
    return {
        'name': bbcodes.bbcode(html_converter.html_to_bb(data['name'])),
        'body': bbcodes.bbcode(html_converter.html_to_bb(data['body'])),
        'closed': False,
        'show_results': bool(data['show_results']),
        'preview_results': bool(data['preview_results']),
        'choices': {
            'items': [{
                'id': i,
                'name': html.escape(item['name']),
                'count': 0,
                'percent': 0,
            } for i, item in enumerate(data['choices']['items'])],
            'votes':
            0,
        },
    }
Exemplo n.º 5
0
 def to_json(self, detailed=False):
     data = {
         'id': self.pk,
         'title': html.escape(self.username),
         'url': self.get_absolute_url(),
     }
     if detailed:
         data.update({
             'sex': self.sex,
             'avatar': self.avatar.url if self.avatar else '',
             'full_stars': self.full_stars(),  # TODO optimize it
             'rank': html.escape(self.rank),
             'stories_author': self.stories_author,
             'signature': bbcodes.bbcode(self.signature),
         })
     signals.user_to_json.send(User,
                               instance=self,
                               response=data,
                               detailed=detailed)
     return data
Exemplo n.º 6
0
 def obj_to_json(self, deleted=False):
     data = {
         'id':
         self.obj.pk,
         'tree_id':
         self.obj.tree_id,
         'title':
         self.obj.title,
         'body':
         bbcodes.bbcode(self.obj.body),
         'room':
         self.obj.room,
         'deleted':
         self.obj.deleted,
         'url':
         self.obj.get_absolute_url() if self.obj.pk else None,
         'parents': [{
             'id': parent.id,
             'title': parent.title,
             'url': parent.get_absolute_url(),
         } for parent in self.obj.get_ancestors()] if self.obj.pk else None,
         'rights':
         self.obj.rights_to_json(self.user),
         'default_rights':
         self.obj.default_rights,
     }
     if self.obj.room:
         data['rooms'] = [
             self.room_to_json(t)
             for t in self.get_subthreads(True, deleted)
         ]
         data['threads'] = [
             self.room_to_json(t)
             for t in self.get_subthreads(False, deleted)
         ]
     else:
         data['closed'] = self.obj.closed
         data['important'] = self.obj.important
         data['user'] = self.obj.user.to_json(detailed=True)
         data['media'] = self.obj.media
     return data
Exemplo n.º 7
0
def test_special_symbols(smiles):
    original = '&Iuml;'
    converted = html_converter.html_to_bb(original)
    assert bbcodes.bbcode(converted) == original