def delete(self): self.__ensure_note_obj() _note_text = self.note_obj.note _entity_id = self.note_obj.entity_id _creator_id = self.note_obj.creator_id self.note_obj.delete() _tags = Tag.Parser.parse(_note_text) for _tag in _tags: Tag.del_entity_tag(entity_id=_entity_id, user_id=_creator_id, tag=_tag)
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)
raise Note.CommentDoesNotExist(_comment_id) _comment_text = self.comments[_comment_id].comment _creator_id = self.comments[_comment_id].creator_id self.comments[_comment_id].delete() _context = self.__load_note_context_from_cache() if _context != None: if _comment_id in _context['comment_id_list']: _context['comment_id_list'].remove(_comment_id) _context['comment_count'] = len(_context['comment_id_list']) self.__reset_note_context_to_cache(_context) self.__ensure_note_obj() _tags = Tag.Parser.parse(_comment_text) for _tag in _tags: Tag.del_entity_tag(entity_id=self.note_obj.entity_id, user_id=_creator_id, tag=_tag) @staticmethod def get_user_last_note(user_id): _user_id = int(user_id) try: _note = NoteModel.objects.filter( creator_id=_user_id).order_by('-created_time')[0] return _note.id except: pass return None