forked from erwenzhang/ConnexUs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
management.py
116 lines (97 loc) · 4.63 KB
/
management.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
105
106
107
108
109
110
111
112
113
114
115
116
import cgi
import urllib
from google.appengine.api import users
from google.appengine.ext import ndb
from google.appengine.ext import db
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.api import images
from stream import Stream
from stream import Picture
from stream import CountViews
from stream import Count_pic
import webapp2
import jinja2
import os
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
class ManagementPage(webapp2.RequestHandler):
def get(self):
print("test!!")
dellsts=self.request.get_all("status")
if (len(dellsts) > 0):
streams=Stream.query(Stream.name.IN(dellsts), Stream.author==users.get_current_user()).fetch()
counts=CountViews.query(CountViews.name.IN(dellsts), ancestor=ndb.Key('User', users.get_current_user().nickname())).fetch()
for stream in streams:
pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1",db.Key.from_path('Stream',stream.name))
for pic in pictures:
images.delete_serving_url(pic.imgkey)
blobstore.delete(pic.imgkey)
db.delete(pictures)
pic_count= Count_pic.query(ancestor=ndb.Key('Stream',stream.name))
ndb.delete_multi(ndb.put_multi(pic_count))
#print pic_count
ndb.delete_multi(ndb.put_multi(streams))
ndb.delete_multi(ndb.put_multi(counts))
dellsts=self.request.get_all("status1")
#self.response.write(len(dellsts))
if (len(dellsts) > 0):
streams=Stream.query(Stream.name.IN(dellsts)).fetch()
for stream in streams:
if(users.get_current_user() and users.get_current_user().nickname() in stream.subscribers):
stream.subscribers.remove(users.get_current_user().nickname())
stream.put()
picNum_list = []
streams_1=Stream.query(Stream.author==users.get_current_user()).order(-Stream.creattime).fetch()
for stream in streams_1:
pic_count= Count_pic.query(ancestor=ndb.Key('Stream',stream.name)).fetch()[0]
pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1 "+"ORDER BY uploaddate DESC",db.Key.from_path('Stream',stream.name))
# print (stream.name, pic_count.numbers)
# picNum_list.append(pic_count.numbers)
picNum_list.append(pictures.count())
streams = Stream.query().fetch()
streams_2 = []
count_list = []
user_name = users.get_current_user().nickname()
# url =users.create_login_url('/')
# if(users.get_current_user()):
#user_name = users.get_current_user().nickname()
url = users.create_logout_url('/')
for stream in streams:
if(users.get_current_user().email().lower() in stream.subscribers):
count=CountViews.query(CountViews.name==stream.name,ancestor=ndb.Key('User',stream.author_name)).fetch()[0]
pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1 "+"ORDER BY uploaddate DESC",db.Key.from_path('Stream',stream.name))
stream.numberofpictures = pictures.count()
streams_2.append(stream)
count_list.append(count.numbers)
#else:
# self.redirect(url,permanent=False)
template_values = {
'user_name':user_name,
'streams_1': streams_1,
'streams_2': streams_2,
'count_list': count_list,
'url': url,
"picNum_list":picNum_list
}
template = JINJA_ENVIRONMENT.get_template('management_index.html')
self.response.write(template.render(template_values))
#if not users.get_current_user():
# no use!!!!!!
class DeleteStreams(webapp2.RequestHandler):
def get(self):
original_url=self.request.headers['Referer']
dellsts=self.request.get_all("status")
if(len(dellsts)>0):
streams=Stream.query(Stream.name.IN(dellsts), Stream.author==users.get_current_user()).fetch()
for stream in streams:
pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1",db.Key.from_path('Stream',stream.name))
db.delete(pictures)
ndb.delete_multi(ndb.put_multi(streams))
self.redirect(original_url)
application = webapp2.WSGIApplication([
('/management', ManagementPage),
('/delstream', DeleteStreams),
], debug=True)