def get_monthly_entries(category): # 获取30天内的内容 q = None if category.current_level == 1: q = Entry.query.filter( and_(Entry.category1_id == category.id, Entry.published_time >= day_before_str(sys_now(), 30))) if category.current_level == 2: q = Entry.query.filter( and_(Entry.category2_id == category.id, Entry.published_time >= day_before_str(sys_now(), 30))) if category.current_level == 3: q = Entry.query.filter( and_(Entry.category3_id == category.id, Entry.published_time >= day_before_str(sys_now(), 30))) if q is None: return [] _list = q.order_by('-entry.ranking').limit(PER_PAGE) return _list
def dec_entry_count(tag_id_list): for tag_id in tag_id_list: tag = TagBase.get_by_id(tag_id) tag.num_entries = TagBase.__table__.c.num_entries - 1 tag.updated_time = sys_now() db.session.commit()
def add(comment): comment.created_time = sys_now() comment.updated_time = comment.created_time db.session.add(comment) db.session.commit() return comment.id is not None
def inc_num_comments(entry_id, num): entry = Entry.get_by_id(entry_id) entry.num_comments = Entry.__table__.c.num_comments + num entry.ranking = entry.num_views + (10 * entry.num_useful) + (10 * entry.num_favorites) + ( 10 * entry.num_retweet) \ + (5 * entry.num_oppositions) + (7 * entry.num_comments) + (5 * entry.num_useless) + ( 7 * entry.num_supports) db.session.commit() app.config['content_updated_time'] = sys_now()
def save(self, commit=True): if self.slug[0] == '/': self.slug = self.slug[1:] if self.slug[-1:] == '/': self.slug = self.slug[0:-1] current_app.config['content_updated_time'] = sys_now() return super(Category, self).save(commit)
def add_or_update(model): model.updated_time = sys_now() if not model.id: model.created_time = model.updated_time db.session.add(model) db.session.commit() return model.id
def save(self, commit=True): if self.slug[0] == '/': self.slug = self.slug[1:] if self.slug[-1:] == '/': self.slug = self.slug[0:-1] self.slug.replace('/', '_') current_app.config['content_updated_time'] = sys_now() return super(TagBase, self).save(commit)
def add_or_update(model): model.updated_time = sys_now() if not model.id: model.created_time = model.updated_time db.session.add(model) db.session.commit() from infopub.configs.setups import init_app_config init_app_config(app) return model.id
def post_preprocessor(data=None, **kw): """Accepts a single argument, `data`, which is the dictionary of fields to set on the new instance of the model. """ print 'get_many_preprocessor: ', data, kw print 'get_many_preprocessor: ', data, kw print 'get_many_preprocessor: ', data, kw print 'get_many_preprocessor: ', data, kw print 'get_many_preprocessor: ', data, kw print 'get_many_preprocessor: ', data, kw data['created_ip'] = get_remote_ip() data['upward_time'] = sys_now().strftime('%Y-%m-%d @ %I:%M %p') return True
def modify_last_comment(entry_id, comment_id): entry = Entry.get_by_id(entry_id) entry.last_comment_id = comment_id entry.upward_time = sys_now() db.session.commit()
def add_or_update(category, entry, is_draft, is_auto_save_img=False): # 保存数据 is_new = False if entry.id is None: # 是新建的数据 is_new = True # todo wqq:如果是管理员权限才能允许表单递交author_id #if not g.user.is_supervisor: # entry.author_id = g.user.id entry.author_id = 1 entry.created_ip = get_remote_ip() # entry.created_time = sys_now() # entry.updated_time = entry.created_time entry.upward_time = sys_now() entry.category_id = category.id entry.entry_type = category.entry_type #if is_auto_save_img: # # 是否自动保存图片 # entry.content = auto_save_img(entry.content, app.config['SITE_DOMAIN'], PHOTOS_RELATIVE_PATH) # 只有管理员可以设置是否推首页、置顶 #if not g.user.is_supervisor: # entry.on_top = 0 # todo 先默认是推到首页的,以后考虑可以配置 entry.on_portal = 1 if is_draft: entry.entry_status = EntryStatus.draft else: # 低权限的文章要审核 #if category.need_review and (not g.user.is_supervisor): #print '低权限的文章要审核:', app.config['SAFE_POST_START_TIME'], app.config['SAFE_POST_END_TIME'], check_in_rank(app.config['SAFE_POST_START_TIME'], app.config['SAFE_POST_END_TIME']) #if (not g.user.is_editor) and ( # not check_in_rank(app.config['SAFE_POST_START_TIME'], app.config['SAFE_POST_END_TIME'])): # # 需要审核 # entry.entry_status = EntryStatus.pending #else: # entry.entry_status = EntryStatus.published # entry.published_id = g.user.id # # if not entry.published_time: # entry.published_time = sys_now() # #if gfw.check(entry.content) or gfw.check(entry.title): # # 需要审核 # entry.entry_status = EntryStatus.pending entry.entry_status = EntryStatus.pending # 处理摘要 if not entry.summary: # 自动产生摘要 entry.summary = extract_summary(entry.content) # 开始处理tags old_tags_list = [] if not is_new: # old_tags_list = json_decode(entry.tags) entry.updated_time = sys_now() new_tags_list = request.form.getlist('m_tags') #entry.tags = json_encode(new_tags_list) if is_new: db.session.add(entry) db.session.flush() if entry.id is None: print '出错了' db.session.rollback() return False # # 要删除的标签 # del_tags_list = [val for val in old_tags_list if val not in new_tags_list] # # # 要添加的标签 # add_tags_list = [val for val in new_tags_list if val not in old_tags_list] # # if del_tags_list: # # 删除 tag_entry_relation (标签的文章关联) # TagEntryRelationService.del_relation(entry.id, del_tags_list) # # # 更新 tag_category_relation (标签的分类计数) # TagCategoryRelationService.del_relation(category, del_tags_list) # # if add_tags_list: # # 添加 tag_entry_relation (标签的文章关联) # TagEntryRelationService.add_relation(entry.id, add_tags_list) # # # 标签内容数 + 1 # TagService.inc_entry_count(add_tags_list) # # # 更新 tag_category_relation (标签的分类关联、计数) # TagCategoryRelationService.add_relation(category, add_tags_list) if not entry.slug: # 文章URL自动生成规则 # 文章标题: {title_name} # 文章ID: {title_id} # 栏目名: {category_name} # 栏目固定地址: {category_slug} # 时间戳: {timestamp} # 时间: {time} # 日期: {date} entry.slug = category.entry_url_rule.replace('{title_name}', '%s' % entry.title) \ .replace('{title_id}', '%d' % entry.id) \ .replace('{category_name}', '%s' % category.category_name) \ .replace('{category_slug}', category.slug) \ .replace('{timestamp}', '%s' % str(int(time()))) \ .replace('{time}', format_time_with_path(int(time()))) \ .replace('{date}', format_date_with_path(int(time()))).replace('//', '/') if entry.slug[0] == '/': entry.slug = entry.slug[1:] db.session.commit() #print '保存成功了' return True
def update_time(parent_id): comment = Comment.get_by_id(parent_id) comment.updated_time = sys_now() db.session.commit()