def questanswer(request, page=None): context = RequestContext(request) context['title'] = u'Вопрос-ответ' if request.method == 'POST': context['author_error'] = False context['mes_error'] = False if not request.POST.get('q_autor', ''): context['author_error'] = True else: context['q_autor'] = request.POST['q_autor'] if not request.POST.get('q_mes', ''): context['mes_error'] = True else: context['q_mes'] = request.POST['q_mes'] if context['author_error'] or context['mes_error']: pass else: qa = QuestAnswer(author = context['q_autor'], question = context['q_mes']) qa.save() context['ok'] = True context['unanswered'] = QuestAnswer.objects.order_by('-date_publication').filter(is_public=False) context['tags'] = TagName.objects.all() context['alphabet'] = Alphabet.objects.filter(is_action=True).order_by('letter') paginate( context, 'questanswer', QuestAnswer.objects.order_by('-date_publication').filter(is_public=True), count=QA_ON_PAGE, page=page, root=context['current_section'].path ) return render_to_response('qa/questanswer.html', context)
def section(request, section, page=None): context = RequestContext(request) paginate( context, 'articles', query=context['section'].article_set.all(), count=ARTICLES_ON_PAGE, page=page, root=request.current_section.path+section+'/' ) return render_to_response('articles/section.html', context)
def index(request, page=None): context = RequestContext(request) paginate( context, 'articles', Article.objects.order_by('-date_written'), count=ARTICLES_ON_PAGE, page=page, root=request.current_section.path ) return render_to_response('articles/index.html', context)
def action_list(request, page=None): context = get_default_context(request) context['actions'] = Action.objects.filter(is_active=True) paginate( context, 'actions', Action.objects.filter(is_active=True).order_by('-id'), count=COLLECTIONS_ON_PAGE, page=page, root=context['current_section'].path ) context['disables'] = Action.objects.filter(is_active=False).order_by('-id') return render_to_response('action/action.html', context)
def index(request, page=None): context = RequestContext(request) # create_widgets_context(context, 'articles_index', 1, 1) groups = Group.objects.all().order_by('id').values() context['groups'] = build_tree(groups, 'group_id') paginate( context, 'articles', Article.objects.order_by('-date_written'), count=ARTICLES_ON_PAGE, page=page, root=request.current_section.path ) return render_to_response('articles/index.html', context)
def tag(request, tag, page=None): context = RequestContext(request) groups = Group.objects.all().order_by('id').values() context['groups'] = build_tree(groups, 'group_id') context['tagview'] = get_object_or_404(Tag, name=tag) paginate( context, 'articles', query=Article.objects.filter(tags__name__exact=tag).order_by('-date_written'), count=ARTICLES_ON_PAGE, page=page, root=request.current_section.path+tag+'/' ) return render_to_response('articles/tag.html', context)
def section(request, section, page=None): context = RequestContext(request) groups = Group.objects.all().order_by('id').values() context['groups'] = build_tree(groups, 'group_id') context['section'] = get_object_or_404(Group, name=section) paginate( context, 'articles', query=context['section'].article_set.all(), count=ARTICLES_ON_PAGE, page=page, root=request.current_section.path+section+'/' ) return render_to_response('articles/section.html', context)
def action_item(request, slug, page=None): context = get_default_context(request) context['action'] = get_object_or_404(Action, slug=slug) context['crumbs'].append({ 'caption': context['action'].name, 'path': slug, }) paginate( context, 'positions', query=Action.objects.get(slug=slug).products.all().filter(is_enabled=True), count=PRODUCTS_ON_PAGE, page=page, root=context['current_section'].path+slug+'/' ) return render_to_response('action/action-item.html', context)
def get(self, request): """ 题目分页json api接口 --- response_serializer: ProblemSerializer """ problem_id = request.GET.get("problem_id", None) if problem_id: try: # 普通管理员只能获取自己创建的题目 # 超级管理员可以获取全部的题目 problem = Problem.objects.get(id=problem_id) if request.user.admin_type != SUPER_ADMIN and problem.created_by != request.user: return error_response(u"题目不存在") return success_response(ProblemSerializer(problem).data) except Problem.DoesNotExist: return error_response(u"题目不存在") # 获取问题列表 problems = Problem.objects.all().order_by("-create_time") if request.user.admin_type != SUPER_ADMIN: problems = problems.filter(created_by=request.user) visible = request.GET.get("visible", None) if visible: problems = problems.filter(visible=(visible == "true")) keyword = request.GET.get("keyword", None) if keyword: problems = problems.filter(Q(title__contains=keyword) | Q(description__contains=keyword)) return paginate(request, problems, ProblemSerializer)
def get(self, request): """ 比赛题目分页json api接口 --- response_serializer: ContestProblemSerializer """ contest_problem_id = request.GET.get("contest_problem_id", None) if contest_problem_id: try: contest_problem = ContestProblem.objects.get(id=contest_problem_id) if request.user.admin_type != SUPER_ADMIN and contest_problem.created_by != request.user: return error_response(u"比赛题目不存在") return success_response(ContestProblemSerializer(contest_problem).data) except ContestProblem.DoesNotExist: return error_response(u"比赛题目不存在") contest_problems = ContestProblem.objects.all().order_by("sort_index") if request.user.admin_type != SUPER_ADMIN: contest_problems = contest_problems.filter(created_by=request.user).order_by("sort_index") visible = request.GET.get("visible", None) if visible: contest_problems = contest_problems.filter(visible=(visible == "true")) keyword = request.GET.get("keyword", None) if keyword: contest_problems = contest_problems.filter(Q(title__contains=keyword) | Q(description__contains=keyword)) contest_id = request.GET.get("contest_id", None) if contest_id: contest_problems = contest_problems.filter(contest__id=contest_id).order_by("sort_index") return paginate(request, contest_problems, ContestProblemSerializer)
def get(self, request): """ 比赛分页json api接口 --- response_serializer: ContestSerializer """ contest_id = request.GET.get("contest_id", None) if contest_id: try: # 普通管理员只能获取自己创建的题目 # 超级管理员可以获取全部的题目 contest = Contest.objects.get(id=contest_id) if request.user.admin_type != SUPER_ADMIN: contest_set = Contest.objects.filter( groups__in=request.user.managed_groups.all()) if contest not in contest_set: return error_response(u"比赛不存在") return success_response(ContestSerializer(contest).data) except Contest.DoesNotExist: return error_response(u"比赛不存在") if request.user.admin_type == SUPER_ADMIN: contest = Contest.objects.all().order_by("-create_time") else: contest = Contest.objects.filter( groups__in=request.user.managed_groups.all()).distinct( ).order_by("-create_time") visible = request.GET.get("visible", None) if visible: contest = contest.filter(visible=(visible == "true")) keyword = request.GET.get("keyword", None) if keyword: contest = contest.filter( Q(title__contains=keyword) | Q(description__contains=keyword)) return paginate(request, contest, ContestSerializer)
def get(self, request): """ 查询小组列表或者单个小组的信息,查询单个小组需要传递group_id参数,否则返回全部 --- response_serializer: GroupSerializer """ group_id = request.GET.get("group_id", None) # 根据 id 查询小组信息 if group_id: try: group = self.get_group(request, group_id) return success_response(GroupSerializer(group).data) except Group.DoesNotExist: return error_response(u"小组不存在") else: groups = self.get_groups(request) # 搜索小组 if request.GET.get("keyword", None): groups = groups.filter(name__contains=request.GET["keyword"]) # 只返回我创建的小组 适用于超级管理员 if request.GET.get("my_group", None): groups = groups.filter(admin=request.user) # 只返回指定用户的小组 适用于管理员 elif request.GET.get("admin_id", None): groups = groups.filter(admin__id=request.GET["admin_id"]) return paginate(request, groups, GroupSerializer)
def get(self, request): """ 比赛分页json api接口 --- response_serializer: ContestSerializer """ contest_id = request.GET.get("contest_id", None) if contest_id: try: # 普通管理员只能获取自己创建的题目 # 超级管理员可以获取全部的题目 contest = Contest.objects.get(id=contest_id) if request.user.admin_type != SUPER_ADMIN: contest_set = Contest.objects.filter(groups__in=request.user.managed_groups.all()) if contest not in contest_set: return error_response(u"比赛不存在") return success_response(ContestSerializer(contest).data) except Contest.DoesNotExist: return error_response(u"比赛不存在") if request.user.admin_type == SUPER_ADMIN: contest = Contest.objects.all().order_by("-create_time") else: contest = Contest.objects.filter(groups__in=request.user.managed_groups.all()).distinct().order_by("-create_time") visible = request.GET.get("visible", None) if visible: contest = contest.filter(visible=(visible == "true")) keyword = request.GET.get("keyword", None) if keyword: contest = contest.filter(Q(title__contains=keyword) | Q(description__contains=keyword)) return paginate(request, contest, ContestSerializer)
def get(self, request): """ 题目分页json api接口 --- response_serializer: ProblemSerializer """ problem_id = request.GET.get("problem_id", None) if problem_id: try: # 普通管理员只能获取自己创建的题目 # 超级管理员可以获取全部的题目 problem = Problem.objects.get(id=problem_id) if request.user.admin_type != SUPER_ADMIN and problem.created_by != request.user: return error_response(u"题目不存在") return success_response(ProblemSerializer(problem).data) except Problem.DoesNotExist: return error_response(u"题目不存在") # 获取问题列表 problems = Problem.objects.all().order_by("-create_time") if request.user.admin_type != SUPER_ADMIN: problems = problems.filter(created_by=request.user) visible = request.GET.get("visible", None) if visible: problems = problems.filter(visible=(visible == "true")) keyword = request.GET.get("keyword", None) if keyword: problems = problems.filter( Q(title__contains=keyword) | Q(description__contains=keyword)) return paginate(request, problems, ProblemSerializer)
def get(self, request): """ 查询比赛提交,单个比赛题目提交的adminAPI --- response_serializer: SubmissionSerializer """ problem_id = request.GET.get("problem_id", None) contest_id = request.GET.get("contest_id", None) if contest_id: try: contest = Contest.objects.get(pk=contest_id) except Contest.DoesNotExist: return error_response(u"比赛不存在!") if request.user.admin_type != SUPER_ADMIN and contest.created_by != request.user: return error_response(u"您无权查看该信息!") submissions = Submission.objects.filter(contest_id=contest_id).order_by("-create_time") else: if problem_id: try: contest_problem = ContestProblem.objects.get(pk=problem_id) except ContestProblem.DoesNotExist: return error_response(u"问题不存在!") if request.user.admin_type != SUPER_ADMIN and contest_problem.contest.created_by != request.user: return error_response(u"您无权查看该信息!") submissions = Submission.objects.filter(contest_id=contest_problem.contest_id).order_by("-create_time") else: return error_response(u"参数错误!") if problem_id: submissions = submissions.filter(problem_id=problem_id) return paginate(request, submissions, SubmissionSerializer)
def get(self, request): problem_id = request.GET.get("problem_id", None) if not problem_id: return error_response(u"参数错误") submissions = Submission.objects.filter( problem_id=problem_id, contest_id__isnull=True).order_by("-create_time") return paginate(request, submissions, SubmissionSerializer)
def get(self, request): page = request.GET.get("page", 1) data, previousPage, nextPage, numberOfPages = paginate( [vendor.dict for vendor in models.VendorModel.objects.all()], page) return json_response(200, data=data, number_of_pages=numberOfPages, previous_page=previousPage, next_page=nextPage)
def get(self, request): """ 返回管理的群的加群请求 --- response_serializer: JoinGroupRequestSerializer """ requests = JoinGroupRequest.objects.filter(group__in=Group.objects.filter(admin=request.user, visible=True), status=False) return paginate(request, requests, JoinGroupRequestSerializer)
def get(self, request): node = Node.objects.all().order_by('id') keyword = request.GET.get("keyword", None) if keyword: node = node.filter(Q(title__contains=keyword) | Q(description__contains=keyword)) for item in node: topics = Topic.objects.filter(node=item) item.num_of_topics= "{}({})".format(topics.count(), topics.visible().count()) return paginate(request, node , EditNodeSerializer)
def get(self, request): """ 返回管理的群的加群请求 --- response_serializer: JoinGroupRequestSerializer """ requests = JoinGroupRequest.objects.filter( group__in=Group.objects.filter(admin=request.user, visible=True), status=False) return paginate(request, requests, JoinGroupRequestSerializer)
def get(self,request): posts=Post.objects.all() topic_id=request.GET.get("topic_id",None) keyword = request.GET.get("keyword", None) if keyword and topic_id: posts = Post.objects.filter(Q(content_raw__contains=keyword),topic_id=topic_id) elif topic_id: posts = Post.objects.filter(topic_id=topic_id) else : return error_response("no this topic_id!") return paginate(request,posts,PostSerializer)
def get(self, request): page = request.GET.get("page", 1) data, previousPage, nextPage, numberOfPages = paginate([ withdrawalRequest.dict for withdrawalRequest in models.WithdrawalRequestModel.objects.filter(user=request.user) ], page) return json_response(200, data=data, number_of_pages=numberOfPages, previous_page=previousPage, next_page=nextPage)
def get(self, request): """ 公告分页json api接口 --- response_serializer: AnnouncementSerializer """ announcement = Announcement.objects.all().order_by("-create_time") visible = request.GET.get("visible", None) if visible: announcement = announcement.filter(visible=(visible == "true")) return paginate(request, announcement, AnnouncementSerializer)
def get(self, request): """ 搜索小组的api,需要传递keyword参数 --- response_serializer: GroupSerializer """ keyword = request.GET.get("keyword", None) if not keyword: return error_response(u"参数错误") # 搜索包含这个关键词的 没有解散的 而且允许加入的小组 groups = Group.objects.filter(name__contains=keyword, visible=True, join_group_setting__lte=2) return paginate(request, groups, GroupSerializer)
def get(self, request): page = request.GET.get("page", 1) data, previousPage, nextPage, numberOfPages = paginate([ payment.dict for payment in request.user.payments.all() ], page) return json_response( 200, data=data, number_of_pages=numberOfPages, previous_page=previousPage, next_page=nextPage )
def get(self, request): """ 公告分页json api接口 --- response_serializer: AnnouncementSerializer """ if request.user.admin_type == SUPER_ADMIN: announcement = Announcement.objects.all().order_by("-last_update_time") else: announcement = Announcement.objects.filter(created_by=request.user) visible = request.GET.get("visible", None) if visible: announcement = announcement.filter(visible=(visible == "true")) return paginate(request, announcement, AnnouncementSerializer)
def get(self, request): """ 获取全部判题服务器 """ judge_server_id = request.GET.get("judge_server_id", None) if judge_server_id: try: judge_server = JudgeServer.objects.get(id=judge_server_id) except JudgeServer.DoesNotExist: return error_response(u"判题服务器不存在") return success_response(JudgesSerializer(judge_server).data) judge_server = JudgeServer.objects.all() return paginate(request, judge_server, JudgesSerializer)
def get(self, request): """ 查询小组成员的api,需要传递group_id参数 --- response_serializer: GroupMemberSerializer """ group_id = request.GET.get("group_id", None) if not group_id: return error_response(u"参数错误") try: group = self.get_group(request, group_id) except Group.DoesNotExist: return error_response(u"小组不存在") return paginate(request, UserGroupRelation.objects.filter(group=group), GroupMemberSerializer)
def get(self,request): topics = Topic.objects.all().order_by("order") keyword = request.GET.get("keyword", None) if keyword: topics = Topic.objects.filter(Q(title__contains=keyword)) ''' |Q(content_raw__contain=keyword)) user=User.objects.filter(Q(username=keyword)) if user: topics+=User.topics.all() ''' topic_id = request.GET.get("topic_id", None) if topic_id: topics=Topic.objects.filter(id=topic_id) return paginate(request,topics ,TopicSerializer)
def get(self, request): """ 查询比赛提交,单个比赛题目提交的adminAPI --- response_serializer: SubmissionSerializer """ problem_id = request.GET.get("problem_id", None) contest_id = request.GET.get("contest_id", None) # 需要 problem_id 和 contest_id 两个参数 否则会在check_user_contest_permission 的时候被拦截 if problem_id: submissions = Submission.objects.filter(contest_id=contest_id, problem_id=problem_id).order_by("-create_time") # 需要 contest_id 参数 else: submissions = Submission.objects.filter(contest_id=contest_id).order_by("-create_time") return paginate(request, submissions, SubmissionSerializer)
def get(self, request): """ 比赛分页json api接口 --- response_serializer: ContestSerializer """ if request.user.admin_type == SUPER_ADMIN: contest = Contest.objects.all().order_by("-create_time") else: contest = Contest.objects.filter(created_by=request.user).order_by("-create_time") visible = request.GET.get("visible", None) if visible: contest = contest.filter(visible=(visible == "true")) keyword = request.GET.get("keyword", None) if keyword: contest = contest.filter(Q(title__contains=keyword) | Q(description__contains=keyword)) return paginate(request, contest, ContestSerializer)
def get(self, request): """ 用户分页json api接口 --- response_serializer: UserSerializer """ user = User.objects.all().order_by("-create_time") admin_type = request.GET.get("admin_type", None) if admin_type: try: user = user.filter(admin_type__gte=int(admin_type)) except ValueError: return error_response(u"参数错误") keyword = request.GET.get("keyword", None) if keyword: user = user.filter(Q(username__contains=keyword) | Q(real_name__contains=keyword) | Q(email__contains=keyword)) return paginate(request, user, UserSerializer)
def get(self, request): """ 用户分页json api接口 --- response_serializer: UserSerializer """ user = User.objects.all().order_by("-create_time") admin_type = request.GET.get("admin_type", None) if admin_type: try: user = user.filter(admin_type__gte=int(admin_type)) except ValueError: return error_response(u"参数错误") keyword = request.GET.get("keyword", None) if keyword: user = user.filter( Q(username__contains=keyword) | Q(real_name__contains=keyword) | Q(email__contains=keyword)) return paginate(request, user, UserSerializer)
def get(self, request): """ 查询比赛提交,单个比赛题目提交的adminAPI --- response_serializer: SubmissionSerializer """ problem_id = request.GET.get("problem_id", None) contest_id = request.GET.get("contest_id", None) # 需要 problem_id 和 contest_id 两个参数 否则会在check_user_contest_permission 的时候被拦截 if problem_id: submissions = Submission.objects.filter( contest_id=contest_id, problem_id=problem_id).order_by("-create_time") # 需要 contest_id 参数 else: submissions = Submission.objects.filter( contest_id=contest_id).order_by("-create_time") return paginate(request, submissions, SubmissionSerializer)
def get(self, request): """ 题目分页json api接口 --- response_serializer: ProblemSerializer """ problem_id = request.GET.get("problem_id", None) if problem_id: try: problem = Problem.objects.get(id=problem_id) return success_response(ProblemSerializer(problem).data) except Problem.DoesNotExist: return error_response(u"题目不存在") problem = Problem.objects.all().order_by("-create_time") visible = request.GET.get("visible", None) if visible: problem = problem.filter(visible=(visible == "true")) keyword = request.GET.get("keyword", None) if keyword: problem = problem.filter(Q(title__contains=keyword) | Q(description__contains=keyword)) return paginate(request, problem, ProblemSerializer)
def get(self, request): problem_id = request.GET.get("problem_id", None) if not problem_id: return error_response(u"参数错误") submissions = Submission.objects.filter(problem_id=problem_id, contest_id__isnull=True).order_by("-create_time") return paginate(request, submissions, SubmissionSerializer)
def catalog_list(request, page=None): context = get_default_context(request) # Getting catalog for the section # @todo improve! o___O cs = context['current_section'] if cs.path != '/catalog/': if Catalog.objects.filter(section=cs): context['catalog'] = Catalog.objects.get(section=cs) elif Catalog.objects.filter(section=cs.parent): context['catalog'] = Catalog.objects.get(section=cs.parent) elif Catalog.objects.filter(section=cs.parent.parent): context['catalog'] = Catalog.objects.get(section=cs.parent.parent) else: context['catalog'] = Catalog.objects.get(section=cs.parent.parent.parent) context['catalog_properties'] = context['catalog'].properties.all() else: context['catalog'] = None context['catalog_properties'] = [] for p in context['catalog_properties']: if p.type == 4: fv = request.GET.getlist(p.slug) if fv is not None: arr = [] for v in fv: arr.append(int(v)) p.filtered_values = arr else: fv = request.GET.get(p.slug) if fv is not None: p.filtered_value = fv # Is it terminal section or not? if context['current_section'].has_children(): # Non-terminal section context['subsections'] = context['current_section'].children.filter(is_enabled=True) current_path = context['current_section'].path descendants_ids = Section.objects.filter(path__startswith=current_path).values('id') descendants_ids = [x['id'] for x in descendants_ids] if context['aphaline_edit_mode']: paginate( context, 'catalog_positions', Product.objects.filter(section__in=descendants_ids) \ .filter(is_exist=True).order_by('-is_enabled', '-order'), count=PRODUCTS_ON_PAGE, page=page, root=context['current_section'].path ) else: paginate( context, 'catalog_positions', Product.objects.filter(section__in=descendants_ids) \ .filter(is_exist=True, is_enabled=True).order_by('-order'), count=PRODUCTS_ON_PAGE, page=page, root=context['current_section'].path ) return render_to_response('catalog/list_nonterminal.html', context) else: if context['aphaline_edit_mode']: paginate( context, 'catalog_positions', Product.objects.filter(section=context['current_section']).order_by('-is_enabled', '-is_exist', '-order'), count=PRODUCTS_ON_PAGE, page=page, root=context['current_section'].path ) else: paginate( context, 'catalog_positions', Product.objects.filter(section=context['current_section'], is_enabled=True).order_by('-is_exist', '-order'), count=PRODUCTS_ON_PAGE, page=page, root=context['current_section'].path ) return render_to_response('catalog/list_terminal.html', context)
def get(self,request): appendixs=Appendix.objects.all() topic_id=request.GET.get("topic_id",None) if topic_id: appendixs = Appendix.objects.filter(topic=topic_id) return paginate(request,appendixs,AppendixSerializer)