stc

a simple time card webapp
git clone _git@git.brennen.work:stc.git
Log | Files | Refs | README

commit 6bb5e0f65705b12f1a7e904ba3acdc605a5cf388
parent b8c8d8b529a0878c328b5635a51ae135f8a534b3
Author: Youth Employment Program Production <youthemployment22@gmail.com>
Date:   Tue, 11 Jun 2024 10:27:45 -0600

Meeting features and Upload document

Diffstat:
Mapp/meetings/__pycache__/routes.cpython-310.pyc | 0
Mapp/meetings/routes.py | 60+++++++++++++++++++++++++++++++++++++++++++++++-------------
Mapp/meetings/templates/get_meeting_file.html | 9++++++++-
Mapp/meetings/templates/meeting.html | 2+-
Mapp/meetings/templates/update_meeting.html | 6+++---
Aapp/meetings/templates/upload_meeting_doc_test.html | 21+++++++++++++++++++++
Mapp/meetings/templates/upload_meeting_document.html | 2+-
7 files changed, 81 insertions(+), 19 deletions(-)

diff --git a/app/meetings/__pycache__/routes.cpython-310.pyc b/app/meetings/__pycache__/routes.cpython-310.pyc Binary files differ. diff --git a/app/meetings/routes.py b/app/meetings/routes.py @@ -12,6 +12,12 @@ from app.meetings.forms import NewMeeting, UpdateMeeting, NewFileUpload #from app.meetings.meeting import mongo = PyMongo(app) +fs = GridFS(mongo.db, 'meeting') + +# REMOVE THIS WHEN UPLOAD AND READ ARE RESOLVED +#a=fs.put(b'test data') +#item = fs.get(a) +# END REMOVE ### Define fetch_meeting ### #TRY TO MOVE TO app.meetings.meeting.py @@ -167,15 +173,17 @@ def upload_meeting_document(meeting_id): return render_template('error.html',error=e) else: form = NewFileUpload() - #upload.filename = "test" if form.validate_on_submit(): - fs = GridFS(mongo.db) - upload = request.files['file'] - if upload.filename != '': - fs.put(upload) - flash("submitted {}".format(upload.filename)) - mongo.db.meeting_collection.update_one({'_id':meeting['_id']},{'$push':{'documents':upload.filename}}) - return redirect(url_for('meetings.upload_meeting_document',meeting_id=meeting['meeting_id'])) + fs = GridFS(mongo.db, 'meeting') + #fs = GridFS(mongo.db) + #upload = request.files['file'] + upload = request.files[form.document.name].read() + uploadfn = request.files[form.document.name].filename + if uploadfn != '': + fid = fs.put(upload,filename=uploadfn,meeting=ObjectId(meeting['_id'])) + flash("submitted {}".format(uploadfn)) + mongo.db.meeting_collection.update_one({'_id':meeting['_id']},{'$push':{'documents':{"doc_id":ObjectId(fid),"doc_filename":uploadfn}}}) + return redirect(url_for('meetings.upload_meeting_document',meeting_id=meeting['meeting_id'])) # app_root = os.path.dirname(os.path.abspath(__file__)) # target = os.path.join(app_root, 'static/meeting-docs') # if not os.path.isdir(target): @@ -189,18 +197,44 @@ def upload_meeting_document(meeting_id): # return redirect(url_for('meetings.upload_meeting_document',meeting_id=meeting['meeting_id'])) return render_template('upload_meeting_document.html',meeting=meeting,form=form) +@bp.route('/meetings/upload',methods=["GET","POST"]) +@login_required +def upload_doc(): + form = NewFileUpload() + if form.validate_on_submit(): + fs = GridFS(mongo.db, 'meeting') + upload = request.files[form.document.name].read() + if request.files[form.document.name].filename != '': + fid = fs.put(upload,filename=request.files[form.document.name].filename,meeting="meeting id") + flash("submitted {}".format(fid)) + return redirect(url_for('meetings.upload_doc')) + return render_template('upload_meeting_doc_test.html',form=form) + @bp.route('/meeting/get-file/<fid>') @bp.route('/meeting/get-file') def get_meeting_file(fid=None): - fs = GridFS(mongo.db) - #fs = GridFS(MongoClient().CINEfs_example) - + fs = GridFS(mongo.db, 'meeting') if fid is not None: file = fs.get(ObjectId(fid)) rfile = app.response_class(file, direct_passthrough=True, mimetype='application/octet-stream') - rfile.headers.set('Content-Disposition','attachment', filename=fid) #maybe change to actually return real filename instead of file_id + rfile.headers.set('Content-Disposition','attachment',filename=file.filename) #maybe change to actually return real filename instead of file_id return rfile - return render_template('get_meeting_file.html', files=fs.list()) + return render_template('get_meeting_file.html', files=fs.find()) #find() was list() + +@bp.route('/meeting/delete-file/<fid>') +@bp.route('/meeting/delete-file/<fid>/<previous>') +def delete_meeting_file(fid=None,previous=None): + fs = GridFS(mongo.db, 'meeting') + if fid is not None and previous is None: + fs.delete(ObjectId(fid)) + return redirect(url_for('meetings.get_meeting_file')) + elif fid is not None and previous is not None: + meeting = fetch_meeting(previous) + fs.delete(ObjectId(fid)) + mongo.db.meeting_collection.update_one({"_id":meeting["_id"]},{"$pull":{'documents':{'doc_id':ObjectId(fid)}}}) + return redirect(url_for('meetings.update_meeting',meeting_id=previous)) + else: + return render_template('get_meeting_file.html', files=fs.find())#find() was list() @bp.route('/meeting/<meeting_id>/update',methods=["GET","POST"]) @login_required diff --git a/app/meetings/templates/get_meeting_file.html b/app/meetings/templates/get_meeting_file.html @@ -11,8 +11,15 @@ {% endif %} {% endwith %} <section class="hours-grid">{#class="meeting">#} + {# {{ item.read() }} #} <ul>{% for file in files %} - <li><a href="{{ url_for('meetings.get_meeting_file', fid=file) }}">{{ file }}</a></li> + <li> + <a href="{{ url_for('meetings.get_meeting_file', fid=file._id) }}"> + {{ file.filename }} + {{ file }} + </a> + <a href="{{url_for('meetings.delete_meeting_file',fid=file._id)}}">remove</a> + </li> {% endfor %}</ul> </section> {% endblock %} diff --git a/app/meetings/templates/meeting.html b/app/meetings/templates/meeting.html @@ -13,7 +13,7 @@ {% if meeting.documents %} {% for document in meeting['documents'] %} <div> - <a href="">{{ document }}</a> + <a href="{{url_for('meetings.get_meeting_file',fid=document['doc_id'])}}">{{ document['doc_filename'] }}</a> </div> {% endfor %} {% endif %} diff --git a/app/meetings/templates/update_meeting.html b/app/meetings/templates/update_meeting.html @@ -18,10 +18,10 @@ <div style="display:flex"><h3>Location link: {{ meeting.location }}</h3><a href="{{url_for('meetings.change_meeting',meeting_id=meeting['meeting_id'],update="location")}}"style="color:red">change</a></div> <div style="display:flex"><h3>Description: {{ meeting.meeting_destription }}</h3><a href="{{url_for('meetings.change_meeting',meeting_id=meeting['meeting_id'],update="description")}}"style="color:red">change</a></div> <div style="display:flex"><h4 href="color:red">Documents:</h4><a href="{{ url_for('meetings.upload_meeting_document',meeting_id=meeting['meeting_id']) }}" style="color:red">[upload]</a></div> - {% if meeting.document %} - {% for document in meeting.document %} + {% if meeting.documents %} + {% for document in meeting.documents %} <div> - <a href="">{{ document }}</a><a href=""style="color:red">remove</a> + <a href="">{{ document["doc_filename"] }}</a><a href="{{url_for('meetings.delete_meeting_file',fid=document["doc_id"],previous=meeting["meeting_id"])}}"style="color:red">remove</a> </div> {% endfor %} {% endif %} diff --git a/app/meetings/templates/upload_meeting_doc_test.html b/app/meetings/templates/upload_meeting_doc_test.html @@ -0,0 +1,21 @@ +{% extends 'base.html' %} + +{% block title %}Upload{% endblock %} + +{% block content %} +{% with messages = get_flashed_messages() %} +{% if messages %} + {% for message in messages %} + <div id="messagebanner"><p>{{ message }}</p></div> + {% endfor %} +{% endif %} +{% endwith %} + <a href="{{ url_for('meetings.meetings') }}">back to meeting</a> + <section class="hours-grid">{#class="meeting">#} + <form action="" method="POST" novalidate enctype="multipart/form-data"> + {{ form.hidden_tag() }} + {{ form.document() }} + {{ form.submit_file() }} + </form> + </section> +{% endblock %} diff --git a/app/meetings/templates/upload_meeting_document.html b/app/meetings/templates/upload_meeting_document.html @@ -22,7 +22,7 @@ {% if meeting.documents %} <h2>existing documents</h2> {% for doc in meeting['documents'] %} - <p>{{ doc }}</p> + <p>{{ doc['doc_filename'] }}</p> {% endfor %} {% endif %} </section>