def delete_documents(): """Render document deleting form.""" form = EditDocumentForm() pfactory = PosGraduationFactory(current_user.pg_initials) dao = pfactory.official_documents_dao() json = pfactory.official_documents_dao().find() json = list(json) json = dumps(json) if form.validate_on_submit() and form.create.data: dao.find_one_and_update({'_id' : ObjectId(form.document_id.data)}, { '$set' : {'deleted' : ''}}) return redirect( url_for( 'admin.delete_documents', success_msg='Documento deletado com sucesso.' ) ) return render_template( 'admin/delete_documents.html', documents=json, form=form, success_msg=request.args.get('success_msg') )
def edit_documents(): """Render document editing form.""" allowed_extensions = ['docx', 'pdf'] form = EditDocumentForm() pfactory = PosGraduationFactory(current_user.pg_initials) dao = pfactory.official_documents_dao() ownerProgram = pfactory.mongo_id json = pfactory.official_documents_dao().find() json = list(json) json = dumps(json) if form.validate_on_submit() and form.create.data: document_id = form.document_id.data if form.document.data: if allowedFile(form.document.data.filename, allowed_extensions): insertedOn = datetime.datetime.now() insertedBy = current_user._full_name document = form.document.data path = os.path.normpath("static/upload_files/" + current_user.pg_initials.lower()) filename = uploadFiles(document, path, document.filename) new_document = { 'title': form.title.data, 'cod': form.cod.data, 'file': filename, 'insertedBy': insertedBy, 'insertedOn': insertedOn, 'category': form.category.data } dao.find_one_and_update( {'_id': ObjectId(form.document_id.data)}, {'$set': new_document}) else: return redirect( url_for('admin.edit_documents', success_msg='Tipo de documento inválido')) else: new_document = { 'title': form.title.data, 'cod': form.cod.data, 'category': form.category.data } dao.find_one_and_update({'_id': ObjectId(form.document_id.data)}, {'$set': new_document}) return redirect( url_for('admin.edit_documents', success_msg='Documento editado com sucesso.')) return render_template('admin/edit_documents.html', documents=json, form=form, success_msg=request.args.get('success_msg'))
def view_documents(initials, document): """Render a view for documents list.""" pfactory = PosGraduationFactory(initials) post_graduation = pfactory.post_graduation document_types = { 'ata': 'Atas', 'regiments': 'Regimentos', 'resolucao': 'Resoluções', 'outros': 'Outros', 'reunion': 'Planos' } document_numbers = { 'ata': 'Data', 'regiments': 'Ano', 'resolucao': 'N Resolução', 'outros': 'Ano', 'reunion': 'Título' } documents = pfactory.official_documents_dao().find({'category': document}) # renders an own page or redirect to another (external/404)? return render_template('public/documents.html', document_type=document_types[document], document_number=document_numbers[document], std=get_std_for_template(post_graduation), documents=documents)
def view_documents_others(initials): """Render a view for documents list.""" pfactory = PosGraduationFactory(initials) post_graduation = pfactory.post_graduation documents = pfactory.official_documents_dao().find({'category': 'outros'}) # renders an own page or redirect to another (external/404)? return render_template('public/documents_others.html', std=get_std_for_template(post_graduation), documents=documents)
def documents(): """Render document adding form.""" allowed_extensions = ['docx', 'pdf'] form = DocumentForm() pfactory = PosGraduationFactory(current_user.pg_initials) dao = pfactory.official_documents_dao() ownerProgram = pfactory.mongo_id if form.validate_on_submit() and form.create.data: insertedOn = datetime.datetime.now() insertedBy = current_user._full_name document = form.document.data path = os.path.normpath("static/upload_files/" + current_user.pg_initials.lower()) if allowedFile(document.filename, allowed_extensions): filename = uploadFiles(document, path, document.filename) new_document = { 'ownerProgram': ownerProgram, 'category': form.category.data, 'title': form.title.data, 'cod': form.cod.data, 'file': filename, 'insertedOn': insertedOn, 'insertedBy': insertedBy } dao.insert_one(None, new_document) return redirect( url_for( 'admin.documents', success_msg='Documento adicionado adicionado com sucesso.' ) ) else: return redirect( url_for( 'admin.documents', success_msg='', invalid_type='Tipo de documento inválido' ) ) return render_template( 'admin/documents.html', documents=dao.find_one(), form=form, success_msg=request.args.get('success_msg') )
def view_documents_others(initials): """Render a view for documents list.""" pfactory = PosGraduationFactory(initials) post_graduation = pfactory.post_graduation documents = pfactory.official_documents_dao().find({'category':'outros'}) # renders an own page or redirect to another (external/404)? return render_template( 'public/documents_others.html', std=get_std_for_template(post_graduation), documents=documents )