def _update(self, item, format): if format == 'json': params = self._validate(json.loads(request.body), UpdateComment, 'edit') #elif format == 'atom': # from lxml import etree # params = Comment.parse_xml(etree.fromstring(request.body)) elif format == 'html': params = self._validate(request.POST.mixed(), UpdateComment, 'edit') else: raise UnacceptedFormat(format) already_published = item.published is not None item.update_from_dict(params) item.add_author_or_contributor(user_from_session(session)) # All comments are published. This is unnessecary #if not already_published and item.published is not None: # permalink = atom.slugify('-'.join([item.published.strftime("%Y-%m-%dT%H-%M-%S"),item.author['name']])) # story_permalink = Article.get_from_id(item.article_id).permalink # story_url = url('story',permalink=story_permalink) # item.atom_id = atom.get_tag_uri(story_url,item.published,item.author['name']) item.save() app_globals.clear_count_comments() return item
def _create(self, format, parent_id=None): if format == 'json': params = self._validate(json.loads(request.body), CreateComment, 'new') #elif format == 'atom': # from lxml import etree # params = Comment.parse_xml(etree.fromstring(request.body)) elif format == 'html': params = self._validate(request.POST.mixed(), CreateComment, 'new') else: raise UnacceptedFormat(format) params['parent'] = parent_id item = Comment.from_dict(params) item.add_author_or_contributor(user_from_session(session)) if item.published is not None: user_id = item.author['name'] or str(session['user_id']) permalink = atom.slugify('-'.join([item.published.strftime("%Y-%m-%dT%H-%M-%S"),user_id])) story_permalink = meta.Session.query(Article).get(int(parent_id)).permalink story_url = url('story',permalink=story_permalink) item.atom_id = atom.get_tag_uri(story_url,item.published,user_id) item.save() app_globals.clear_count_comments() return item
def _delete(self, item): item.delete() app_globals.clear_count_comments()