Moved to Git repo from PST server
This commit is contained in:
commit
e952817423
|
@ -0,0 +1,16 @@
|
|||
AuthType Basic
|
||||
AuthName "Restricted Access"
|
||||
AuthUserFile /path/to/file/with/passwords
|
||||
Require valid-user
|
||||
|
||||
AddHandler mod_python .py
|
||||
PythonHandler mod_python.publisher
|
||||
PythonDebug On
|
||||
#<LocationMatch "^/+$">
|
||||
Options -Indexes
|
||||
RedirectMatch "^/+$" /index.py/view
|
||||
RedirectMatch "^/index.py+$" /index.py/view
|
||||
RedirectMatch "^/imp+$" /index.py/imp
|
||||
RedirectMatch "^/view+$" /index.py/view
|
||||
RedirectMatch "^/delete+$" /index.py/delete
|
||||
#</LocationMatch>
|
|
@ -0,0 +1,436 @@
|
|||
#!/usr/bin/env python
|
||||
class table:
|
||||
def __init__(self, db, name, columns):
|
||||
self.db = db # database connection
|
||||
self.name = name # table name
|
||||
self.columns = columns
|
||||
self.dbc = self.db.cursor() # cursor object
|
||||
self.debug = 0
|
||||
self.order = ''
|
||||
self.qfilter = ''
|
||||
self.selectopts = ''
|
||||
|
||||
# def _sqlvalue(self, value):
|
||||
# if value == None:
|
||||
# return 'NULL'
|
||||
# else:
|
||||
# return value
|
||||
|
||||
def _getorder(self):
|
||||
if len(self.order) > 0:
|
||||
orderstr = 'ORDER BY `%s`' % self.order
|
||||
else:
|
||||
orderstr = ''
|
||||
return orderstr
|
||||
|
||||
# def _enumquoted(self, list):
|
||||
# result = ''
|
||||
# for i in xrange(len(list)-1):
|
||||
# result = '%s\'%s\', ' % (result, self._sqlvalue(list[i]))
|
||||
# result = '%s%s' % (result, self._sqlvalue(list[i+1]))
|
||||
# return result
|
||||
|
||||
# def _gensubstitute(self, list):
|
||||
# result = ''
|
||||
# for i in xrange(len(list)-1):
|
||||
# result += '%r, '
|
||||
# result = result + '%r'
|
||||
# return result
|
||||
|
||||
def _listtotuple(self, list):
|
||||
result = ()
|
||||
for i in xrange(len(list)):
|
||||
result += (list[i],)
|
||||
return result
|
||||
|
||||
def _enumquotedreverse(self, list):
|
||||
result = ''
|
||||
if (len(list)) > 1:
|
||||
for i in xrange(len(list)-1):
|
||||
if list[i] == None:
|
||||
result = result + 'NULL' + ', '
|
||||
else:
|
||||
result = result + '`%s`, ' % list[i]
|
||||
result = result + '`' + list[i+1] + '`'
|
||||
else:
|
||||
result = list[0]
|
||||
return result
|
||||
|
||||
def _replacelist(self, list):
|
||||
result = ''
|
||||
for i in xrange(len(list)-1):
|
||||
result += '%s, '
|
||||
result +='%s'
|
||||
return result
|
||||
|
||||
def __getitem__(self, item):
|
||||
self._query("SELECT %s %s FROM %s %s %s LIMIT %s, 1" % (self.selectopts, self._enumquotedreverse(self.columns), self.name, self.qfilter, self._getorder(), item))
|
||||
return self.dbc.fetchone()
|
||||
|
||||
def _query(self, q, values = ()):
|
||||
if self.debug == 1:
|
||||
print "Query: %s" % (q)
|
||||
self.dbc.execute(q, values)
|
||||
|
||||
def __iter__(self):
|
||||
"creates a data set, and returns an iterator (self)"
|
||||
q = "SELECT %s %s FROM %s %s %s" % (self.selectopts, self._enumquotedreverse(self.columns), self.name, self.qfilter, self._getorder())
|
||||
self._query(q)
|
||||
return self
|
||||
|
||||
def __len__(self):
|
||||
self.__iter__()
|
||||
return int(self.dbc.rowcount)
|
||||
|
||||
def setfilter(self, filterstr):
|
||||
self.qfilter = filterstr
|
||||
q = "SELECT %s %s FROM %s %s %s" % (self.selectopts, self._enumquotedreverse(self.columns), self.name, self.qfilter, self._getorder())
|
||||
self._query(q)
|
||||
|
||||
def setorder(self, orderstr):
|
||||
self.order = orderstr
|
||||
q = "SELECT %s %s FROM %s %s %s" % (self.selectopts, self._enumquotedreverse(self.columns), self.name, self.qfilter, self._getorder())
|
||||
self._query(q)
|
||||
|
||||
def next(self):
|
||||
"returns the next item in the data set, or tells Python to stop"
|
||||
r = self.dbc.fetchone()
|
||||
if not r:
|
||||
raise StopIteration
|
||||
return r
|
||||
|
||||
def append(self, values):
|
||||
q = 'INSERT INTO %s (%s) VALUES (%s)' % (self.name, self._enumquotedreverse(self.columns), self._replacelist(values))
|
||||
self._query(q, self._listtotuple(values))
|
||||
|
||||
def delete_by_filter(self, qfilter):
|
||||
q = 'DELETE FROM %s %s' % (self.name, qfilter)
|
||||
self._query(q)
|
||||
|
||||
def create(self, parameters):
|
||||
q = 'CREATE TABLE `%s` (' % self.name
|
||||
for i in xrange(len(self.columns)-1):
|
||||
q = '%s `%s` %s,' % (q, self.columns[i], parameters[i])
|
||||
q = '%s `%s` %s)' % (q, self.columns[i+1], parameters[i+1])
|
||||
self._query(q)
|
||||
|
||||
def create_if_not_exists(self, parameters):
|
||||
q = 'CREATE TABLE IF NOT EXISTS `%s` (' % self.name
|
||||
for i in xrange(len(self.columns)-1):
|
||||
q = '%s `%s` %s,' % (q, self.columns[i], parameters[i])
|
||||
q = '%s `%s` %s)' % (q, self.columns[i+1], parameters[i+1])
|
||||
self._query(q)
|
||||
|
||||
class vcards:
|
||||
class __card__:
|
||||
def __init__(self):
|
||||
r.company = ''
|
||||
r.firstName = None
|
||||
r.lastName = None
|
||||
r.title = None
|
||||
r.city = None
|
||||
r.country = None
|
||||
r.address = None
|
||||
r.zipCode = None
|
||||
r.state = None
|
||||
r.email = None
|
||||
r.webSite = None
|
||||
r.phone = None
|
||||
r.phone2 = None
|
||||
r.fax = None
|
||||
r.cellPhone = None
|
||||
r.image = None
|
||||
|
||||
def __init__(self, vcfdata):
|
||||
import vobject
|
||||
vcard_delemiter = "\nEND:VCARD"
|
||||
self.vcfdata = vcfdata
|
||||
vcards = vcfdata.split(vcard_delemiter)
|
||||
del(vcards[len(vcards)-1])
|
||||
self.v = []
|
||||
_nextPos = 0
|
||||
for i in xrange(len(vcards)):
|
||||
vcards[i] = vcards[i] + vcard_delemiter
|
||||
self.v.append(vobject.readOne(vcards[i].replace(';QUOTED-PRINTABLE','')))
|
||||
|
||||
def _rmspaces(self, val):
|
||||
try:
|
||||
for i in xrange(len(val)):
|
||||
if val[0] == ' ':
|
||||
val = val[1:]
|
||||
if val == '':
|
||||
result = None
|
||||
else:
|
||||
result = val
|
||||
except:
|
||||
result = val
|
||||
return result
|
||||
|
||||
def _normalize(self, val):
|
||||
if type(val) == type([]):
|
||||
result = ''
|
||||
for i in xrange(len(val)-1):
|
||||
result += '%s, ' % val[i]
|
||||
result += '%s' % val[i + 1]
|
||||
else:
|
||||
result = val
|
||||
result = self._rmspaces(result)
|
||||
return result
|
||||
|
||||
def _getFirstName(self, vcard):
|
||||
try:
|
||||
result = vcard.n.value.given
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getLastName(self, vcard):
|
||||
try:
|
||||
result = vcard.n.value.family
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getCity(self, vcard):
|
||||
try:
|
||||
result = vcard.adr.value.city
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getCountry(self, vcard):
|
||||
try:
|
||||
result = vcard.adr.value.country
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getAddress(self, vcard):
|
||||
try:
|
||||
result = vcard.adr.value.street
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getZipCode(self, vcard):
|
||||
try:
|
||||
result = vcard.adr.value.code
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getState(self, vcard):
|
||||
try:
|
||||
result = vcard.adr.value.region
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getEmail(self, vcard):
|
||||
try:
|
||||
result = vcard.email.value
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getWebSite(self, vcard):
|
||||
try:
|
||||
result = vcard.url.value
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getTitle(self, vcard):
|
||||
try:
|
||||
result = vcard.title.value
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getCompany(self, vcard):
|
||||
try:
|
||||
result = vcard.org.value[0]
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getImage(self, vcard):
|
||||
try:
|
||||
result = vcard.photo.value
|
||||
except:
|
||||
result = None
|
||||
return result
|
||||
|
||||
def _getPhone(self, vcard):
|
||||
try:
|
||||
tel = vcard.tel_list
|
||||
for i in xrange(len(tel)):
|
||||
pref = False
|
||||
work = False
|
||||
voice = False
|
||||
cell = False
|
||||
fax = False
|
||||
for j in xrange(len(tel[i].singletonparams)):
|
||||
if tel[i].singletonparams[j] == 'PREF': pref = True
|
||||
if tel[i].singletonparams[j] == 'WORK': work = True
|
||||
if tel[i].singletonparams[j] == 'VOICE': voice = True
|
||||
if tel[i].singletonparams[j] == 'CELL': cell = True
|
||||
if tel[i].singletonparams[j] == 'FAX': fax = True
|
||||
if pref == True and work == True and voice == True and cell == False and fax == False:
|
||||
found = 1
|
||||
break
|
||||
if found == True:
|
||||
result = tel[i].value
|
||||
else:
|
||||
result = None
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getPhone2(self, vcard):
|
||||
try:
|
||||
tel = vcard.tel_list
|
||||
for i in xrange(len(tel)):
|
||||
pref = False
|
||||
work = False
|
||||
voice = False
|
||||
cell = False
|
||||
fax = False
|
||||
for j in xrange(len(tel[i].singletonparams)):
|
||||
if tel[i].singletonparams[j] == 'PREF': pref = True
|
||||
if tel[i].singletonparams[j] == 'WORK': work = True
|
||||
if tel[i].singletonparams[j] == 'VOICE': voice = True
|
||||
if tel[i].singletonparams[j] == 'CELL': cell = True
|
||||
if tel[i].singletonparams[j] == 'FAX': fax = True
|
||||
if pref == False and work == True and voice == True and cell == False and fax == False:
|
||||
found = 1
|
||||
break
|
||||
if found == True:
|
||||
result = tel[i].value
|
||||
else:
|
||||
result = None
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getFax(self, vcard):
|
||||
try:
|
||||
tel = vcard.tel_list
|
||||
for i in xrange(len(tel)):
|
||||
pref = False
|
||||
work = False
|
||||
voice = False
|
||||
cell = False
|
||||
fax = False
|
||||
for j in xrange(len(tel[i].singletonparams)):
|
||||
if tel[i].singletonparams[j] == 'PREF': pref = True
|
||||
if tel[i].singletonparams[j] == 'WORK': work = True
|
||||
if tel[i].singletonparams[j] == 'VOICE': voice = True
|
||||
if tel[i].singletonparams[j] == 'CELL': cell = True
|
||||
if tel[i].singletonparams[j] == 'FAX': fax = True
|
||||
if pref == False and work == True and voice == False and cell == False and fax == True:
|
||||
found = 1
|
||||
break
|
||||
if found == True:
|
||||
result = tel[i].value
|
||||
else:
|
||||
result = None
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def _getCellPhone(self, vcard):
|
||||
try:
|
||||
tel = vcard.tel_list
|
||||
for i in xrange(len(tel)):
|
||||
pref = False
|
||||
work = False
|
||||
voice = False
|
||||
cell = False
|
||||
fax = False
|
||||
for j in xrange(len(tel[i].singletonparams)):
|
||||
if tel[i].singletonparams[j] == 'PREF': pref = True
|
||||
if tel[i].singletonparams[j] == 'WORK': work = True
|
||||
if tel[i].singletonparams[j] == 'VOICE': voice = True
|
||||
if tel[i].singletonparams[j] == 'CELL': cell = True
|
||||
if tel[i].singletonparams[j] == 'FAX': fax = True
|
||||
if pref == False and work == False and voice == True and cell == True and fax == False:
|
||||
found = 1
|
||||
break
|
||||
if found == True:
|
||||
result = tel[i].value
|
||||
else:
|
||||
result = None
|
||||
except:
|
||||
result = None
|
||||
return self._normalize(result)
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __getitem__(self, item):
|
||||
r = self.__card__
|
||||
r.company = self._getCompany(self.v[item])
|
||||
r.firstName = self._getFirstName(self.v[item])
|
||||
r.lastName = self._getLastName(self.v[item])
|
||||
r.title = self._getTitle(self.v[item])
|
||||
r.city = self._getCity(self.v[item])
|
||||
r.country = self._getCountry(self.v[item])
|
||||
r.address = self._getAddress(self.v[item])
|
||||
r.zipCode = self._getZipCode(self.v[item])
|
||||
r.state = self._getState(self.v[item])
|
||||
r.email = self._getEmail(self.v[item])
|
||||
r.webSite = self._getWebSite(self.v[item])
|
||||
r.phone = self._getPhone(self.v[item])
|
||||
r.phone2 = self._getPhone2(self.v[item])
|
||||
r.fax = self._getFax(self.v[item])
|
||||
r.cellPhone = self._getCellPhone(self.v[item])
|
||||
r.image = self._getImage(self.v[item])
|
||||
return r
|
||||
|
||||
|
||||
def next(self):
|
||||
r = self.__card__
|
||||
if not self.v[_nextPos]:
|
||||
raise StopIteration
|
||||
else:
|
||||
r.company = self._getCompany(self.v[self._nextPos])
|
||||
r.firstName = self._getFirstName(self.v[self._nextPos])
|
||||
r.lastName = self._getLastName(self.v[self._nextPos])
|
||||
r.title = self._getTitle(self.v[self._nextPos])
|
||||
r.city = self._getCity(self.v[self._nextPos])
|
||||
r.country = self._getCountry(self.v[self._nextPos])
|
||||
r.address = self._getAddress(self.v[self._nextPos])
|
||||
r.zipCode = self._getZipCode(self.v[self._nextPos])
|
||||
r.state = self._getState(self.v[self._nextPos])
|
||||
r.email = self._getEmail(self.v[self._nextPos])
|
||||
r.webSite = self._getWebSite(self.v[self._nextPos])
|
||||
r.phone = self._getPhone(self.v[self._nextPos])
|
||||
r.phone2 = self._getPhone2(self.v[self._nextPos])
|
||||
r.fax = self._getFax(self.v[self._nextPos])
|
||||
r.cellPhone = self._getCellPhone(self.v[self._nextPos])
|
||||
r.image = self._getImage(self.v[self._nextPos])
|
||||
self._nextPos = self._nextPos + 1
|
||||
return r
|
||||
|
||||
def __len__(self):
|
||||
return len(self.v)
|
||||
|
||||
#
|
||||
#for i in xrange(len(v)):
|
||||
# print 'Company: %s' % _getCompany(v[i])
|
||||
# print 'First name: %s' % _getFirstName(v[i])
|
||||
# print 'Last name: %s' % _getLastName(v[i])
|
||||
# print 'Title: %s' % _getTitle(v[i])
|
||||
# print 'City: %s' % _getCity(v[i])
|
||||
# print 'Country: %s' % _getCountry(v[i])
|
||||
# print 'Address: %s' % _getAddress(v[i])
|
||||
# print 'Zip code: %s ' % _getZipCode(v[i])
|
||||
# print 'State: %s' % _getState(v[i])
|
||||
# print 'Email: %s' % _getEmail(v[i])
|
||||
# print 'Web site: %s' % _getWebSite(v[i])
|
||||
# print 'Phone: %s' % _getPhone(v[i])
|
||||
# print 'Phone2: %s' % _getPhone2(v[i])
|
||||
# print 'Fax: %s' % _getFax(v[i])
|
||||
# print 'Cell phone: %s' % _getCellPhone(v[i])
|
||||
# print '------------------------------------------------------'
|
|
@ -0,0 +1,327 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys, os, MySQLdb, binascii
|
||||
from mod_python import apache, util
|
||||
from htmlgen import HTMLgen
|
||||
|
||||
DB_NAME = 'bc'
|
||||
DB_HOST = 'localhost'
|
||||
DB_USER = 'bc'
|
||||
DB_PASSWORD = 'super-secret-password'
|
||||
|
||||
ITEMS_PER_PAGE = 25
|
||||
|
||||
def _init(req):
|
||||
sys.path.append(os.path.dirname(req.filename) + "/include")
|
||||
|
||||
def _pageTitle(req, meta='', title=''):
|
||||
if len(title) > 0:
|
||||
title += ' - '
|
||||
if len(meta) > 0:
|
||||
meta = '<meta %s>\n' % meta
|
||||
page = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n'\
|
||||
'<html lang="ru">\n'\
|
||||
'<head>\n'\
|
||||
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n'\
|
||||
'%s' % meta +\
|
||||
'<title>%sBusiness cards</title>\n' %title +\
|
||||
'</head>\n'\
|
||||
'<body>\n'\
|
||||
'<font face="Calibri, Arial, Verdana, Sans">\n'\
|
||||
'<H1><table width="100%" bgcolor="#336299"><tr><td><p align="center"><font color="white">Business cards</font></p></td></tr></table></H1>\n'
|
||||
return page
|
||||
|
||||
def _pageFooter(req):
|
||||
page = '<br><hr><p align="center">©2010 Сергей Морозов, ОАО \"Промышленно - строительное товарищество\"</p>\n'\
|
||||
'</font>\n'\
|
||||
'</body>\n'\
|
||||
'</html>\n'
|
||||
return page
|
||||
|
||||
def _pageImpForm(req):
|
||||
page = '<H2>Импорт записей из .vcf файлов</H2>\n'\
|
||||
'<form method="post" enctype="multipart/form-data" action="%s">\n'\
|
||||
'Выберите файл: \n'\
|
||||
'<input type="file" name="file" id="file" size="40">\n'\
|
||||
'<input type="submit" value="Отправить"\n>'\
|
||||
'</form>\n'\
|
||||
'<br>\n'\
|
||||
'<a href="delete">Удаление ранее загруженных записей</a>\n'\
|
||||
% req.uri
|
||||
return page
|
||||
|
||||
def _pageDone(req, additional = ''):
|
||||
page = 'Операция завершена.<br>%s' % additional
|
||||
return page
|
||||
|
||||
def _pageDeleteForm(req, list):
|
||||
liststring = ''
|
||||
for i in xrange(len(list)):
|
||||
liststring += '<option>%s\n' % list[i]
|
||||
|
||||
page = '<H2>Удаление информации из базы данных</H2>\n'\
|
||||
'<form method="post" enctype="multipart/form-data" action="%s">\n'\
|
||||
'Выберите раздел: \n'\
|
||||
'<select name="filename"\n>'\
|
||||
'%s'\
|
||||
'</select>\n'\
|
||||
'<input type="submit" value="Удалить"\n>'\
|
||||
'</form>'\
|
||||
'<br>\n'\
|
||||
'<a href="imp">Импорт записей из файлов .vcf</a>\n'\
|
||||
% (req.uri, liststring)
|
||||
return page
|
||||
|
||||
def _pageFileSelect(req, list):
|
||||
page = '<H2 align="center">Выберите раздел:</H2>\n'\
|
||||
'<p align="center">'
|
||||
for i in xrange(len(list)):
|
||||
page += '<a href="view?filename=%s"><b>%s</b></a><br>\n' % (list[i], list[i])
|
||||
page += '</p>'
|
||||
return page
|
||||
|
||||
def _pagePrintItem(req, record):
|
||||
key = str(record[0])
|
||||
FirstName = record[2]
|
||||
LastName = record[3]
|
||||
City = record[4]
|
||||
Country = record[5]
|
||||
Address = record[6]
|
||||
ZipCode = record[7]
|
||||
State = record[8]
|
||||
Email = record[9]
|
||||
WebSite = record[10]
|
||||
Title = record[11]
|
||||
Company = record[12]
|
||||
Phone = record[13]
|
||||
Phone2 = record[14]
|
||||
Fax = record[15]
|
||||
CellPhone = record[16]
|
||||
textfields = ''
|
||||
if FirstName != None: textfields += '<b>First name:</b> %s<br>\n' % FirstName
|
||||
if LastName != None: textfields += '<b>Last name:</b> %s<br>\n' % LastName
|
||||
if City != None: textfields += '<b>City:</b> %s<br>\n' % City
|
||||
if Country != None: textfields += '<b>Country:</b> %s<br>\n' % Country
|
||||
if Address != None: textfields += '<b>Address:</b> %s<br>\n' % Address
|
||||
if ZipCode != None: textfields += '<b>Zip code:</b> %s<br>\n' % ZipCode
|
||||
if State != None: textfields += '<b>State:</b> %s<br>\n' % State
|
||||
if Email != None: textfields += '<b>Email:</b> <a href="mailto:%s">%s</a><br>\n' % (Email, Email)
|
||||
if WebSite != None:
|
||||
if WebSite[0:7] != 'http://' and WebSite[0:8] != 'https://' and WebSite[0:6] != 'ftp://':
|
||||
WebSite = 'http://%s' % WebSite
|
||||
textfields += '<b>Web site:</b> <a href="%s">%s</a><br>\n' % (WebSite, WebSite)
|
||||
if Title != None: textfields += '<b>Title:</b> %s<br>\n' % Title
|
||||
if Company != None: textfields += '<b>Company:</b> %s<br>\n' % Company
|
||||
if Phone != None: textfields += '<b>Phone:</b> %s<br>\n' % Phone
|
||||
if Phone2 != None: textfields += '<b>Phone2:</b> %s<br>\n' % Phone2
|
||||
if Fax != None: textfields += '<b>Fax:</b> %s<br>\n' % Fax
|
||||
if CellPhone != None: textfields += '<b>CellPhone:</b> %s<br>\n' % CellPhone
|
||||
page = '<table width="100%" border=1 cellpadding=10>\n'\
|
||||
'<tr>\n'\
|
||||
'<td width="400px">\n'\
|
||||
'<img src="getimage?key=' + key + '" width="400px">\n'\
|
||||
'</td>\n'\
|
||||
'<td valign="top">\n' +\
|
||||
'%s' % textfields +\
|
||||
'</td>\n'\
|
||||
'</tr>\n'\
|
||||
'</table>\n'\
|
||||
'<br>'
|
||||
# '<hr>'
|
||||
return page
|
||||
|
||||
def _pagePrintPages(req, filename, numpages, page):
|
||||
result = 'Страница: '
|
||||
if numpages > 1:
|
||||
for i in xrange(numpages - 1):
|
||||
if i + 1 == page:
|
||||
result += '<b>%s</b> ' % (i + 1)
|
||||
else:
|
||||
result += '<a href="view?filename=%s&page=%s">%s</a> ' % (filename, (i + 1), (i + 1))
|
||||
else:
|
||||
i = -1
|
||||
if i + 2 == page:
|
||||
result += '<b>%s</b><br>\n' % (i + 2)
|
||||
else:
|
||||
result += '<a href="view?filename=%s&page=%s">%s</a><br>\n' % (filename, (i + 2), (i + 2))
|
||||
return result
|
||||
|
||||
def view(req):
|
||||
_init(req)
|
||||
req.content_type = 'text/html'
|
||||
req.write(str(page))
|
||||
|
||||
def imp(req):
|
||||
_init(req)
|
||||
import bc
|
||||
form = req.form
|
||||
if not form:
|
||||
req.content_type = 'text/html'
|
||||
req.write(_pageTitle(req, title = 'Импорт'))
|
||||
req.write(_pageImpForm(req))
|
||||
req.write(_pageFooter(req))
|
||||
else:
|
||||
req.content_type = 'text/html'
|
||||
filename = form['file'].filename
|
||||
file = form['file'].file
|
||||
filename = os.path.splitext(filename)[0]
|
||||
db = MySQLdb.connect(host = DB_HOST, user = DB_USER, passwd = DB_PASSWORD, db = DB_NAME, charset = "utf8", use_unicode = False)
|
||||
dbfields = ['key', 'Filename' ,'FirstName', 'LastName', 'City', 'Country', 'Address', 'ZipCode', 'State', 'Email', 'WebSite', 'Title', 'Company', 'Phone', 'Phone2', 'Fax', 'CellPhone', 'Image']
|
||||
items = bc.table(db, "vcards", dbfields)
|
||||
items.create_if_not_exists([
|
||||
'BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY', # key
|
||||
'CHAR( 128 ) NULL', # Filename
|
||||
'CHAR( 128 ) NULL', # FirstName
|
||||
'CHAR( 128 ) NULL', # LastName
|
||||
'CHAR( 128 ) NULL', # City
|
||||
'CHAR( 128 ) NULL', # Country
|
||||
'CHAR( 128 ) NULL', # Address
|
||||
'CHAR( 128 ) NULL', # ZipCode
|
||||
'CHAR( 128 ) NULL', # State
|
||||
'CHAR( 128 ) NULL', # Email
|
||||
'CHAR( 128 ) NULL', # WebSite
|
||||
'CHAR( 128 ) NULL', # Title
|
||||
'CHAR( 128 ) NULL', # Company
|
||||
'CHAR( 128 ) NULL', # Phone
|
||||
'CHAR( 128 ) NULL', # Phone2
|
||||
'CHAR( 128 ) NULL', # Fax
|
||||
'CHAR( 128 ) NULL', # CellPhone
|
||||
'LONGBLOB NULL' # Image
|
||||
])
|
||||
items.delete_by_filter('WHERE `Filename` = \'%s\'' % filename)
|
||||
vcards = bc.vcards(file.read())
|
||||
for i in xrange(len(vcards)):
|
||||
items.append([
|
||||
None,
|
||||
filename,
|
||||
vcards[i].firstName,
|
||||
vcards[i].lastName,
|
||||
vcards[i].city,
|
||||
vcards[i].country,
|
||||
vcards[i].address,
|
||||
vcards[i].zipCode,
|
||||
vcards[i].state,
|
||||
vcards[i].email,
|
||||
vcards[i].webSite,
|
||||
vcards[i].title,
|
||||
vcards[i].company,
|
||||
vcards[i].phone,
|
||||
vcards[i].phone2,
|
||||
vcards[i].fax,
|
||||
vcards[i].cellPhone,
|
||||
vcards[i].image
|
||||
])
|
||||
req.write(_pageTitle(req, 'http-equiv="refresh" content="3; url=imp"'))
|
||||
try:
|
||||
totalrecords = i + 1
|
||||
except:
|
||||
totalrecords = 0
|
||||
req.write(_pageDone(req, additional = 'Записей импортировано: %s.' % totalrecords))
|
||||
req.write(_pageFooter(req))
|
||||
|
||||
def getimage(req):
|
||||
_init(req)
|
||||
import bc
|
||||
key = req.form['key']
|
||||
db = MySQLdb.connect(host = DB_HOST, user = DB_USER, passwd = DB_PASSWORD, db = DB_NAME, charset = "utf8", use_unicode = False)
|
||||
dbfields = ['key', 'Filename' ,'FirstName', 'LastName', 'City', 'Country', 'Address', 'ZipCode', 'State', 'Email', 'WebSite', 'Title', 'Company', 'Phone', 'Phone2', 'Fax', 'CellPhone', 'Image']
|
||||
items = bc.table(db, "vcards", dbfields)
|
||||
key = int(key)
|
||||
items.setfilter ('WHERE `key` = %s' % key)
|
||||
try:
|
||||
req.content_type = 'image/JPEG'
|
||||
#req.content_type = 'text/plain'
|
||||
image = items[0][17]
|
||||
req.write(image)
|
||||
|
||||
except:
|
||||
req.content_type = 'text/plain'
|
||||
req.status = apache.HTTP_NOT_FOUND
|
||||
req.write('Image not found')
|
||||
|
||||
def delete(req):
|
||||
_init(req)
|
||||
import bc
|
||||
db = MySQLdb.connect(host = DB_HOST, user = DB_USER, passwd = DB_PASSWORD, db = DB_NAME, charset = "utf8", use_unicode = False)
|
||||
# dbfields = ['key', 'Filename' ,'FirstName', 'LastName', 'City', 'Country', 'Address', 'ZipCode', 'State', 'Email', 'WebSite', 'Title', 'Company', 'Phone', 'Phone2', 'Fax', 'CellPhone', 'Image']
|
||||
dbfields = ['Filename']
|
||||
items = bc.table(db, "vcards", dbfields)
|
||||
form = req.form
|
||||
if not form:
|
||||
req.content_type = 'text/html'
|
||||
req.write(_pageTitle(req, title = 'Удаление'))
|
||||
items.selectopts = 'DISTINCT'
|
||||
items.order = 'Filename'
|
||||
files = []
|
||||
for i in xrange(len(items)):
|
||||
files += [items[i][0],]
|
||||
# for i in xrange(len(files)):
|
||||
# req.write(files[i] + '<br>')
|
||||
req.write(_pageDeleteForm(req, files))
|
||||
req.write(_pageFooter(req))
|
||||
else:
|
||||
req.content_type = 'text/html'
|
||||
filename = form['filename']
|
||||
items.delete_by_filter('WHERE `Filename` = \'%s\'' % filename)
|
||||
req.write(_pageTitle(req, 'http-equiv="refresh" content="3; url=delete"'))
|
||||
req.write(_pageDone(req))
|
||||
req.write(_pageFooter(req))
|
||||
|
||||
def view(req):
|
||||
_init(req)
|
||||
import bc
|
||||
db = MySQLdb.connect(host = DB_HOST, user = DB_USER, passwd = DB_PASSWORD, db = DB_NAME, charset = "utf8", use_unicode = False)
|
||||
dbfields = ['key', 'Filename' ,'FirstName', 'LastName', 'City', 'Country', 'Address', 'ZipCode', 'State', 'Email', 'WebSite', 'Title', 'Company', 'Phone', 'Phone2', 'Fax', 'CellPhone', 'Image']
|
||||
items = bc.table(db, "vcards", dbfields)
|
||||
form = req.form
|
||||
if not form:
|
||||
req.content_type = 'text/html'
|
||||
req.write(_pageTitle(req, title = 'Выбор раздела'))
|
||||
items.selectopts = 'DISTINCT'
|
||||
items.columns = ['Filename']
|
||||
items.order = 'Filename'
|
||||
len_items = len(items)
|
||||
files = []
|
||||
for i in xrange(len_items):
|
||||
files += [items[i][0],]
|
||||
req.write(_pageFileSelect(req, files))
|
||||
req.write(_pageFooter(req))
|
||||
else:
|
||||
#items.order = 'LastName'
|
||||
items.setorder('LastName')
|
||||
filename = form['filename']
|
||||
try:
|
||||
page = int(form['page'])
|
||||
except:
|
||||
page = 1
|
||||
items.setfilter('WHERE `FileName` = \'%s\'' % filename)
|
||||
len_items = len(items)
|
||||
|
||||
startpos = (page - 1) * ITEMS_PER_PAGE
|
||||
endpos = startpos + ITEMS_PER_PAGE - 1
|
||||
if startpos > (len_items - 1):
|
||||
startpos = len_items - 1
|
||||
if endpos > (len_items - 1):
|
||||
endpos = len_items - 1
|
||||
|
||||
numpages = len_items / ITEMS_PER_PAGE
|
||||
if len_items % ITEMS_PER_PAGE > 0:
|
||||
numpages += 1
|
||||
|
||||
req.content_type = 'text/html'
|
||||
|
||||
if len_items > 0:
|
||||
req.write(_pageTitle(req, title = filename))
|
||||
req.write('<H2>Просмотр записей раздела %s</H2>' % filename)
|
||||
req.write('<a href="view">Вернуться к выбору раздела</a><br><br>\n')
|
||||
req.write('Количество записей: %s<br>\n' % len_items)
|
||||
req.write(_pagePrintPages(req, filename, numpages, page))
|
||||
req.write('Отображаемые записи: %s - %s<br>\n' % ((startpos + 1), (endpos + 1)))
|
||||
for i in xrange(startpos, endpos + 1):
|
||||
req.write(_pagePrintItem(req, items[i]))
|
||||
req.write(_pagePrintPages(req, filename, numpages, page))
|
||||
else:
|
||||
req.write(_pageTitle(req, title = 'Error!'))
|
||||
req.write('<H2><center><font color="red">ОШИБКА! Выбранный раздел отсутствует!</font></center></H2>')
|
||||
req.write(_pageFooter(req))
|
Loading…
Reference in New Issue