-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
118 lines (99 loc) · 3.83 KB
/
main.py
File metadata and controls
118 lines (99 loc) · 3.83 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import webapp2
from google.appengine.ext import db
from google.appengine.ext.webapp import template
import cgi
from handlers import *
from utils import *
from models import *
#not using sessions tables as of yet.
class MainPage(webapp2.RequestHandler):
def get(self):
user=get_current_user(self)
if user:
self.redirect("/home")
LOGIN_URL = users.create_login_url("/home")
self.response.out.write(template.render("templates/landingpage.html",locals()))
class Home(webapp2.RequestHandler):
def get(self):
user=get_current_user(self)
if user:
self.response.out.write(template.render("templates/home.html",locals()))
else:
self.redirect('/')
class ViewQuestions(webapp2.RequestHandler):
def get(self):
user=get_current_user(self)
if user:
status = True
else:
status = False
tags=Tag.all()
self.response.out.write(template.render("templates/view.html",locals()))
def post(self):
user=get_current_user(self)
if user:
status = True
else:
status = False
tags=Tag.all()
tag=self.request.get('tag')
q = Question.all()
questions=q.filter("tags =", tag)
if not user:
questions=questions.fetch(10)
self.response.out.write(template.render("templates/view.html",locals()))
class CreateCategory(webapp2.RequestHandler):
def get(self):
user=get_current_user(self)
if user:
tags=Tag.all()
self.response.out.write(template.render("templates/tags.html",locals()))
else:
self.redirect('/')
def post(self):
user=get_current_user(self)
if user:
new_tag=self.request.get('newtag')
query=Tag.all()
query.filter("tag =", new_tag)
q=query.get()
if q is not None:
message='Tag already Exists!'
tags=Tag.all()
self.response.out.write(template.render("templates/tags.html",locals()))
else:
tag=Tag(tag=new_tag)
tag.put()
message='Tag added!'
tags=Tag.all()
self.response.out.write(template.render("templates/tags.html",locals()))
else:
self.redirect('/')
class CreateQuestion(webapp2.RequestHandler):
def get(self):
user=get_current_user(self)
if user:
tags=Tag.all()
message = 'Please create a Question'
self.response.out.write(template.render("templates/index.html", locals()))
else:
self.redirect('/')
def post(self):
user=get_current_user(self)
if user:
new_question=self.request.get('question')
tag=self.request.get('tag')
question=Question(content=new_question,tags=tag)
question.put()
tags=Tag.all()
message= 'Question Added! Add more!'
self.response.out.write(template.render("templates/index.html",locals()))
else:
self.redirect('/')
class Logout(webapp2.RequestHandler):
def get(self):
self.redirect(users.create_logout_url("/"))
app = webapp2.WSGIApplication([('/', MainPage),('/home',Home),
('/view-questions', ViewQuestions),('/create-questions', CreateQuestion),('/add-category',CreateCategory),('/login',Login),
('/register',Register),('/logout',Logout)],
debug=True)