-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.py
104 lines (86 loc) · 3.34 KB
/
form.py
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
import os
import cgi
import models
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext import db
import wsgiref.handlers
class Form(webapp.RequestHandler):
def get(self):
template_values = {
}
path = os.path.join(os.path.dirname(__file__), 'form.html')
self.response.out.write(template.render(path, template_values))
def post(self):
app=models.App(
name=cgi.escape(self.request.POST.get('name')),
appid=cgi.escape(self.request.POST.get('name')),
gov=False,
url=cgi.escape(self.request.POST.get('url')),
summary=cgi.escape(self.request.POST.get('summary')),
description=cgi.escape(self.request.POST.get('description')),
category=cgi.escape(self.request.POST.get('category')),
tags=cgi.escape(self.request.POST.get('tags')),
submittername=cgi.escape(self.request.POST.get('submittername')),
submitterphone=cgi.escape(self.request.POST.get('submitterphone')),
submitteremail=cgi.escape(self.request.POST.get('submitteremail'))
)
if (cgi.escape(self.request.POST.get('gov'))=="True"):
app.gov=True
else:
app.gov=False
app.sourcecode=cgi.escape(self.request.POST.get('sourcecode'))
app.license=cgi.escape(self.request.POST.get('license'))
#authors=cgi.escape(self.request.get('name'))
if 'iconfile' in self.request.POST:
if (self.request.POST.get('iconfile', None) is None or
not self.request.POST.get('iconfile', None).filename):
pass
else:
picture = self.request.POST.get('iconfile').file.read()
appid = cgi.escape(self.request.POST.get('name'))
type = "icon"
im = models.Image()
im.appid = appid
im.type = type
im.picture = picture
im.save()
for i in range(5):
file="file"+str(i)
if file in self.request.POST:
if (self.request.POST.get(file) == ""):
pass
else:
picture = self.request.POST.get(file).file.read()
appid = cgi.escape(self.request.POST.get('name'))
type = "screenshot"+str(i)
im = models.Image()
im.appid = appid
im.type = type
im.picture = picture
im.save()
for i in range(5):
author="author"+str(i)
url="url"+str(i)
if author in self.request.POST:
if (self.request.POST.get(author) == "" or self.request.POST.get(url, None) == ""):
pass
else:
dev=models.Developer(
appid = app.appid,
name = cgi.escape(self.request.POST.get(author)),
url = cgi.escape(self.request.POST.get(url)))
dev.save()
app.stars=0
app.votes=0
app.rating=0.0
app.save()
template_values = {
}
path = os.path.join(os.path.dirname(__file__), 'submit.html')
self.response.out.write(template.render(path, template_values))
def main():
application = webapp.WSGIApplication([('/submit', Form)], debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == "__main__":
main()