def delete_article_comment_ajax(request): comment_id = int(request.matchdict['comment_id']) dbsession = DBSession() comment = dbsession.query(Comment).get(comment_id) if comment is None: return HTTPNotFound() dbsession.delete(comment) article = dbsession.query(Article).get(comment.article_id) _update_comments_counters(dbsession, article) data = {} return data
def delete_article(request): article_id = int(request.matchdict['article_id']) dbsession = DBSession() article = dbsession.query(Article).get(article_id) if article is None: return HTTPNotFound() # delete article and all article comments, invalidate tags too dbsession.query(Comment).filter(Comment.article_id == article_id).delete() dbsession.delete(article) h.get_public_tags_cloud(force_reload=True) data = {} return data
def _update_article(article_id, request): _ = request.translate dbsession = DBSession() article = dbsession.query(Article).get(article_id) if article is None: return HTTPNotFound() # check fields etc e = _check_article_fields(article, request) c = {'errors': {}} c['article'] = article c['errors'].update(e) c['article_published_str'] = request.POST['published'] if 'published' not in request.POST: c['errors']['published'] = _('invalid date and time format') else: # parse value to check structure date_re = re.compile('^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2})$') mo = date_re.match(request.POST['published']) if mo is None: c['errors']['published'] = _('invalid date and time format') else: # we need to convert LOCAL date and time to UTC seconds article.published = h.str_to_timestamp(request.POST['published']) v = [int(x) for x in mo.groups()[0:3]] article.shortcut_date = '{0:04d}/{1:02d}/{2:02d}'.format(*v) dbsession = DBSession() q = dbsession.query(Article).filter(Article.shortcut_date == article.shortcut_date)\ .filter(Article.id != article_id)\ .filter(Article.shortcut == article.shortcut) res = q.first() if res is not None: c['errors']['shortcut'] = _('duplicated shortcut') # tags c['tags'] = [] # these are new tags if 'tags' in request.POST: tags_str = request.POST['tags'] tags = set([s.strip() for s in tags_str.split(',')]) for tag_str in tags: if tag_str == '': continue c['tags'].append(tag_str) if len(c['errors']) == 0: for tag in article.tags: dbsession.delete(tag) for tag_str in c['tags']: tag = Tag(tag_str, article) dbsession.add(tag) # force update of tags cloud h.get_public_tags_cloud(force_reload=True) return HTTPFound(location=route_url('blog_go_article', request, article_id=article_id)) else: transaction.abort() return c