#!/usr/bin/env python # -*- coding: utf-8 -*- ''' Created on 17.12.2010 @author: morozov ''' import sys, cgi, datetime sys.path.append('.') import functions from wsgiref.util import application_uri config = functions.readConfig() class pageParts(object): ''' classdocs ''' def __init__(self, environ, db): ''' Constructor ''' self.environ = environ self.userName = environ['REMOTE_USER'] self.fieldStorage = cgi.FieldStorage(fp = environ['wsgi.input'], environ = environ, keep_blank_values = 1) self.db = db self.appUrl = application_uri(environ) self.requestUri = environ['REQUEST_URI'] self.errStatus = False self.errMsg = '' self.now = datetime.datetime.now() if self.fieldStorage.has_key('year') and self.fieldStorage.has_key('month') and self.fieldStorage.has_key('day'): try: self.journalDate = datetime.date(year = int(self.fieldStorage.getfirst('year')), month = int(self.fieldStorage.getfirst('month')), day = int(self.fieldStorage.getfirst('day'))) except ValueError: self.journalDate = self.now.date() else: self.journalDate = self.now.date() try: self.previousDay = self.journalDate - datetime.timedelta(days = 1) except OverflowError: self.previousDayError = True else: self.previousDayError = False try: self.nextDay = self.journalDate + datetime.timedelta(days = 1) except OverflowError: self.nextDayError = True else: self.nextDayError = False self.tomorrow = datetime.datetime.now().date() + datetime.timedelta(days = 1) if self.fieldStorage.has_key('newName')\ and self.fieldStorage.has_key('newPosition')\ and self.fieldStorage.has_key('newDepartment')\ and self.fieldStorage.has_key('newStartTimeHour')\ and self.fieldStorage.has_key('newStartTimeMinute')\ and self.fieldStorage.has_key('newEndTimeHour')\ and self.fieldStorage.has_key('newEndTimeMinute')\ and self.fieldStorage.has_key('newDescription')\ and self.fieldStorage.has_key('newChief'): try: newRecord = self.db.journalRecord(name = self.fieldStorage.getfirst('newName'), position = self.fieldStorage.getfirst('newPosition'), department = self.fieldStorage.getfirst('newDepartment'), date = self.journalDate, startTime = datetime.time(hour = int(self.fieldStorage.getfirst('newStartTimeHour')), minute = int(self.fieldStorage.getfirst('newStartTimeMinute'))), endTime = datetime.time(hour = int(self.fieldStorage.getfirst('newEndTimeHour')), minute = int(self.fieldStorage.getfirst('newEndTimeMinute'))), description = self.fieldStorage.getfirst('newDescription'), chief = self.fieldStorage.getfirst('newChief'), userName = self.userName) for value in newRecord.name, newRecord.position, newRecord.department, newRecord.description: if len(value) == 0: raise ValueError except ValueError: self.errStatus = True self.errMsg = 'Введены неверные данные. Заполняйте форму внимательнее.' else: self.db.setProperty(self.userName, 'latestName', newRecord.name) self.db.setProperty(self.userName, 'latestPosition', newRecord.position) self.db.setProperty(self.userName, 'latestDepartment', newRecord.department) self.db.setProperty(self.userName, 'latestChief', newRecord.chief) self.db.journalSaveRecord(newRecord) if self.fieldStorage.has_key('delete'): try: self.db.journalDeleteRecord(self.userName, int(self.fieldStorage.getfirst('delete'))) except: self.errStatus = True self.errMsg = 'Ошибка при удалении записи. Возможно, вы пытались удалить несуществующую запись.' self.propertyLatestName = self.db.getProperty(self.userName, 'latestName') if self.propertyLatestName == None: self.propertyLatestName = '' self.propertyLatestPosition = self.db.getProperty(self.userName, 'latestPosition') if self.propertyLatestPosition == None: self.propertyLatestPosition = '' self.propertyLatestDepartment = self.db.getProperty(self.userName, 'latestDepartment') if self.propertyLatestDepartment == None: self.propertyLatestDepartment = '' self.propertyLatestChief = self.db.getProperty(self.userName, 'latestChief') if self.propertyLatestChief == None: self.propertyLatestChief = '' def _getWeekDay(self, date): days = {0: 'понедельник', 1: 'вторник', 2: 'среда', 3: 'четверг', 4: 'пятница', 5: 'суббота', 6: 'воскресенье'} return(days[date.weekday()]) def _replaceTags(self, str): str = str.replace('<', '<') str = str.replace('>', '>') return str def header(self): output = '\n'\ '\n'\ '
\n'\ ' \n'\ '\n'
output += '
Журнал командировок \n' output += ' |
%s |
Журнал командировок
\n' return(output) def journalForDay(self): records = self.db.journalGetRecords(self.journalDate) output = '\n' output += ' \n' % (self.journalDate.day, self.journalDate.month, self.journalDate.year) output += ' | \n' output += '\n' output += ' версия для печати\n' % (self.journalDate.day, self.journalDate.month, self.journalDate.year) output += ' | \n' output += '
Дата:
\n' output += ' \n' if len(records) == 0: output += 'Дата: %s.%s.%s (%s)
\n' % (str(self.journalDate.day).zfill(2), str(self.journalDate.month).zfill(2), self.journalDate.year, self._getWeekDay(self.journalDate)) output += 'Отчёт сгенерирован: %s.%s.%s %s:%s
\n' % (str(self.now.day).zfill(2), str(self.now.month).zfill(2), self.now.year, self.now.hour, str(self.now.minute).zfill(2)) if len(records) == 0: output += 'Фамилия И.О. | \n'\ 'Должность | \n'\ 'Отдел | \n'\ 'Время начала | \n'\ 'Время окончания | \n'\ 'Цель и место встречи | \n'\ 'Руководитель | \n'\ '
%s | \n' % field output += '
Все журналы:
\n' output += '' if len(allDays) == 0: output += '
%s.%s.%s | %s |
© 2010 Сергей Морозов
\n' output += '\n' return(output) def footerPrint(self): output = '\n'\ '
\n'\ ' \n' output += '\n' return(output)