mixins.py
794 Bytes
import os
from settings import conf
class DocHandler:
@staticmethod
def get_link(doc_id, file='pdf'):
data_path = os.path.join(conf.DATA_DIR, doc_id)
if file == 'pdf':
return os.path.join(data_path, '{0}.pdf'.format(doc_id))
elif file == 'img':
return os.path.join(data_path, '{0}_img.zip'.format(doc_id))
else:
return os.path.join(data_path, '{0}.xlsx'.format(doc_id))
def get_doc_list(self, doc_queryset):
for doc_dict in doc_queryset:
doc_id = doc_dict.get('id')
doc_dict['pdf_link'] = self.get_link(doc_id)
doc_dict['img_link'] = self.get_link(doc_id, 'img')
doc_dict['excel_link'] = self.get_link(doc_id, 'excel')
return list(doc_queryset)