forked from linuxscout/mishkal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadawaty.py
executable file
·200 lines (178 loc) · 5.35 KB
/
adawaty.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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#-------------------------------------------------------------------------------
# Name: adawaty
# Purpose: web interface tools for manipulating arabic texts.
#
# Author: Taha Zerrouki (taha.zerrouki[at]gmail.com)
#
# Created: 31-10-2011
# Copyright: (c) Taha Zerrouki 2011
# Licence: GPL
#-------------------------------------------------------------------------------
"""
The original web interface is friom webQamoos,
Copyright © 2009, Muayyad Alsadi <alsadi@ojuba.org>
Released under terms of Waqf Public License.
This program is free software; you can redistribute it and/or modify
it under the terms of the latest version Waqf Public License as
published by Ojuba.org.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The Latest version of the license can be found on
"http://waqf.ojuba.org/license"
"""
import sys
import os
import os.path
import re
from glob import glob
sys.path.append('mishkal/');
sys.path.append('mishkal/lib/');
sys.path.append('lib');
sys.path.append('lib/web');
from okasha2.baseWebApp import *
from okasha2.utils import fromFs, toFs
import core.adaat
# import core.myrepr
import datetime
header=u"""
<div style='text-align:left;vertical-align:middle; display:table-cell;'>
<a href="/mishkal/index">الرئيسية</a>
<a href="/mishkal/doc">توثيق</a>
<a href="/mishkal/link">روابط</a>
<a href="/mishkal/download">تحميل</a>
<a href="/mishkal/projects">مشاريع</a>
<a href="/mishkal/contact">اتصل بنا</a>
</div>
<hr/>
"""
footer=u"""
<hr class="footer"/>
<div id="footer">
<a href="/mishkal/contact">للاتصال</a>
بدعم من <a href="http://www.arabeyes.org">arabeyes.org</a>
<a href="http://blog.tahadz.com">مدونتي</a>
</div>
"""
MyJsonHeaders={
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Content-Type, *",
}
#used in local
#comment it on server
# header=re.sub("/mishkal/",'', header);
# footer=re.sub("/mishkal/",'', footer);
class webApp(baseWebApp):
def __init__(self, *args, **kw):
baseWebApp.__init__(self,*args, **kw)
# self.myRepr = core.myrepr.MyRepr();
def _root(self, rq, *args):
raise redirectException(rq.script+'/main')
@expose(percentTemplate,["main.html"])
def main(self, rq, *args):
return {
'title':u'أدوات',
'script':rq.script,
'DefaultText':core.adaat.randomText(),
'ResultText':u"السلام عليكم",
'header':header,
"footer":footer,
# 'mode':self.mode, 'version':'0.1.0'
}
@expose(percentTemplate,["main.html"])
def index(self, rq, *args):
return {
'title':u'مشكال لتشكيل النصوص',
'script':rq.script,
'DefaultText':core.adaat.randomText(),
'ResultText':u"السلام عليكم",
'header':header,
"footer":footer,
# 'mode':self.mode, 'version':'0.1.0'
}
@expose(percentTemplate,["body_help.html"])
def help(self, rq, *args):
return {
}
@expose(jsonDumps, headers=MyJsonHeaders)
def ajaxGet(self, rq, *args):
"""
this is an example of using ajax/json
to test it visit http://localhost:8080/ajaxGet"
"""
text=rq.q.getfirst('text','ZerroukiTAha').decode('utf-8')
action=rq.q.getfirst('action','DoNothing').decode('utf-8')
order=rq.q.getfirst('order','0').decode('utf-8')
options={};
options['lastmark']=rq.q.getfirst('lastmark','0').decode('utf-8')
#print order.encode('utf8');
self.writelog(text,action);
#Handle contribute cases
if action=="Contribute":
return {'result':u"شكرا جزيلا على مساهمتك."}
resulttext=core.adaat.DoAction(text,action, options)
# self.writelog(repr(resulttext),"ResultText");
# we choose to avoid logging results
# self.writelog(resulttext,"ResultText");
return {'result':resulttext, 'order':order}
@expose(percentTemplate,["doc.html"])
def doc(self, rq, *args):
return {
'script':rq.script,
'header':header,
"footer":footer,
}
@expose(percentTemplate,["download.html"])
def download(self, rq, *args):
return {
'script':rq.script,
'header':header,
"footer":footer,
}
@expose(percentTemplate,["contact.html"])
def contact(self, rq, *args):
return {
'script':rq.script,
'header':header,
"footer":footer,
}
@expose(percentTemplate,["link.html"])
def link(self, rq, *args):
return {
'script':rq.script,
'header':header,
"footer":footer,
}
@expose(percentTemplate,["projects.html"])
def projects(self, rq, *args):
return {
'script':rq.script,
'header':header,
"footer":footer,
}
@expose(percentTemplate,["log.html"])
def log(self, rq, *args):
return {
'script':rq.script,
'header':header,
"footer":footer,
}
@expose(percentTemplate,["whoisqutrub.html"])
def whoisqutrub(self, rq, *args):
return {
'script':rq.script,
'header':header,
"footer":footer,
}
def writelog(self,text,action):
"""
@param text: an object to be logged
@type text: object
"""
timelog=datetime.datetime.now().strftime("%Y-%m-%d %I:%M");
textlog=u"\t".join([timelog,action, text]);
self._logger.info(textlog);