Диплом: Автоматизация процесса введения документации и отчетности в ООО "Аэрофильтр"

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
91
file = await self.gridfs.get(doc['fileid'])
return file
import aiohttp_jinja2
from aiohttp import web
from datetime import datetime
from tempfile import NamedTemporaryFile
from aiohttp_session import get_session
from settings import config
from components.documents.models import Document
from utils.jinjia_utils import complete_response
class Download(web.View):
async def get(self):
_id = self.request.match_info.get('id')
if not _id:
raise web.HTTPFound(self.request.app.router['main']._path)
d = Document(self.request.app.db)
file = await d.download(_id)
92
headers = {
'Content-Type': 'application/octet-stream',
'Content-Disposition': 'attachment; filename=%s' % file.filename
}
return web.Response(body=await file.read(), headers=headers)
class AddNew(web.View):
@aiohttp_jinja2.template('documents/add_new.jinja2')
@complete_response
async def get(self):
return {
'document_types': config.get('document_types') or {}
}
@aiohttp_jinja2.template('documents/add_new.jinja2')
@complete_response
async def post(self):
reader = await self.request.multipart()
93
data = {}
while True:
field = await reader.next()
if not field:
break
if field.name == 'fileinput':
filename = field.filename
with NamedTemporaryFile(delete=False, suffix=filename) as f:
while True:
chunk = await field.read_chunk()
if not chunk:
break
f.write(chunk)
data['filename'] = filename
data['filepath'] = f.name
else:
data[field.name] = (await field.read()).decode('utf-8')
data['created'] = datetime.now()
94
if data.get('date'):
try:
_ = datetime.strptime(data['date'], '%Y-%m-%d')
except:
_ = data['created']
data['date'] = _
else:
data['date'] = data['created']
errors = []
if not data.get('filename'):
errors.append('Не задан файл документа')
if not data.get('title'):
errors.append('Неверный заголовок')
if not data.get('type') or not config.document_types.get(data.get('type', '')):
errors.append('Неверный тип документа')
if errors:
return dict(document_types=config.get('document_types') or {}, errors=errors,
**data)
session = await get_session(self.request)
95
user = session.get('user')
data['author'] = user['login']
data['access_level'] = -1
d = Document(self.request.app.db)
if not await d.process_document(data):
errors.append('Неверный файл документа')
if errors:
return dict(document_types=config.get('document_types') or {},
errors=errors, **data)
session = await get_session(self.request)
session['success'] = 'Документ добавлен'
return web.HTTPSeeOther(self.request.app.router['main']._path)
import datetime
import phonenumbers
from bson.objectid import ObjectId
from dotted.collection import DottedDict
96
def multidict_to_dict(multidict):
d = {}
for k in multidict.keys():
v = multidict.getall(k)
if isinstance(v, list) and len(v) > 1:
d[k] = v
else:
d[k] = v[0]
return d
def tolist(val):
if not val and not val.__class__ in (int, float, bool):
return []
if val.__class__ is set or val.__class__ is tuple:
return list(val)
return val if val.__class__ is list else [val]
def hex_to_unicode(h):
if not h:
97
return ''
new = ''
for i in range(int(len(h) / 4)):
new += chr(int(h[i * 4:(i + 1) * 4], 16))
return new.encode('utf-16', 'surrogatepass').decode('utf-16')
def unicode_to_hex(t):
if not t:
return ''
return ''.join(['{:04x}'.format(ord(x)) for x in t])
def validate_phone(phone):
try:
phone = phonenumbers.parse(phone)
if phonenumbers.is_valid_number(phone):
return '+%s%s' % (phone.country_code, phone.national_number)
else:
return False
except phonenumbers.NumberParseException:
return False
98
def json_default(obj):
if isinstance(obj, ObjectId):
return str(obj)
if isinstance(obj, datetime.datetime):
return int(obj.timestamp())
def dict_to_dotted(d, result=None, prev_keys=None):
if d.__class__ is DottedDict:
d = d.to_python()
if result is None:
result = {}
if prev_keys is None:
prev_keys = []
for k, v in d.items():
if isinstance(v, dict):
dict_to_dotted(v, result, prev_keys + [k])
else:
result['.'.join(prev_keys + [k])] = v
99
return result
import docx
import magic
from openpyxl import load_workbook
from openpyxl.utils.exceptions import InvalidFileException
def get_words(filename):
try:
return get_words_from_docx(filename)
except ValueError:
pass
try:
return get_words_from_xlsx(filename)
except InvalidFileException:
pass
raise Exception('InvalidFileException')
def get_words_from_docx(filename):
doc = docx.Document(filename)
100
words = set()
for p in doc.paragraphs:
words.update(str(p.text).split())
return ' '.join(words)
def detect_mime(path):
mime = magic.Magic(mime=True)
_type = mime.from_file(path)
if not _type:
return
return _type.rsplit('/')[-1]
def get_words_from_xlsx(path):
wb = load_workbook(path, read_only=True)
words = set()
for sheet_name in wb.sheetnames:

Смотрите также:

"Автоматизация обработки заявок ООО "Проектно-Строительная Компания"
"Автоматизация процесса аттестации персонала для ООО "Нэт Бай Нэт Холдинг"
"Анализ интернет-активности конкурентов ( на примере конкурентов "Газпром нефть")
"Бухгалтерский учёт и аудит расчётов с подотчётними лицами в организации на примере ООО "ЛОЦ 10""
«Психологическое сопровождение персонала в организации на примере ООО «Крокус»
Cовершенствование деловой оценки персонала в организации (на примере ООО "Даймонд кейтеринг развитие")
IPO - инструмент финансирования деятельности организации. На примере ПАО «Нефтяная компания «Лукойл»
PR как средство продвижения организации (на примере ПАО "Тамбовский завод "Комсомолец им. Н.С. Артемова")
PR-коммуникации в сфере общественного питания (на примере кафе-кондитерской «Cream Cheese»)
SMM как средство повышения эффективности работы учреждений социокультурной сферы (на примере Малого театра)