def get(self, user_key): """ Get all posts of a given user :param user_key: Key of the user we want to get all posts """ user = User.get(user_key) posts = Post.get_all(user=user) pagination = Pagination(self.request.GET.get('p'), posts.count()) if pagination and pagination.is_valid(): posts = posts.fetch(limit=pagination.posts_per_page, offset=pagination.offset) nb_likes = Like.get_nb_likes_per_posts(posts) nb_comments = Comment.get_nb_comments_per_posts(posts) self.render("posts/user.html", userposts=user, posts=posts, nb_likes=nb_likes, nb_comments=nb_comments, pagination=pagination) else: self.abort(404, "Invalid page number")
def home(request): try: p = int(request.GET.get('p', 1)) n = int(request.GET.get('n', 25)) q = CBCDInit.objects data = { 'index': 'cbcd', 'paging': Pagination(request, q.count()), 'form': InitForm(), 'inits': { 'p': p, 'n': n, 'data': q.all().order_by('-id')[(p - 1) * n:p * n], } } if request.method == 'POST': data['form'] = InitForm(request.POST) if data['form'].is_valid(): try: CBCDInit.objects.all().update(status=0) except: pass cinit = CBCDInit(total=int(request.POST.get('total')), unsell=int(request.POST.get('total')), price=float(request.POST.get('price')), status=1) cinit.save() return HttpResponseRedirect('/backend/cbcd/') except: utils.debug() return utils.ErrResp(errors.FuncFailed) return render(request, 'backend/cbcd/index.html', data)
def visa_apply(request): try: p = int(request.GET.get('p', 1)) n = int(request.GET.get('n', 25)) username = request.GET.get('username', '') status = int(request.GET.get('status', -1)) q = UserVisaApply.objects if username: try: u = Auth_user.objects.get(username=username) q = q.filter(user_id=u.id) except: pass if status != -1: q = q.filter(status=status) form_initial = {'username': username, 'status': status} form = VisaSearchForm(initial=form_initial) data = { 'index': 'user', 'paging': Pagination(request, q.count()), 'forms': form, 'list': { 'p': p, 'n': n, 'data': q.all().order_by('-id')[(p - 1) * n:p * n], } } return render(request, 'backend/user/visa_apply.html', data) except: traceback.print_exc() return utils.ErrResp(errors.FuncFailed)
def setUpClass(cls): super(FieldinterviewsTest, cls).setUpClass() cls.fieldinterviewspage = FieldInterviewsPage(cls.driver) cls.pagination = Pagination(cls.driver) cls.fieldinterviewspage.open_field_interviews_app() cls.section = 'FieldInterviewsMessages' cls.config = ConfigParser.ConfigParser() cls.config.readfp(open('baseconfig.cfg'))
def setUpClass(cls): super(TimelinepageTest, cls).setUpClass() cls.timelinepage = TimelinePage(cls.driver) cls.pagination = Pagination(cls.driver) cls.timelinepage.open_timeline_app() cls.section = 'TimelineMessages' cls.config = ConfigParser.ConfigParser() cls.config.readfp(open('baseconfig.cfg'))
def get(self, name, page=1): posts = Post.select().join(Category).where(Category.name == name) pagination = Pagination(posts, int(page), per_page=8) self.render('archive.html', pagination=pagination, name=name, obj_url='/category/%s' % (name), flag='category')
def setUpClass(cls): super(IncidentsPageTest, cls).setUpClass() cls.AssessmentSections = 'AssessmentSections' cls.config = ConfigParser.ConfigParser() cls.config.readfp(open('baseconfig.cfg')) cls.incident = IncidentsPage(cls.driver) cls.incident.logintoapp() cls.pagination = Pagination(cls.driver)
def withdraw(request): try: p = int(request.GET.get('p', 1)) n = int(request.GET.get('n', 25)) username = request.GET.get('username', '') q = UserWithDraw.objects if username: try: u = Auth_user.objects.get(username=username) q = q.filter(user=u) except: pass form_initial = {'username': username} form = WithDrawSearchForm(initial=form_initial) data = { 'index': 'user', 'paging': Pagination(request, q.count()), 'forms': form, 'withdraw_list': { 'p': p, 'n': n, 'data': [], } } withdraws = q.all().order_by('-id')[(p - 1) * n:p * n] for w in withdraws: try: create_time = utils.dt_field_to_local(w.create_time) \ .strftime('%Y-%m-%d %H:%M:%S') except: create_time = '' try: update_time = utils.dt_field_to_local(w.update_time) \ .strftime('%Y-%m-%d %H:%M:%S') except: update_time = '' d = { 'id': w.id, 'username': w.user.username, 'amount': float(w.amount), 'pay_type': w.pay_type, 'pay_account': w.pay_account, 'order_id': w.order_id, 'create_time': create_time, 'update_time': update_time, 'status': UserWithDraw.STATUS[w.status] } data['withdraw_list']['data'].append(d) return render(request, 'backend/user/withdraw.html', data) except: import traceback traceback.print_exc() return utils.ErrResp(errors.FuncFailed)
def home(request): try: p = int(request.GET.get('p', 1)) n = int(request.GET.get('n', 25)) code = request.GET.get('code', '') status = int(request.GET.get('status', -1)) q = InviteCode.objects if status != -1: q = q.filter(status=status) if code: q = q.filter(code=code) form = SearchForm(initial={'status': status, 'code': code}) quick_jump_form = QuickJumpForm(initial={ 'status': status, 'code': code, 'p': p, 'n': n }) data = { 'index': 'admin', 'paging': Pagination(request, q.count()), 'forms': form, 'quick_jump_form': quick_jump_form, 'code_list': { 'p': p, 'n': n, 'data': [], } } codes = q.all().order_by('-id')[(p - 1) * n:p * n] for c in codes: try: update_time = utils.dt_field_to_local(c.update_time) \ .strftime('%Y-%m-%d %H:%M:%S') except: update_time = '' data['code_list']['data'].append({ 'id': c.id, 'code': c.code, 'status': c.status, 'status_name': InviteCode.STATUS[c.status], 'update_time': update_time }) return render(request, 'backend/invite_code.html', data) except: import traceback traceback.print_exc() return utils.ErrResp(errors.FuncFailed)
def get(self, id): cate = Category.get_cat_by_id(id) page = self._get_page() books = Book.get_page_books_by_cate(id, page) if not books and page != 1: raise HTTPError(404) pagination = Pagination(page, 30, cate["count"]) self.render("cate.html", cate=cate, pagination=pagination, books=books)
def get(self, year, month, page=1): format = '%%%s-%s%%' % (year, month) posts = Post.select().where(Post.created**format) pagination = Pagination(posts, int(page), per_page=8) self.render('archive.html', year=year, month=month, pagination=pagination, flag='archives', obj_url='/archives/%s/%s' % (year, month))
def get(self, page=1): p = self.get_argument('p', None) if p: post = Post.get(id=int(p)) post.readnum += 1 post.save() self.render('post.html', post=post) else: pagination = Pagination(Post.select(), int(page), per_page=8) self.render('index.html', pagination=pagination)
def get(self, tagname, page=1): tags = Tag.select().where(Tag.name == tagname) postids = [tag.post for tag in tags] pagination = Pagination(Post.select().where(Post.id << postids), int(page), per_page=8) self.render('archive.html', pagination=pagination, name=tagname, obj_url='/tag/%s' % (tagname), flag='tag')
def oplog(request): try: p = int(request.GET.get('p', 1)) n = int(request.GET.get('n', 25)) username = request.GET.get('username', '') optype = int(request.GET.get('optype', -1)) q = UserOplog.objects if optype != -1: q = q.filter(optype=optype) if username: try: u = Auth_user.objects.get(username=username) q = q.filter(user_id=u.id) except: pass form_initial = {'optype': optype, 'username': username} form = OplogSearchForm(initial=form_initial) data = { 'index': 'user', 'paging': Pagination(request, q.count()), 'forms': form, 'oplog_list': { 'p': p, 'n': n, 'data': [], } } oplogs = q.all().order_by('-id')[(p - 1) * n:p * n] for o in oplogs: try: optime = utils.dt_field_to_local(o.create_time) \ .strftime('%Y-%m-%d %H:%M:%S') except: optime = '' d = { 'id': o.id, 'user_id': o.user.id, 'username': o.user.username, 'optype': UserOplog.OPTYPE[o.optype], 'content': o.content, 'optime': optime, 'ip': o.ip } data['oplog_list']['data'].append(d) return render(request, 'backend/user/oplog.html', data) except: import traceback traceback.print_exc() return utils.ErrResp(errors.FuncFailed)
def get(self): page_size = 30 count = Book.get_count()["count"] page = self._get_page() books = Book.get_all_books(page, page_size) if not books and page != 1: raise HTTPError(404) pagination = Pagination(page, page_size, count) self.render("finish.html", pagination=pagination, books=books)
def revenue(request): try: p = int(request.GET.get('p', 1)) n = int(request.GET.get('n', 25)) username = request.GET.get('username', '') revenue_type = request.GET.get('revenue_type', -1) q = UserRevenue.objects if revenue_type != -1: q = q.filter(revenue_type=revenue_type) if username: try: u = Auth_user.objects.get(username=username) q = q.filter(user_id=u.id) except: pass form_initial = {'revenue_type': revenue_type, 'username': username} form = RevenueSearchForm(initial=form_initial) data = { 'index': 'user', 'paging': Pagination(request, q.count()), 'forms': form, 'revenue_list': { 'p': p, 'n': n, 'data': [], } } revenues = q.all().order_by('-id')[(p - 1) * n:p * n] for r in revenues: try: create_time = utils.dt_field_to_local(r.create_time) \ .strftime('%Y-%m-%d %H:%M:%S') except: create_time = '' d = { 'id': r.id, 'user_id': r.user.id, 'username': r.user.username, 'revenue_type': UserRevenue.REVENUE_TYPE[r.revenue_type], 'revenue': r.revenue, 'create_time': create_time } data['user_list']['data'].append(d) return render(request, 'backend/user/revenue_records.html', data) except: import traceback traceback.print_exc() return utils.ErrResp(errors.FuncFailed)
def home(request): try: p = int(request.GET.get('p', 1)) n = int(request.GET.get('n', 25)) name = request.GET.get('name', '') status = int(request.GET.get('status', -1)) q = Projects.objects if status != -1: q = q.filter(status=status) if name: q = q.filter(name__icontains=name) form = SearchForm(initial={'status': status, 'name': name}) data = { 'index': 'admin', 'paging': Pagination(request, q.count()), 'forms': form, 'project_list': { 'p': p, 'n': n, 'data': [], } } projects = q.all().order_by('-id')[(p - 1) * n:p * n] for p in projects: try: create_time = utils.dt_field_to_local(p.create_time) \ .strftime('%Y-%m-%d %H:%M:%S') except: create_time = '' data['project_list']['data'].append({ 'id': p.id, 'name': p.name, 'total': p.total, 'price': float(p.price), 'status': p.status, 'status_name': Projects.STATUS[p.status], 'create_time': create_time }) return render(request, 'backend/project/list.html', data) except: import traceback traceback.print_exc() return utils.ErrResp(errors.FuncFailed)
def setUpClass(cls): super(AssessmenttPageTest, cls).setUpClass() cls.AssessmentSections = 'AssessmentSections' cls.config = ConfigParser.ConfigParser() cls.config.readfp(open('baseconfig.cfg')) cls.ast = AssessmentPage(cls.driver) cls.ast.logintoapp() cls.pagination = Pagination(cls.driver) try: cls.ast.get_asset_avilability( cls.config.get(cls.AssessmentSections, 'MAIN_MAINSCHOOL')) except Exception, err: print err.message
def feedback(request): try: p = int(request.GET.get('p', 1)) n = int(request.GET.get('n', 25)) username = request.GET.get('username', '') q = UserFeedback.objects if username: try: u = Auth_user.objects.get(username=username) q = q.filter(user=u) except: pass form_initial = {'username': username} form = FeedbackSearchForm(initial=form_initial) data = { 'index': 'user', 'paging': Pagination(request, q.count()), 'forms': form, 'feedback_list': { 'p': p, 'n': n, 'data': [], } } feedbacks = q.all().order_by('-id')[(p - 1) * n:p * n] for f in feedbacks: try: create_time = utils.dt_field_to_local(f.create_time) \ .strftime('%Y-%m-%d %H:%M:%S') except: create_time = '' d = { 'id': f.id, 'username': f.user.username, 'title': f.title, 'create_time': create_time, 'status': UserFeedback.STATUS[f.status] } data['feedback_list']['data'].append(d) return render(request, 'backend/user/feedback.html', data) except: import traceback traceback.print_exc() return utils.ErrResp(errors.FuncFailed)
def get(self): key = self.get_argument('key', '') page = self._get_page() page_size = 30 count = Book.get_search_books_count(key) books = Book.get_search_books(key, page, page_size) pagination = Pagination(page, page_size, count['count']) self.render( "search.html", pagination=pagination, books=books, searchKey=key, )
def get(self): """ Get all posts """ posts = Post.get_all() pagination = Pagination(self.request.GET.get('p'), posts.count()) if pagination.is_valid(): posts = posts.fetch(limit=pagination.posts_per_page, offset=pagination.offset) nb_likes = Like.get_nb_likes_per_posts(posts) nb_comments = Comment.get_nb_comments_per_posts(posts) self.render("home/page.html", posts=posts, nb_likes=nb_likes, nb_comments=nb_comments, pagination=pagination) else: self.abort(404, "Invalid page number")
def rank(request): data = { 'index': 'member', 'sub_index': 'home', 'statics': services.get_statics(request.user.id), 'news': News.objects.all().order_by('-id')[0:10] } n = 20 p = request.GET.get('p', 1) q = UserPromoteRank.objects data['ranklist'] = { 'tot': q.count(), 'paging': Pagination(request, q.count()), 'data': q.all().order_by('-id')[(p - 1) * n:p * n] } return utils.crender(request, 'frontend/member/rank.html', data)
def order(request): try: q = UserOrderSell.objects p = int(request.GET.get('p', 1)) n = int(request.GET.get('n', 25)) username = request.GET.get('username', '') status = int(request.GET.get('status', -1)) if username: try: u = Auth_user.objects.get(username=username) q = q.filter(user=u) except: pass if status != -1: q = q.filter(status=status) data = { 'index': 'cbcd', 'paging': Pagination(request, q.count()), 'form': UserOrderSellSearchForm(), 'orders': { 'p': p, 'n': n, 'data': [], } } results = q.all().order_by('-id')[(p - 1) * n:p * n] for r in results: data['orders']['data'].append({ 'id': r.id, 'order_id': r.order_id, 'seller': r.seller_user.username, 'price': float(r.price), 'num': int(r.num), 'num_unsell': int(r.num_unsell), 'create_at': r.create_at, 'status': r.status }) except: utils.debug() return utils.ErrResp(errors.FuncFailed) return render(request, 'backend/cbcd/order.html', data)
def log_withdraw(request): data = { 'index': 'member', 'sub_index': 'log', 'statics': services.get_statics(request.user.id), 'news': News.objects.all().order_by('-id')[0:10] } n = 20 p = request.GET.get('p', 1) q = UserWithDraw.objects \ .filter(user_id=request.user.id) data['loglist'] = { 'paging': Pagination(request, q.count()), 'data': q.all().order_by('-id')[(p - 1) * n:p * n] } return utils.crender(request, 'frontend/member/log_withdraw.html', data)
def log(request, logtype): data = { 'index': 'member', 'sub_index': 'log', 'statics': services.get_statics(request.user.id), 'news': services.get_news(request) } n = 20 p = request.GET.get('p', 1) q = UserOplog.objects \ .filter(optype=UserOplog.OPTYPE_CODES[logtype]) \ .filter(user_id=request.user.id) data['loglist'] = { 'paging': Pagination(request, q.count()), 'data': q.all().order_by('-id')[(p - 1) * n:p * n] } return utils.crender(request, 'frontend/member/log_%s.html' % logtype, data)
def news(request): data = { 'index': 'member', 'sub_index': 'log', 'statics': services.get_statics(request.user.id), 'news': News.objects.all().order_by('-id')[0:10] } n = 20 p = request.GET.get('p', 1) q = News.objects if request.session['lang'] == 'en': q = q.filter(category=2) data['news'] = { 'paging': Pagination(request, q.count()), 'data': q.all().order_by('-id')[(p - 1) * n:p * n] } return utils.crender(request, 'frontend/member/news.html', data)
def mailbox(request, ctype): data = { 'index': 'member_mailbox', 'sub_index': 'log', 'statics': services.get_statics(request.user.id), 'news': News.objects.all().order_by('-id')[0:10], 'ctype': ctype } n = 20 p = request.GET.get('p', 1) q = UserMessage.objects.filter(ctype='member') if ctype == 'sended': q = q.filter(from_user_id=request.user.id) elif ctype == 'received': q = q.filter(to_user_id=request.user.id) data['maillist'] = { 'tot': q.count(), 'paging': Pagination(request, q.count()), 'data': q.all().order_by('-id')[(p - 1) * n:p * n] } return utils.crender(request, 'frontend/member/mailbox.html', data)
def mailbox(request): try: p = int(request.GET.get('p', 1)) n = int(request.GET.get('n', 25)) from_user = request.GET.get('from_user', '') to_user = request.GET.get('to_user', '') ctype = request.GET.get('ctype', 'member') q = UserMessage.objects if from_user: try: u = Auth_user.objects.get(username=from_user) q = q.filter(from_user_id=u.id) except: pass if to_user: try: u = Auth_user.objects.get(username=to_user) q = q.filter(to_user_id=u.id) except: pass if ctype: q = q.filter(ctype=ctype) form_initial = {'from_user': from_user, 'to_user': to_user, 'ctype': ctype} form = MailboxSearchForm(initial=form_initial) data = { 'index': 'user', 'paging': Pagination(request, q.count()), 'forms': form, 'mail_list': { 'p': p, 'n': n, 'data': [], } } mails = q.all().order_by('-id')[(p - 1) * n:p * n] for m in mails: try: send_time = utils.dt_field_to_local(m.create_time) \ .strftime('%Y-%m-%d %H:%M:%S') except: send_time = '' try: read_time = utils.dt_field_to_local(m.read_time) \ .strftime('%Y-%m-%d %H:%M:%S') except: read_time = '' d = { 'id': m.id, 'from_user': m.from_user.username, 'to_user': m.to_user.username, 'title': m.title, 'ctype': m.ctype, 'send_time': send_time, 'read_time': read_time, 'status_name': UserMessage.STATUS[m.status], 'status': m.status } data['mail_list']['data'].append(d) return render(request, 'backend/user/mailbox.html', data) except: import traceback traceback.print_exc() return utils.ErrResp(errors.FuncFailed)
def get(self, page=1): posts = Pagination(Post.select(), int(page), 10) self.render('admin/post/index.html', pagination=posts, nav='post')
def get(self, page=1): pagination = Pagination(Link.select(), int(page), 1) self.render('admin/link/index.html', pagination=pagination, nav='link')