def add_news(request, dn): d = department.objects.get(name=dn) if request.method == 'GET': return render_to_response('news/add.html', { 'user': request.user, 'dn': dn, 'title': '添加一条新闻', 'department': d.cn }, context_instance=RequestContext(request)) elif request.method == 'POST': n = list() title = request.POST['title'] url = request.POST['url'] auth = request.user if title and url: n.title = title n.url = url n.auth = auth n.department_name = d n.save() else: messages.add_message( request, messages.WARNING, _(u'标题或链接不能为空'), ) return HttpResponseRedirect(reverse('add_news', kwargs={'dn': dn})) return HttpResponseRedirect(reverse('news_index', kwargs={'dn': dn}))
def news_index(request, dn): if department.objects.filter(name=dn).exists(): d = department.objects.get(name=dn) new = list() new.department_name = d news = list.objects.filter(department_name=d) return render_to_response( "news/list.html", {"user": request.user, "dn": dn, "title": u"News %s" % (d.cn), "news": news, "department": d.cn}, context_instance=RequestContext(request), ) return HttpResponseRedirect(reverse("index"))
def news_index(request, dn): if department.objects.filter(name=dn).exists(): d = department.objects.get(name=dn) new = list() new.department_name = d news = list.objects.filter(department_name=d) return render_to_response('news/list.html', { 'user': request.user, 'dn': dn, 'title': u'News %s' % (d.cn), 'news': news, 'department': d.cn }, context_instance=RequestContext(request)) return HttpResponseRedirect(reverse('index'))
def add_news(request, dn): d = department.objects.get(name=dn) if request.method == "GET": return render_to_response( "news/add.html", {"user": request.user, "dn": dn, "title": "添加一条新闻", "department": d.cn}, context_instance=RequestContext(request), ) elif request.method == "POST": n = list() title = request.POST["title"] url = request.POST["url"] auth = request.user if title and url: n.title = title n.url = url n.auth = auth n.department_name = d n.save() else: messages.add_message(request, messages.WARNING, _(u"标题或链接不能为空")) return HttpResponseRedirect(reverse("add_news", kwargs={"dn": dn})) return HttpResponseRedirect(reverse("news_index", kwargs={"dn": dn}))