/
views.py
64 lines (54 loc) · 1.71 KB
/
views.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
#!/usr/bin/env python
# encoding: utf-8
from django.http import HttpResponse
from django.template.loader import get_template
from django.template import Template, Context
from django.shortcuts import render_to_response
from fontdict import fontdict
from draw import my_draw
from misc import getVersionInfor
def fontcss():
'''generate css for fonts; '''
format='''
/**** %s ****/
@font-face {
font-family: "%s";
src: url(/site_media/font/%s);
}'''
css=''
for font in fontdict.keys():
css += format % (fontdict[font], font, font)
return css
# response = HttpResponse(mimetype='text/plain; charset=utf-8')
# response.write(css)
# return response
def home(request):
'''index view'''
version,build = getVersionInfor()
t = get_template('index.html')
html = t.render(Context({'fontdict':fontdict,
'fontcss': fontcss(),
"version": version,
"build": build}))
return HttpResponse(html)
def generate(request):
bg = request.GET.get('bg', '') #can be changed to POST
if not bg or bg=='undefined':#undefined
bg='logo192.png'
text=request.GET.get('text', '')
font=request.GET.get('font', '')
textColor=request.GET.get('textColor', '')
shadowColor=request.GET.get('shadowColor', '')
#boolean args
border=eval(request.GET.get('border', ''))
shadow=eval(request.GET.get('shadow', ''))
highlight=eval(request.GET.get('highlight', ''))
return my_draw(request,
bg=bg,
text=text,
font=font,
textColor=textColor,
shadowColor=shadowColor,
border=border,
shadow=shadow,
highlight=highlight)