예제 #1
0
파일: note.py 프로젝트: guoku/Raspberry
    def create(cls,
               entity_id,
               creator_id,
               note_text,
               score=0,
               image_data=None):
        if Note.user_add_note_already(entity_id, creator_id):
            raise Note.UserAddNoteForEntityAlready(entity_id, creator_id)

        _note_text = note_text.replace(u"#", "#")
        if image_data != None:
            _image_obj = Image.create(source='note_uploaded',
                                      image_data=image_data)
            _figure = _image_obj.image_id
        else:
            _figure = ''

        _note_obj = NoteModel.objects.create(entity_id=entity_id,
                                             creator_id=creator_id,
                                             note=_note_text,
                                             score=int(score),
                                             figure=_figure)

        _inst = cls(_note_obj.id)
        _inst.note_obj = _note_obj

        _tags = Tag.Parser.parse(_note_text)
        for _tag in _tags:
            Tag.add_entity_tag(entity_id=_note_obj.entity_id,
                               user_id=creator_id,
                               tag=_tag)

        return _inst
예제 #2
0
파일: note.py 프로젝트: guoku/Raspberry
    def add_comment(self,
                    comment_text,
                    creator_id,
                    reply_to_comment_id=None,
                    reply_to_user_id=None):
        _creator_id = int(creator_id)
        _comment_text = comment_text.replace(u"#", "#")
        _obj = NoteCommentModel.objects.create(
            note_id=self.note_id,
            comment=_comment_text,
            creator_id=_creator_id,
            replied_comment_id=reply_to_comment_id,
            replied_user_id=reply_to_user_id)
        self.comments[_obj.id] = _obj

        _context = self.__load_note_context_from_cache()
        if _context != None:
            _context['comment_id_list'].append(_obj.id)
            _context['comment_count'] = len(_context['comment_id_list'])
            _context = self.__reset_note_context_to_cache(_context)

        self.__ensure_note_obj()
        _tags = Tag.Parser.parse(_comment_text)
        for _tag in _tags:
            Tag.add_entity_tag(entity_id=self.note_obj.entity_id,
                               user_id=_creator_id,
                               tag=_tag)

        _creator = User(_creator_id)
        if _creator_id != self.note_obj.creator_id:
            CreateNoteCommentMessageTask.delay(
                user_id=self.note_obj.creator_id,
                user_unread_message_count=User(
                    self.note_obj.creator_id).get_unread_message_count(),
                note_id=self.note_id,
                comment_id=_obj.id,
                comment_creator_id=_creator_id,
                comment_creator_nickname=_creator.get_nickname(),
            )

        if reply_to_user_id != None and int(reply_to_user_id) != _creator_id:
            _reply_to_user_id = int(reply_to_user_id)
            _reply_to_comment_id = int(reply_to_comment_id)
            CreateNoteCommentReplyMessageTask.delay(
                user_id=_reply_to_user_id,
                user_unread_message_count=User(
                    _reply_to_user_id).get_unread_message_count(),
                note_id=self.note_id,
                comment_id=_reply_to_comment_id,
                replying_comment_id=_obj.id,
                replying_user_id=_creator_id,
                replying_user_nickname=_creator.get_nickname(),
            )
        return _obj.id
예제 #3
0
파일: note.py 프로젝트: guoku/Raspberry
    def update(self, score=None, note_text=None, image_data=None, weight=None):
        _context = self.__load_note_context_from_cache()
        self.__ensure_note_obj()

        if image_data != None:
            _image_obj = Image.create(source='note_uploaded',
                                      image_data=image_data)
            if _image_obj.image_id != self.note_obj.figure:
                self.note_obj.figure = _image_obj.image_id
            if _context != None:
                _context['figure'] = Image(_image_obj.image_id).getlink()

        if score != None:
            self.note_obj.score = score

        if note_text != None:
            _note_text = note_text.replace(u"#", "#")
            _old_text = self.note_obj.note
            _new_text = _note_text

            self.note_obj.note = _note_text
            if _context != None:
                _context['content'] = _note_text

            _new_tags = Tag.Parser.parse(_new_text)
            _old_tags = Tag.Parser.parse(_old_text)
            for _tag in _new_tags:
                if not _tag in _old_tags:
                    Tag.add_entity_tag(entity_id=self.note_obj.entity_id,
                                       user_id=self.note_obj.creator_id,
                                       tag=_tag)
            for _tag in _old_tags:
                if not _tag in _new_tags:
                    Tag.del_entity_tag(entity_id=self.note_obj.entity_id,
                                       user_id=self.note_obj.creator_id,
                                       tag=_tag)

        if weight != None:
            _weight = int(weight)
            self.note_obj.weight = _weight
            if _context != None:
                _context['weight'] = _weight
        self.note_obj.save()

        if _context != None:
            self.__reset_note_context_to_cache(_context)