def classify(title, id, page): post = Post.getPagination(page, cid=id) main = Classify.query.get(id) gtop = Post.getTop(cid=id, num=3) args = dict(endpoint='home.classify', title=title, id=id) data = dict(pagination=post, gtop=gtop, breadcrumb=Breadcrumb(main).get(), args=args, main=main) return render_template('home/classify.html', **data)
def init_data(self, slug, post_id): try: self.post_id = int(post_id) except TypeError: self.post_id = 0 self.post = Post.get_by_id(self.post_id) context['post'] = self.post
def init_data(self, post_id, action): try: self.post_id = int(post_id) self.post = Post.get_by_id(self.post_id) context['page_path'] = '/post/'+self.post.slug+'-'+str(self.post.key().id())+'/edit' except TypeError: self.post_id = 0 context['page_path'] = '/post/add' self.form = self.form_class() if action == 'edit': self.form.get('title').value = self.post.title self.form.get('body').value = self.post.body self.form.get('active').value = self.post.active
def post_add(): form = PostForm() form.cid.choices = [(v.id, v.title) for v in db.session.query(Classify.id, Classify.title).all()] form.sid.choices = [(v.id, v.name) for v in Style.query.all()] form.author.data = session.get('nikename') # 表单是否验证成功 if form.validate_on_submit(): form.tags.data = tags_handle(form.tags.data) form.content.data = content_file_handle(form.content.data) post = field_obj_set(Post(),form.data) db.session.add(post) db.session.commit() flash('添加成功!', category='ok') return redirect(url_for('admin.post_add')) title = '新建文章' data = dict(title=title, tags=Tag.tags(), form=form) return render_template('admin/post.form.html', **data)
def GET(self): import PyRSS2Gen as RSS2 posts = Post.all().filter('active =', True).order('-datetime') items = list() for post in posts: link = SITE_URL+'/post/'+post.slug+'-'+str(post.key().id()) items.append( RSS2.RSSItem( title = post.title, link = link, description = post.body.split('\n')[0], guid = RSS2.Guid(link), pubDate = post.datetime)) rss = RSS2.RSS2( title = "Sibande's feed", link = SITE_URL, description = "Random thoughs by Sibande_", lastBuildDate = datetime.datetime.now(), items = items) return rss.to_xml();
def POST(self, post_id=None, action='add'): self.init_data(post_id, 'update') #switch to "update" and lose "edit" state form = self.form_class() if form.validates(): active = True if form.get('active').value else False title = form.get('title').value body = form.get('body').value if action == 'edit': post_data = self.post post_data.title=title post_data.body=body else: post_data = Post(title=title, body=body,) post_data.active=active post_data.put() return web.seeother('/post/'+post_data.slug+'-'+str(post_data.key().id()), absolute=True) context['form'] = form return render_template('add.html', **context)
def handle(self, *args, **options): for crawler in Crawler.objects.filter(enabled=True): self.stdout.write("Starting {0}\n".format(crawler.link)) for link in crawler.listings(): try: Post.objects.get(link=link) except Post.DoesNotExist: self.stdout.write(link) post = Post() post.load(link) post.crawler = crawler if post.is_match: self.stdout.write(" Yes!\n") if crawler.hits_email is not None: send_mail( 'Apartment Found: {0}'.format(post.headline), settings.EMAIL_BODY.format( post.link, post.headline, post.cost, post.bedrooms, post.raw_text ), settings.EMAIL_FROM_USER, [crawler.hits_email], fail_silently=False) else: self.stdout.write(" No\n") if post.is_match or not crawler.store_matches_only: post.save() crawler.last_run = datetime.now() crawler.save() self.stdout.write("Done!\n")
def GET(self): context['posts'] = Post.all().filter('active =', True).order('-datetime') return render_template('index.html', **context)
def tag(name,id): main = Tag.query.get_or_404(id) main.title = main.name data = dict(main=main, gtop=Post.getTop(), breadcrumb=Breadcrumb(main).get()) return render_template('home/tag.html', **data)
def index(): site = Site.query.filter_by(group='seo').all() page = request.args.get('page', 1, type=int) post = Post.getPagination(page, num=10) data = dict(breadcrumb=Breadcrumb().get(), gtop=Post.getTop(), main=site_to_dict(site), pagination=post) return render_template('home/index.html', **data)
def test(self): checkin_actor = TransactionManager.get_checkin_actor() board = Board.objects.create(title="공지사항") post1 = Post() post1.title = "공지사항 제 1번" post1.content = "첫번째 공지사항입니다." post1.author = checkin_actor post1.board = board post1.save() assert board.posts.count() == 1 assert post1.board == board assert post1.title == "공지사항 제 1번" assert post1.content == "첫번째 공지사항입니다." assert post1.author == checkin_actor assert post1.created_date.date() == post1.published_date.date() post2 = Post() post2.title = "공지사항 제 2번" post2.content = "두번째 공지사항입니다." post2.author = checkin_actor post2.board = board post2.save() assert board.posts.count() == 2 assert post2.board == board assert post2.title == "공지사항 제 2번" assert post2.content == "두번째 공지사항입니다." assert post2.author == checkin_actor assert post2.created_date.date() == post2.published_date.date()
def test(self): assert Dummy.owner.computed_field_name == "computed_owner" assert Dummy.container.computed_field_name == "computed_container" assert Email.email_address.field_name == "data" assert User.actors.field_name == "computed" assert Post.resolve_subfield_name("board") == "container"