-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
101 lines (83 loc) · 3.09 KB
/
Copy pathviews.py
File metadata and controls
101 lines (83 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Create your views here.
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.template.loader import get_template
from django.template import Context
from article.models import Article, Comment
from article.forms import CreateArticle, CreateComment
from django.http import HttpResponseRedirect
from django.core.context_processors import csrf
from django.utils import timezone
import datetime
def mainView(request):
name = 'Avinash'
return render_to_response('main.html',{'name':name})
def mainView2(reqest):
name= 'Avinash'
f = get_template('main.html')
html = f.render(Context({'name':name}))
return HttpResponse(html)
def allView(request):
username = request.user.username
return render_to_response('articles.html', {'articles':Article.objects.all(), 'username':username})
def articleView(request, article_id=1):
username = request.user.username
if username is not None:
a= Article.objects.get(id = article_id)
print a.id
if request.POST:
print 'Am in'
form = CreateComment(request.POST)
if form.is_valid():
c = form.save(commit = False)
c.pub_date = datetime.datetime.now()
c.article = a
c.save()
return HttpResponseRedirect('/article/%s' % article_id)
args_c = {}
args_c.update(csrf(request))
args_c['article']= a
args_c['comment_form'] = CreateComment()
print 'Am in f'
return render_to_response('article.html', args_c)
# return render_to_response('article.html', {'article': Article.objects.get(id=article_id), 'username':username})
def createView(request):
if request.POST:
form = CreateArticle(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/article/all')
c = {}
c.update(csrf(request))
c['form'] = CreateArticle()
return render_to_response('create.html',c)
def likeView(request,article_id):
a = Article.objects.get(id=article_id)
count = a.likes
count += 1
a.likes = count
a.save();
return HttpResponseRedirect('/article/%s' %article_id)
def searchTitleView(request):
if request.POST:
search_text = request.POST['search_text']
else:
search_text = ''
articles = Article.objects.filter(title__contains=search_text)
return render_to_response('search.html', {'articles': articles})
#def commentView(request, article_id):
# a= Article.objects.get(id = article_id)
# if request.POST:
# print 'Am in'
# form = CreateComment(request.POST)
# if form.is_valid():
# form.save(commit = False)
# form.pub_date = timezone.now()
# form.save()
# return HttpResponseRedirect('/articcle/%s' % article_id)
# args_c = {}
# args_c.update(csrf(request))
# args_c['article']= a
# args_c['comment_form'] = CreateComment()
# print 'Am in f'
# return render_to_response('article.html', args_c)