-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincanto.py
361 lines (285 loc) · 15.4 KB
/
incanto.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
from operator import truediv
import loader
from cherrypy import request
import cherrypy
import os.path
import configparser
import urllib
from urllib.request import urlopen
from jinja2 import Environment, FileSystemLoader
from Connect import Connect
env = Environment(loader=FileSystemLoader('templates'))
class HelloWorld():
@cherrypy.expose
def index(self,**kwargs):
if cherrypy.url() == 'http://carlozanieri.it/' :
tmpl = env.get_template('mytemplate.html')
if kwargs :
pag = kwargs['pag']
blogid = kwargs['blogid']
else :
pag="blog"
page = tmpl.render(pag=pag,products=Connect.products(""), target=kwargs, manifestazione="blog", menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "mugello"), luogo = "mugello", urlx=cherrypy.url())
elif cherrypy.url() == 'http://web.carlozanieri.it/':
tmpl = env.get_template('carlozanieriweb.html')
page= tmpl.render( products=Connect.products(""), blogs=Connect.blog(""), target='World', menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "index"), luogo = "index")
elif cherrypy.url() == 'http://linuxmugello.net/' :
tmpl = env.get_template('mytemplate.html')
page = tmpl.render( blogs=Connect.blog(""), target='World', menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "mugello"), luogo = "mugello", urlx=cherrypy.url())
elif cherrypy.url() == 'http://localhost/':
tmpl = env.get_template('uno/index4.html')
if kwargs :
pag = kwargs['pag']
blogid = kwargs['blogid']
else :
pag="blog"
page = tmpl.render(pag=pag,products=Connect.products(""), target=kwargs, manifestazione="blog", menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "mugello"), luogo = "mugello", urlx=cherrypy.url())
elif cherrypy.url() == 'http://localhost:7575/':
tmpl = env.get_template('uno/index4.html')
if kwargs :
pag = kwargs['pag']
blogid = kwargs['blogid']
else :
pag="blog"
page = tmpl.render(pag=pag,products=Connect.products(""), target=kwargs, manifestazione="blog", menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "mugello"), luogo = "mugello", urlx=cherrypy.url())
elif cherrypy.url() == 'http://carlozanieri.it:7575/':
tmpl = env.get_template('uno/index4.html')
if kwargs :
pag = kwargs['pag']
blogid = kwargs['blogid']
else :
pag="blog"
page = tmpl.render(pag=pag,products=Connect.products(""), target=kwargs, manifestazione="blog", menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "mugello"), luogo = "mugello", urlx=cherrypy.url())
elif cherrypy.url() == 'http://91.134.132.25:7575/':
tmpl = env.get_template('uno/index4.html')
if kwargs :
pag = kwargs['pag']
blogid = kwargs['blogid']
else :
pag="blog"
page = tmpl.render(pag=pag,products=Connect.products(""), target=kwargs, manifestazione="blog", menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "mugello"), luogo = "mugello", urlx=cherrypy.url())
elif cherrypy.url() == 'carlozanieri.it' :
tmpl = env.get_template('mytemplate.html')
if kwargs :
pag = kwargs['pag']
else :
pag="master"
page = tmpl.render(pag=pag, products=Connect.products(""), target=kwargs, manifestazione="blog", menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "mugello"), luogo = "mugello", urlx=cherrypy.url())
elif cherrypy.url() == 'http://carlozanieri.it/' :
tmpl = env.get_template('mytemplate.html')
if kwargs :
pag = kwargs['pag']
else :
pag="master"
page = tmpl.render(pag=pag,products=Connect.products(""), target=kwargs, manifestazione="blog", menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "mugello"), luogo = "mugello", urlx=cherrypy.url())
elif cherrypy.url() == 'http://incanto.carlozanieri.it/' :
tmpl = env.get_template('mytemplate.html')
if kwargs :
pag = kwargs['pag']
blogid = kwargs['blogid']
else :
pag="django"
page = tmpl.render(pag=pag,blogs=Connect.blog(""), target=kwargs, manifestazione="blog", menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "mugello"), luogo = "mugello", urlx=cherrypy.url())
elif cherrypy.url() == 'http://0.0.0.0/' :
tmpl = env.get_template('index.html')
page = tmpl.render(blogs=Connect.blog(""), target='World', menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "mugello"), luogo = "mugello", urlx=cherrypy.url())
else:
tmpl = env.get_template('mytemplate.html')
pag="blog"
page = tmpl.render(pag="master",blogs=Connect.blog(""), target=kwargs, menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "sanpiero"), luogo = "sanpiero", news=Connect.news(""),urlx=cherrypy.url())
return page
@cherrypy.expose
def test(self):
return "Test Controller"
@cherrypy.expose
def submit(self, cancel =False,**value):
if cherrypy.request.method=='POST':
if cancel:
raisecherrypy.HTTPRedirect('/')# to cancel the action
link=Link(**value)
self.data[link.id]= link
raise cherrypy.HTTPRedirect('/submit')
tmp=env.get_template('submit.html')
streamValue=tmp.generate()
return tmp.render(salutation='Hello', target='World')
@cherrypy.expose
def menu(self):
tmp=env.get_template('menu5.html')
streamValue=tmp.generate()
return tmp.render(salutation='Menu', target='World', blogs=Connect.blog(""),menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "index"), renderer='json')
@cherrypy.expose
def slider(self):
tmp=env.get_template('css3/index.html')
streamValue=tmp.generate()
return tmp.render(urlx="by Carlo Zanieri", salutation='Menu', target='World', blogs=Connect.blog(""),menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "index"), renderer='json')
@cherrypy.expose
def slide(self, luogo):
tmp = env.get_template('nivo.html')
streamValue=tmp.generate()
#luogo = request.params[0]
return tmp.render(luogo="sanpiero", slider=Connect.slider("", luogo), renderer="json")
@cherrypy.expose
def news_one(request,titolo,id):
#titolo=request.POST['titolo']
tmp=env.get_template('news_one.html')
#id=request.POST['id']
return tmp.render(pagina=Connect.body("", "sanpiero"), manifestazione="Blog", news=Connect.news_one("",titolo, id))
@cherrypy.expose
def blogs_one(self,titolo,blogid, path=True, **kwargs):
#titolo=request.POST['titolo']
if not path:
tmp=env.get_template('mytemplate.html')
path= tmp.render(pagina=Connect.body("", "sanpiero"), manifestazione="Blog", blogs=Connect.blogs_one("",blogid),pag="blogs_one",blogid=blogid)
#blogs=Connect.blogs_one("", id)
#raise cherrypy.HTTPRedirect("/?pag=blogs_one&blogid=%s" %blogid)
raise cherrypy.HTTPRedirect(cherrypy.url('/?%s%s' % ("pag=blogs_one&blogid=",blogid)))
else :
tmp=env.get_template('blogs_one.html')
path= tmp.render(pagina=Connect.body("", "sanpiero"), manifestazione="Blog", blogo=Connect.blogs_one("",blogid),pag="blogs_one",blogid=blogid,menu=Connect.menu(""), submenu=Connect.submnu(""))
return path
def url_for(self, action='show'):
if action in ('show', 'index', None):
return cherrypy.url('/%s' % self.id)
elif action:
return cherrypy.url('/%s/%s' % (self.id, action))
else:
return cherrypy.url('/notfound')
@cherrypy.expose
def sanpiero(self):
tmpl = env.get_template('mytemplate.html')
return tmpl.render(salutation='Hello', target='World', menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "sanpiero"), luogo = "sanpiero")
@cherrypy.expose
def cart(self):
tmpl = env.get_template('homebase.html')
return tmpl.render(salutation='Hello', target='World', menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "cart"), luogo = "sanpiero")
@cherrypy.expose
def mugello(self):
tmpl = env.get_template('mytemplate.html')
return tmpl.render(salutation='Hello', target='World', menu=Connect.menu(""), submenu=Connect.submnu(""),pagina=Connect.body("", "mugello"), luogo = "mugello")
@cherrypy.expose
def newss(self,*url_parts, **params):
tmp=env.get_template('news.html')
return tmp.render( pagina=Connect.body("", "sanpiero"), manifestazione="news", news=Connect.news(""), urlx="by Carlo Zanieri")
@cherrypy.expose
def store_mp3_view(request):
# ``filename`` contains the name of the file in string format.
#
# WARNING: Internet Explorer is known to send an absolute file
# *path* as the filename. This example is naive; it trusts
# user input.
filename = request.POST['file'].filename
dirname = request.POST['dir']
# ``input_file`` contains the actual file data which needs to be
# stored somewhere.
input_file = request.POST['file'].file
# Using the filename like this without cleaning it is very
# insecure so please keep that in mind when writing your own
# file handling.
file_path = os.path.join(dirname, filename)
with open(file_path, 'wb') as output_file:
shutil.copyfileobj(input_file, output_file)
tmp=env.get_template('upload_form.html')
return tmp.render( pagina=Connect.body("", "sanpiero"), manifestazione="news", news=Connect.news(""))
return Response(' File ' + filename + ' salvato correttamente' )
@cherrypy.expose
def blog(self, path=True, **kwargs):
if kwargs :
pag = kwargs['pag']
#blogid = kwargs['blogid']
#cherrypy.HTTPRedirect("localhost?pag=blog")
#tmp=env.get_template('mytemplate.html')
#return tmp.render( pag="blog", pagina=Connect.body("", "sanpiero"), manifestazione="blog", blogs=Connect.blog(""), urlx="by Carlo Zanieri", luogo = "blog")
if not path:
raise cherrypy.HTTPRedirect("/?pag=blog")
else :
tmp=env.get_template('blogmaster.html')
path = tmp.render(menu=Connect.menu(""), submenu=Connect.submnu(""), pag="blog", pagina=Connect.body("", "sanpiero"), manifestazione="blog", blogs=Connect.blog(""), urlx="by Carlo Zanieri", luogo = "blog")
return path
@cherrypy.expose
def blogs(self):
tmp=env.get_template('blogs.html')
return tmp.render( pagina=Connect.body("", "sanpiero"), manifestazione="blog", blogs=Connect.blog(""), urlx="by Carlo Zanieri", luogo = "blog")
@cherrypy.expose
def upload_form(self, file, dir, tipo, titolo, descrizione, dirdb):
# Either save the file to the directory where server.py is
# or save the file to a given path:
# upload_path = '/path/to/project/data/'
upload_path = dir
# Save the file to a predefined filename
# or use the filename sent by the client:
# upload_filename = ufile.filename
upload_filename = file.filename
upload_file = os.path.normpath(
os.path.join(upload_path, upload_filename))
size = 0
with open(upload_file, 'wb') as out:
while True:
data = file.file.read(8192)
if not data:
break
out.write(data)
size += len(data)
if tipo == "manifestazioni" :
Connect.ins_manifesta("",dirdb, file.filename, titolo, descrizione)
elif tipo == "news" :
Connect.ins_news("",dirdb, file.filename, titolo, descrizione, tipo)
out = '''
File received.
Filename: {}
Length: {}
Mime-type: {}
''' .format(upload_path + "/" + file.filename, size, file.content_type, data)
return out
@cherrypy.expose
def ins_manifesta(self, file, dir, titolo, descrizione, dirdb):
# Either save the file to the directory where server.py is
# or save the file to a given path:
# upload_path = '/path/to/project/data/'
upload_path = os.path.dirname(dir)
# Save the file to a predefined filename
# or use the filename sent by the client:
# upload_filename = ufile.filename
upload_filename = file.filename
upload_file = os.path.normpath(
os.path.join(upload_path, upload_filename))
size = 0
with open(upload_file, 'wb') as out:
while True:
data = file.file.read(8192)
if not data:
break
out.write(data)
size += len(data)
Connect.ins_manifesta("",upload_path, file.filename, titolo, descrizione)
out = '''
File received.
Filename: {}
Length: {}
Mime-type: {}
''' .format(upload_path + "/" + file.filename, size, file.content_type, data)
return out
@cherrypy.expose
def upload(request):
tmp=env.get_template('upload_form.html')
return tmp.render( pagina=Connect.body("", "sanpiero"), manifestazione="news", news=Connect.news(""))
@cherrypy.expose
def ins_iscrizioni(self, id, username, useremail):
tmp=env.get_template('uno/index4.html')
return tmp.render(pagina=Connect.ins_iscrizioni(self, username, useremail))
@cherrypy.expose
def ins_manifestazioni(request):
tmp=env.get_template('inserimenti.html')
return tmp.render( pagina=Connect.body("", "sanpiero"), manifestazione="news", news=Connect.news(""), directory="./static/manifestazioni/img/" , dirdb="/manifestazioni/img/",tipo="manifestazioni")
@cherrypy.expose
def ins_news(request):
tmp=env.get_template('inserimenti.html')
return tmp.render( pagina=Connect.body("", "sanpiero"), manifestazione="news", news=Connect.news(""), directory="./static/news/img/",dirdb="/news/img/" ,tipo="news")
@cherrypy.expose
def add_cart(self, blogid, titolo):
Connect.add_cart('',blogid, titolo)
@cherrypy.expose
def manifesta(request):
tmp=env.get_template('ins_manifesta.html')
return tmp.render( pagina=Connect.body("", "sanpiero"), manifestazione="news", news=Connect.news(""))
configfile=os.path.join(os.path.dirname(__file__),'./server.conf')
cherrypy.quickstart(HelloWorld(), config=configfile)