实训项目第二周2
来源:互联网 发布:苏菲淘宝旗舰店 编辑:程序博客网 时间:2024/05/18 03:49
以下是论坛方面的代码
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import get_object_or_404, render, render_to_response
# Create your views here.
from django.http import HttpResponseRedirect, HttpResponse
from django.urls import reverse
from django.utils import timezone
from django.template import loader, RequestContext
from django.views import generic
from django import forms
from .models import Problem, User, SubmitCode, AcceptedCode, Discussion, Response
class DiscussionForm(forms.Form):
title = forms.CharField()
text = forms.CharField(widget=forms.Textarea)
code = forms.CharField(widget=forms.Textarea)
# coding page , submit code , get result
class CodingView(generic.TemplateView):
template_name = 'judgeOL/coding.html'
def get_context_data(self, **kwargs):
context = super(CodingView, self).get_context_data(**kwargs)
context['problem_id'] = self.kwargs['problem_id']
return context
# bbs page, so many discussions
class DiscussionView(generic.ListView):
model = Discussion
template_name = 'judgeOL/discussions.html'
context_object_name = 'discussion_list'
@staticmethod
def get_discussions(problem_id):
return Discussion.objects.get(problem_id=problem_id)
def get_context_data(self, **kwargs):
context = super(DiscussionView, self).get_context_data(**kwargs)
context['problem_id'] = self.kwargs['problem_id']
context['problem_name'] = Problem.objects.get(pk=self.kwargs['problem_id']).name
return context
# every discussions have a lot of responses
class ResponseView(generic.ListView):
model = Response
template_name = 'judgeOL/responses.html'
context_object_name = 'response_list'
def get_queryset(self):
return Response.objects.all().filter(discussion_id=self.kwargs['discussion_id'])
def get_context_data(self, **kwargs):
context = super(ResponseView, self).get_context_data(**kwargs)
context['discussion'] = Discussion.objects.get(pk=self.kwargs['discussion_id'])
context['problem_id'] = self.kwargs['problem_id']
return context
class EditView(generic.TemplateView):
template_name = 'judgeOL/edit.html'
def get_context_data(self, **kwargs):
context = super(EditView, self).get_context_data(**kwargs)
context['problem_id'] = self.kwargs['problem_id']
return context
def new_discussion(request, problem_id):
if request.method == 'GET':
return HttpResponseRedirect(reverse('judgeOL:discussions', args={problem_id}))
else:
try:
name = request.POST['title']
pub_text = request.POST['text']
pub_code = request.POST['code']
user_id = request.session['user_id']
Discussion.objects.create(user_id=user_id, problem_id=problem_id, name=name, pub_text=pub_text,
pub_code=pub_code, pub_date=timezone.now(), vote_count=1, view_count=1)
return HttpResponseRedirect(reverse('judgeOL:discussions', args={problem_id}))
except KeyError:
return HttpResponse('key error')
"""
discussion_form = DiscussionForm(request.POST)
if discussion_form.is_valid():
name = discussion_form.cleaned_data['title']
pub_text = discussion_form.cleaned_data['pub_text']
pub_code = discussion_form.cleaned_data['pub_code']
user_id = request.session['user_id']
Discussion.objects.create(user_id=user_id, problem_id=problem_id, name=name, pub_text=pub_text,
pub_code=pub_code, pub_date=timezone.now(), vote_count=1, view_count=1)
return HttpResponse(reverse('judgeOL:discussions', args={problem_id}))
else:
return HttpResponse('judgeOL/error.html')
- 项目实训第二周2
- 实训项目第二周2
- 第二周项目2
- 第二周项目2
- 第二周 项目2
- 第二周项目-2
- 第二周项目2
- 第二周项目2
- 第二周【项目2
- 第二周 项目2
- 【第二周】项目2
- 第二周-项目2
- 项目实训——第二周(2)
- 实训项目第二周1
- 第二周项目三.2
- 第二周项目2长方体
- 第二周项目2汉诺塔
- 第二周项目2 循环
- 极验验证码 Geetest
- Vue2.0全家桶仿腾讯体育APP
- Codeforces 498C Array and Operations 题解
- hadoop安装、使用过程的异常汇总
- 【Python学习系列二】Python默认编码和Eclipse环境的冲突问题
- 实训项目第二周2
- soap命名空间的别名
- 特斯拉式升级
- 设计模式-简单工厂模式
- 使用linux命令获取文件夹下所有文件的绝对路径
- 使用spring jdbc的batchUpdate功能提高性能
- 用PS做一个简单的相机图标
- IE11 Windows7下F12 DOC资源管理器不能用Exception in window.onload: Error: An error has ocurredJSPlugin.3005 20
- 字符串操作