コード例 #1
0
    def run(self, site, messages=None):
        site.clear()
        show_messages(messages)
        course_list = paginator(site.active_user.get_scores(), 20)
        page_number = 0
        while True:
            menu = {
                'Home': '/student/',
            }
            if page_number - 1 >= 0:
                menu['Previous Page'] = '/student/workbook/'
            if page_number + 1 < len(course_list):
                menu['Next Page'] = '/student/workbook/'
            if len(course_list) == 0:
                print("There is no passed course in the system.")
            else:
                pprint_table(
                    'Workbook',
                    course_list[page_number],
                    foot='Page {} of {}'.format(page_number + 1,
                                                len(course_list)),
                    cols_title=site.active_user.get_score_columns_title())
            choice = choose_from_menu(menu.keys())
            if choice == 'Home':
                site.state = menu[choice]
                break
            elif choice == 'Previous Page':
                page_number -= 1
                site.clear()
            elif choice == 'Next Page':
                page_number += 1
                site.clear()

        return None
コード例 #2
0
    def get_results(self, obj):
        page = self.context.get("page")
        url = self.context.get("url")
        all = self.context.get("notifs")
        user = self.context.get('user')
        p = paginator(all, page=page, limit=15)

        result = p.get('result')
        result_list = []
        for notif in result:
            data = {}

            if notif.action_type == NotifType.LIKE.value or \
                    notif.action_type == NotifType.COMMENT.value:
                data['post_picture'] = url + str(notif.post.picture)
                data['post_id'] = notif.post.id

            if notif.action_type == NotifType.OTHER_FOLLOW.value:
                action_data = json.loads(notif.action_data)
                id = action_data['other_user']
                username = User.objects.get(id=id).username
                data['username'] = username

            item = {
                'subject_user': notif.subject_user.username,
                'notif_type': notif.action_type,
                'profile_picture': url + str(notif.subject_user.profile_picture),
                'time': notif.time,
                'data': data
            }
            result_list.append(item)
        return result_list
コード例 #3
0
    def run(self, site, messages=None):
        site.clear()
        show_messages(messages)
        course_list = paginator(site.get_verified_courses(), 20)
        page_number = 0
        while True:
            menu = ['Home']
            if page_number - 1 >= 0:
                menu.append('Previous Page')
            if page_number + 1 < len(course_list):
                menu.append('Next Page')
            if len(course_list) == 0:
                print("There is no verified course in the system.")
            else:
                pprint_table('Courses',
                             course_list[page_number],
                             foot='Page {} of {}'.format(
                                 page_number + 1, len(course_list)))
            choice = choose_from_menu(menu)
            if choice == 'Home':
                site.state = '/manager/'
                break
            elif choice == 'Previous Page':
                page_number -= 1
                site.clear()
            elif choice == 'Next Page':
                page_number += 1
                site.clear()

        return None
コード例 #4
0
    def get_results(self, obj):
        page = self.context.get("page")
        url = self.context.get("url")
        all = self.context.get("posts")
        user = self.context.get('user')
        tag_search = self.context.get('tag_search')

        p = paginator(all, page=page)

        result = p.get('result')
        result_list = []
        for post in result:
            like_query = Like.objects.filter(post=post, user=user)
            is_liked = True if len(like_query) > 0 else False
            item = {}
            if tag_search == None:
                item = {
                    'id': post.id,
                    'owner_username': post.owner.username,
                    'profile_picture': url + str(post.owner.profile_picture),
                    'post_picture': url + str(post.picture),
                    'caption':
                    post.caption if post.caption is not None else "",
                    'likes_count': Like.objects.filter(post=post).count(),
                    'comments_count':
                    Comment.objects.filter(post=post).count(),
                    'time': post.time,
                    'is_liked': is_liked
                }
            else:
                item = {'id': post.id, 'post_picture': url + str(post.picture)}
            result_list.append(item)

        return result_list
コード例 #5
0
    def get_results(self, obj):

        page = self.context.get("page")
        url = self.context.get("url")
        all = self.context.get("data")
        p = paginator(all, page=page)

        result = p.get('result')
        result_list = []

        for board in result:
            last_posts = BoardContains.objects.filter(
                board=board).order_by('-id')[:5]
            last_pics = []

            for postcontains in last_posts:
                post = postcontains.post
                last_pics.append(url + str(post.picture))

            item = {
                'id': board.id,
                'name': board.name,
                'count': BoardContains.objects.filter(board=board).count(),
                'last_pics': last_pics
            }
            result_list.append(item)

        return result_list
コード例 #6
0
ファイル: user.py プロジェクト: lisongjian/ts-ad
 def get(self):
     uid = self.get_argument('uid', 0)
     status = self.get_argument('status', 0)
     vip = self.get_argument('vip',"")
     if vip != "":
         users.set_user_vip(uid,vip)
     if status:
         users.set_user_status(uid, status)
     page = int(self.get_argument('page', 1))
     user_info = users.get_user(uid)
     ip_info = users.get_user_ips(uid)
     device_info = users.get_device(uid)
     if not device_info:
         device_info = {}
     data = orders.get_global_orders(uid)
     result = paginator(data, page)
     data = {
         "title": "用户详细信息",
         "current_user": self.current_user,
         "user": user_info,
         "device": device_info,
         "orders": result,
         "ips": ip_info,
     }
     self.render("user/detailaos.html", **data)
コード例 #7
0
ファイル: user.py プロジェクト: lisongjian/ts-ad
    def get(self):
        page = int(self.get_argument('page', 1))
        platform = self.get_argument('platform','')
        orderby = self.get_argument('orderby', 'uid')
        data = []
        strdate, sdate, edate = parse_date(self)
# if strdate:
#           data = users.get_user_time(sdate, edate)##
#       if orderby == 'total_sons':
#           data = users.get_users_by_ttsons(sdate,edate)
#elif orderby != 'uid':
        if orderby == 'total_sons':
            data = users.get_users_by_ttsons(sdate,edate,platform)
        elif orderby != 'uid':
            data = users.get_users(sdate,edate,orderby,platform)
        else:
		    data = users.get_user_time(sdate, edate,platform)
        #test = users.get_user_platform(sdate,edate,2,orderby)
        #print test
        result = paginator(data, page)
        data = {
            "title": "用户信息列表",
            "current_user": self.current_user,
            "users": result,
            "orderby": orderby,
            "strdate": strdate,
	   	    "sdate" : strdate['s'],
	        "edate" : strdate['e'],
            "platform" : platform
        }
        self.render("user/index.html", **data)
コード例 #8
0
    def run(self, site, messages=None):
        site.clear()
        show_messages(messages)
        course_list = paginator(site.get_current_courses(site.active_user), 20)
        page_number = 0
        while True:
            menu = {
                'Home': '/teacher/',
            }
            if page_number - 1 >= 0:
                menu['Previous Page'] = '/teacher/courses/'
            if page_number + 1 < len(course_list):
                menu['Next Page'] = '/teacher/courses/'
            if len(course_list) == 0:
                print("There is no course for you.")
            else:
                pprint_table('Courses',
                             course_list[page_number],
                             foot='Page {} of {}'.format(
                                 page_number + 1, len(course_list)))
            choice = choose_from_menu(menu.keys())
            if choice == 'Home':
                site.state = menu[choice]
                break
            elif choice == 'Previous Page':
                page_number -= 1
                site.clear()
            elif choice == 'Next Page':
                page_number += 1
                site.clear()

        return None
コード例 #9
0
    def get(self, request, format=None):
        Tags_query_set = TagContains.objects.values('tag_id').annotate(
            count=Count('tag')).order_by('-count', '-tag_id')[:1000]
        page_number = request.GET.get('page')
        pages = utils.paginator(Tags_query_set, page=page_number)
        results = pages.get('result')
        count = pages.get('count')
        total_page = pages.get('total_page')
        results_list = []
        url = str(request.scheme) + '://' + request.get_host() + MEDIA_URL
        for item in results:
            tag_query_set = Tags.objects.get(id=item['tag_id'])
            tag_id = tag_query_set.id
            tag_name = tag_query_set.name

            tag_contains = TagContains.objects.filter(
                tag=tag_query_set,
                post__owner__is_private=False).order_by('-id').first()

            if tag_contains:
                new_item = {
                    "tag_id": tag_id,
                    "tag_name": tag_name,
                    "picture": '%s%s' % (url, str(tag_contains.post.picture))
                }
                results_list.append(new_item)
        data = {
            "total_pages": total_page,
            "count": count,
            "results": results_list
        }

        return Response(data=data, status=status.HTTP_200_OK)
コード例 #10
0
    def get_results(self, obj):

        page = self.context.get("page")
        url = self.context.get("url")
        all = self.context.get("data")
        requset_user = self.context.get('request_user')
        p = paginator(all, page=page, limit=15)

        result = p.get('result')
        result_list = []

        for user in result:

            follow_state = 3
            is_followed = Followers.objects.filter(user=requset_user,
                                                   following=user)

            if len(is_followed):
                follow_state = 1

            is_requested = Request.objects.filter(requester=requset_user,
                                                  requestee=user)
            if len(is_requested):
                follow_state = 2

            item = {
                'username': user.username,
                'is_private': user.is_private,
                'profile_picture': url + str(user.profile_picture),
                'fullname': user.fullname if user.fullname is not None else "",
                'following_status': follow_state
            }
            result_list.append(item)

        return result_list
コード例 #11
0
ファイル: tags.py プロジェクト: styleold/missuor
def all(request, *args, **kwargs):
    template_name = kwargs.get('template', 'tags/home.html')
    extra_context = kwargs.get('extra_context', None)

    objs = models.Tag.objects.all().order_by('-count', 'flag')
    context = paginator(request, objs)
    context = {'records': objs}
    return TemplateResponse(request, template_name, context)
コード例 #12
0
ファイル: views.py プロジェクト: styleold/missuor
def drafts(request, *args, **kwargs):
    template_name = kwargs.get('template', 'blog/drafts.html')
    user = request.user
    objs = models.Article.objects.filter(
        is_publish=False,
        owner=user
    ).order_by('-create_time')
    context = paginator(request, objs)
    return TemplateResponse(request, template_name, context)
コード例 #13
0
ファイル: feedback.py プロジェクト: lisongjian/ts-ad
 def get(self):
     page = int(self.get_argument('page', 1))
     data = feedback.get_feedbacks()
     result = paginator(data, page)
     data = {
         "title": "用户反馈列表",
         "current_user": self.current_user,
         "fbs": result,
     }
     self.render("feedback/index.html", **data)
コード例 #14
0
    def get(self, request, username=None, *args, **kwargs):

        ip = utils.get_client_ip(request)

        utils.start_method_log('PaginationApiView: get',
                               authorized_user=request.user.username,
                               request_user=username)

        if username is None:
            username = request.user.username
        try:
            profile = User.objects.get(username=username)
        except ObjectDoesNotExist:
            data = {"error": "Username not found"}
            logger.info('PaginationApiView: get '
                        '(Username not found) username:{}, ip: {}'.format(
                            request.user.username, ip))
            return Response(data=data, status=status.HTTP_404_NOT_FOUND)

        profile_private = profile.is_private
        target_profile = profile
        user_profile = request.user
        if target_profile != user_profile and profile_private:
            try:
                follow_status = Followers.objects.get(user=user_profile,
                                                      following=target_profile)
            except ObjectDoesNotExist:
                return Response(status=status.HTTP_403_FORBIDDEN)

        queryset = Posts.objects.filter(owner=profile).order_by('-time')

        page = request.GET.get('page')
        pages = utils.paginator(queryset, page=page)
        results = pages.get('result')
        count = pages.get('count')
        total_page = pages.get('total_page')
        results_list = []
        for post in results:
            item = {
                "id":
                post.id,
                "post_picture":
                str(request.scheme) + "://" + request.get_host() + MEDIA_URL +
                str(post.picture)
            }
            results_list.append(item)
        data = {
            "count": count,
            "total_pages": total_page,
            "results": results_list
        }
        logger.info('PaginationApiView: get '
                    '(get posts of {}) username:{}, ip: {}'.format(
                        username, request.user.username, ip))
        return Response(data=data, status=status.HTTP_200_OK)
コード例 #15
0
ファイル: exchange.py プロジェクト: lisongjian/ts-ad
 def get(self):
     page = int(self.get_argument('page', 1))
     status = int(self.get_argument('status', 10))
     data = orders.get_exchange_orders(status)
     result = paginator(data, page)
     data = {
         "title": "兑换订单列表",
         "current_user": self.current_user,
         "orders": result,
         "status": status,
     }
     self.render('exchange/index.html', **data)
コード例 #16
0
    def get(self, request, board_id=None, format=None):

        ip = utils.get_client_ip(request)

        utils.start_method_log('ProfileViewSet: get',
                               username=request.user.username,
                               ip=ip)

        if (not self._can_see(request, board_id)) or board_id is None:
            logger.info('BoardDetailsAPI: get (Permission denied!)'
                        'username: {}, ip{}'.format(request.user.username, ip))
            data = {'details': 'Permission denied!'}

            return Response(data, status.HTTP_400_BAD_REQUEST)

        posts = BoardContains.objects.filter(
            board=board_id).order_by('-id').values('post_id', 'post__picture')
        utils.paginator(posts)

        page = request.GET.get('page')
        pages = utils.paginator(posts, page=page)
        results = pages.get('result')
        count = pages.get('count')
        total_page = pages.get('total_page')
        results_list = []
        for post in results:
            item = {
                "id":
                post.get('post_id'),
                "post_picture":
                str(request.scheme) + "://" + request.get_host() + MEDIA_URL +
                str(post.get('post__picture'))
            }
            results_list.append(item)
        data = {
            "count": count,
            "total_page": total_page,
            "results": results_list
        }
        return Response(data=data, status=status.HTTP_200_OK)
コード例 #17
0
 def run(self, site, messages=None):
     site.clear()
     show_messages(messages)
     user_list = paginator(site.get_unverified_users(), 20)
     page_number = 0
     while True:
         if len(user_list) == 0:
             print("There is no unverified user in the system.\n")
         else:
             pprint_table('New Users',
                          copy.copy(user_list[page_number]),
                          foot='Page {} of {}'.format(
                              page_number + 1, len(user_list)))
         menu = ['Home']
         if page_number - 1 >= 0:
             menu.append('Previous Page')
         if page_number + 1 < len(user_list):
             menu.append('Next Page')
         if len(user_list) > 0:
             menu.append('Accept')
             menu.append('Reject')
         choice = choose_from_menu(menu)
         if choice == 'Home':
             site.state = '/manager/'
             break
         elif choice == 'Previous Page':
             page_number -= 1
             site.clear()
         elif choice == 'Next Page':
             page_number += 1
             site.clear()
         else:
             student_row = get_input("Enter row number of the student: ",
                                     output_type=int)
             student_row -= 1
             if student_row >= len(
                     user_list[page_number]) or student_row < 0:
                 return ['Invalid row number!']
             if choice == 'Accept':
                 site.accept_user(user_list[page_number][student_row])
             else:
                 site.reject_user(user_list[page_number][student_row])
             return ['Operation completed successfully.']
     return None
コード例 #18
0
 def run(self, site, messages=None):
     site.clear()
     show_messages(messages)
     course_list = paginator(site.get_available_courses(), 20)
     page_number = 0
     while True:
         if len(course_list) == 0:
             print("There is no available course in the system.")
         else:
             pprint_table('Available Courses',
                          copy.copy(course_list[page_number]),
                          foot='Page {} of {}'.format(
                              page_number + 1, len(course_list)))
         menu = ['Home']
         if page_number - 1 >= 0:
             menu.append('Previous Page')
         if page_number + 1 < len(course_list):
             menu.append('Next Page')
         if len(course_list) > 0:
             menu.append('Select')
         choice = choose_from_menu(menu)
         if choice == 'Home':
             site.state = '/student/'
             break
         elif choice == 'Previous Page':
             page_number -= 1
             site.clear()
         elif choice == 'Next Page':
             page_number += 1
             site.clear()
         else:
             course_row = get_input(
                 "Enter row number of the course to get it: ",
                 output_type=int)
             course_row -= 1
             if course_row >= len(
                     course_list[page_number]) or course_row < 0:
                 return ['Invalid row number!']
             site.active_user.add_course(
                 course_list[page_number][course_row])
             return ['You added course successfully.']
     return None
コード例 #19
0
    def get_results(self, obj):

        page = self.context.get("page")
        url = self.context.get("url")
        all = self.context.get("data")
        requset_user = self.context.get('request_user')
        p = paginator(all, page=page, limit=15)

        result = p.get('result')
        result_list = []
        for tag in result:

            all_pic = TagContains.objects.filter(tag=tag).order_by('-id')
            if len(all_pic) == 0:
                continue
            picture = url + str(all_pic[0].post.picture)

            item = {'tag_id': tag.id, 'tag_name': tag.name, 'picture': picture}
            result_list.append(item)

        return result_list
コード例 #20
0
ファイル: assessment.py プロジェクト: Grackins/GoodUniversity
 def run(self, site, messages=None):
     site.clear()
     show_messages(messages)
     teacher_list = paginator(site.get_verified_teachers(), 20)
     page_number = 0
     while True:
         if len(teacher_list) == 0:
             print("There is no student in the system.")
         else:
             pprint_table('Teachers', copy.copy(teacher_list[page_number]),
                          foot='Page {} of {}'.format(page_number + 1, len(teacher_list)))
         menu = ['Home']
         if page_number - 1 >= 0:
             menu.append('Previous Page')
         if page_number + 1 < len(teacher_list):
             menu.append('Next Page')
         if len(teacher_list) > 0:
             menu.append('Rate')
         choice = choose_from_menu(menu)
         if choice == 'Home':
             site.state = '/student/'
             break
         elif choice == 'Previous Page':
             page_number -= 1
             site.clear()
         elif choice == 'Next Page':
             page_number += 1
             site.clear()
         else:
             teacher_row = get_input('Enter the row number of the teacher you wanna rate: ', output_type=int)
             teacher_row -= 1
             if teacher_row < 0 or teacher_row >= len(teacher_list[page_number]):
                 return ['Invalid row number!']
             rate = get_input('How do you rate this teacher?\nChoose a natural number from 1 to 5: ',
                              output_type=int)
             if rate < 1 or rate > 5:
                 return ['Invalid rating!']
             teacher_list[page_number][teacher_row].rates[rate - 1] += 1
             return ['You rated the teacher successfully.']
     return None
コード例 #21
0
    def get_results(self, obj):
        page = self.context.get("page")
        url = self.context.get("url")
        all = self.context.get("requests")
        p = paginator(all, page=page)

        result = p.get('result')
        result_list = []
        for req in result:
            item = {
                'id':
                req.id,
                'requester_username':
                req.requester.username,
                'requester_username_picture':
                url + str(req.requester.profile_picture),
                'request_time':
                req.request_time,
            }
            result_list.append(item)

        return result_list
コード例 #22
0
ファイル: earn.py プロジェクト: lisongjian/ts-ad
    def get(self):
        sdate = self.get_argument('sdate', '')
        edate = self.get_argument('edate','')
        page = self.get_argument('page', 1)
        print page
        if not sdate and not edate:
            etime = date.today().strftime("%Y-%m-%d")
            stime = (date.today() + timedelta(days=-14))
        else:
            stime = sdate
           # etime = datetime.strptime(qdate, "%Y-%m-%d") +timedelta(days=1)
            etime = edate
        if stime == etime:
            qdate = etime
        else:
            qdate = str(stime) + ' - ' + str(etime)
        cborders = orders.get_callback_orders(stime, datetime.strptime(etime,"%Y-%m-%d")+timedelta(days = 1))
        result = paginator(cborders, int(page))
        print result
        data = {
            "title": "广告激活列表",
            "current_user": self.current_user,
            "total": len(cborders),
            "qdate": qdate,
            "sdate": stime,
            "edate": etime,
            "orders": result,
        }
        export = self.get_argument('export',0)
        if export:
            ex = {
                "data" : data
            }
            self.set_header("Content-Type", 'application/ms-excel;charset=utf-8')
            self.set_header("Content-Disposition", "attachment; filename=export_file.xls;charset=utf-8")
            return self.render("earn/export_xls.html",**ex)

        self.render("earn/index.html", **data)
コード例 #23
0
 def run(self, site, messages=None):
     site.clear()
     show_messages(messages)
     student_list = [(student.get_average_score(), student)
                     for student in site.get_verified_students()]
     student_list.sort()
     student_list = student_list[::-1]
     student_list = [[t[0], t[1].name, t[1].serial, t[1].field]
                     for t in student_list]
     student_list = paginator(student_list, 20)
     page_number = 0
     while True:
         if len(student_list) == 0:
             print("There is no verified students in the system.\n")
         else:
             pprint_table(
                 'Students',
                 student_list[page_number],
                 foot='Page {} of {}'.format(page_number + 1,
                                             len(student_list)),
                 cols_title=['Avg. Score', 'Name', 'Student No.', 'Field'])
         menu = ['Home']
         if page_number - 1 >= 0:
             menu.append('Previous Page')
         if page_number + 1 < len(student_list):
             menu.append('Next Page')
         choice = choose_from_menu(menu)
         if choice == 'Home':
             site.state = '/manager/'
             break
         elif choice == 'Previous Page':
             page_number -= 1
             site.clear()
         elif choice == 'Next Page':
             page_number += 1
             site.clear()
     return None
コード例 #24
0
ファイル: exchange.py プロジェクト: lisongjian/ts-ad
    def get(self):
        keys = ['uid', 'address', 'ip', 'sdate', 'edate', 'status', 'ip_address']
        params = {}
        for key in keys:
            params[key] = self.get_argument(key, '').encode('utf-8')

        where_clause = []
        for key in ['uid', 'address', 'ip', 'status' , 'ip_address']:
            if params[key] == '':
                continue
           # where_clause.append("%s = '%s'" % (key,params[key]))
           # print params[key] + '========================'
           # print 'key'
            if params[key] != params['ip_address']:
                where_clause.append("%s = '%s'" % (key, params[key]))
            else:
                where_clause.append("%s REGEXP '%s'" % (key, params[key]))
        if params['sdate']:
            where_clause.append("create_time>='%s'" % params['sdate'])
        if params['edate']:
            where_clause.append("create_time<='%s'" % params['edate'])

        if where_clause:
            sql = "SELECT * FROM `exchange_orders` WHERE " + ' AND '.join(where_clause)
        else:
            sql = "SELECT * FROM `exchange_orders` ORDER BY `id` DESC"
        data = self.db.query(sql)
        export = self.get_argument('export', 0)
        count = 0
        for d in data:
           str(data[count]['create_time'])
           data[count]['create_time'] = d.create_time.strftime("%Y-%m-%d %H:%M:%S")
           count += 1
        if export:
            ex = {
                "data": data
            }
            """导出订单"""
            #data_json = tornado.escape.json_encode(data)

            self.set_header("Content-Type", 'application/ms-excel;charset=utf-8 ')
            self.set_header("Content-Disposition", "attachment; filename=export_file.xls;charset=utf-8")
            #self.write(data_json)
            return self.render("exchange/export_xls.html", **ex)
            #response['Content-Disposition'] = 'attachment; filename=export_file.xls'
            #response['Content-Type'] = 'application/ms-excel; charset=utf-8'

        #self.web.header('Content-type','application/vnd.ms-excel')
        #self.web.headerheader('Transfer-Encoding','chunked')
        #self.web.header('Content-Disposition','attachment;filename="export.xls"')
        #h = HTTPHeaders({"Content-type", "application/ms-excel"})
        #print h
        #response = self.render("exchange/export_xls.html", data)
        #response['Content-Disposition'] = 'attachment; filename=export_file.xls'
        #response['Content-Type'] = 'application/ms-excel; charset=utf-8'
        #return response


        page = int(self.get_argument('page', 1))
        result = paginator(data, page)
        data = {
            "title": "订单搜索结果",
            "current_user": self.current_user,
            "orders": result,
            "params": params,
        }
        self.render("exchange/search.html", **data)
コード例 #25
0
ファイル: user.py プロジェクト: lisongjian/ts-ad
    def get(self):
        field = {}
        page = self.get_argument('page',1)
        sdate = self.get_argument('sdate','')
        edate = self.get_argument('edate','')
        keys = ['tid', 'phone', 'username', 'uid', 'pkg']
        key_ifa = ['ifa']
        key_un = ['un']
        where_clause = []
        where_clause_ifa = []
        where_clause_un = []
        for k in keys:
            value = self.get_argument(k, '')
            field[k] = value
            if value:
                where_clause.append("%s='%s'" % (k, value))
        if sdate != '':
            where_clause.append("`create_time`>='%s'" % (sdate))
        if edate != '':
            where_clause.append("`create_time`<='%s'" % (edate))
        for k in key_ifa:
            value_ifa = self.get_argument(k, '')
            field[k] = value_ifa
            if value_ifa:
                ifa=value_ifa.replace('-','').lower()
                where_clause_ifa.append("%s='%s'" % (k, ifa))
        for k in key_un:
            value_un = self.get_argument(k, '')
            field[k] = value_un
            if value_un:
                where_clause_un.append("%s='%s'" % (k, value_un))

        result = {
            "data": [],
        }
        if where_clause_ifa and self.get_argument('ifa', '') !='':
            '''通过ifa查找'''
            userinfo = self.db.get("SELECT * FROM `devices` WHERE `ifa`= %s", ifa)
            if userinfo:
                uid = int(userinfo['uid'])
                where = "uid = '%s'" % uid
                result['data'] = self.db.query("SELECT * FROM `users` WHERE " + where)
        if where_clause_un and self.get_argument('un', '') !='':
            '''通过设备名称查找'''
            userinfo = self.db.get("SELECT * FROM `devices` WHERE `device_name` REGEXP %s", value_un)
            if userinfo:
                uid = int(userinfo['uid'])
                where = "uid = '%s'" % uid
                result['data'] = self.db.query("SELECT * FROM `users` WHERE " + where)
        if where_clause and self.get_argument('ifa') == '':
            where = ' AND '.join(where_clause)
            result['data'] = self.db.query("SELECT * FROM `users` WHERE " + where)
        field['sdate'] = sdate
        field['edate'] = edate
        result = paginator(result['data'], int(page))
        data = {
            "title": "用户搜索结果",
            "current_user": self.current_user,
            "users": result,
            "field": field
        }
        self.render("user/search.html", **data)
コード例 #26
0
ファイル: views.py プロジェクト: styleold/missuor
def loadmore(request, *args, **kwargs):
    template_name = kwargs.get('template', 'blog/loadmore.html')
    objs = models.Article.objects.filter(is_publish=True).order_by('-create_time')
    context = paginator(request, objs)
    return TemplateResponse(request, template_name, context)
コード例 #27
0
    def get_total_pages(self, obj):
        all = self.context.get('requests')
        p = paginator(all)

        return p.get('total_page')
コード例 #28
0
 def get_total_pages(self, obj):
     all = self.context.get("data")
     p = paginator(all)
     return p.get('total_page')
コード例 #29
0
    def get(self, request, post_id):

        ip = utils.get_client_ip(request)

        utils.start_method_log('GetCommentsApiView: get',
                               authorized_user=request.user.username,
                               request_post_id=post_id)

        if post_id is None:
            logger.info('PaginationApiView: get '
                        '(Post_id is required) username:{}, ip: {}'.format(
                            request.user.username, ip))
            return Response(data={"detail": "Post_id is required."},
                            status=status.HTTP_400_BAD_REQUEST)
        try:
            post_query_set = Posts.objects.get(id=post_id)
        except ObjectDoesNotExist:
            logger.info('PaginationApiView: get '
                        '(Post not found) username:{}, ip: {}'.format(
                            request.user.username, ip))
            return Response(data={"details": "Post not found"},
                            status=status.HTTP_400_BAD_REQUEST)
        profile_private = post_query_set.owner.is_private
        post_owner = post_query_set.owner
        user_profile = request.user
        if post_owner != user_profile and profile_private:
            try:
                follow_status = Followers.objects.get(user=user_profile,
                                                      following=post_owner)
            except ObjectDoesNotExist:
                logger.info(
                    'PaginationApiView: get '
                    '(User not follow this post owner) username:{}, ip: {}'.
                    format(request.user.username, ip))
                return Response(status=status.HTTP_403_FORBIDDEN)

        comment_query_set = Comment.objects.filter(
            post=post_query_set).order_by('-time')
        page = request.GET.get('page')
        pages = utils.paginator(comment_query_set, page=page)
        results = pages.get('result')
        count = pages.get('count')
        total_page = pages.get('total_page')
        results_list = []
        url = str(request.scheme) + '://' + request.get_host() + MEDIA_URL
        for cm in results:
            item = {
                "id": cm.id,
                "username": cm.user.username,
                "profile_picture": url + str(cm.user.profile_picture),
                "comment": cm.content,
                "time": cm.time
            }
            results_list.append(item)
        data = {
            "count": count,
            "total_pages": total_page,
            "results": results_list
        }
        logger.info(
            'PaginationApiView: get '
            '(Successfully return comment list) username:{}, ip: {}'.format(
                request.user.username, ip))
        return Response(data=data, status=status.HTTP_200_OK)
コード例 #30
0
    def get_total_pages(self, obj):
        all = self.context.get('notifs')
        p = paginator(all, limit=15)

        return p.get('total_page')
コード例 #31
0
ファイル: tags.py プロジェクト: styleold/missuor
def edit(request, *args, **kwargs):
    pass

def tag(request, *args, **kwargs):
    template_name = kwargs.get('template', 'blog/index.html')
    extra_context = kwargs.get('extra_context', None)
    tag = args and args[0] or None
    if not tag:
        return HttpResponseRedirect(reverse('tags:all'))
    try:
        o = models.Tag.objects.get(flag=tag)
    except models.Tag.DoesNotExist, e:
        return JsonResponseFailure(msg=u'错误的键', debug=str(e))
    except Exception, e:
        return JsonResponseFailure(msg=u'服务器错误', debug=str(e))

    objs = o.article_set.all().order_by('-create_time')
    context = paginator(request, objs)
    return TemplateResponse(request, template_name, context)

def children(request, *args, **kwargs):
    tag = args and args[0] or None
    if not tag:
        return JsonResponseFailure()

    objs = models.Tag.objects.filter(parent__flag=tag).values_list('flag', flat=True)
    
    return JsonResponseSuccess(choices=list(objs))