diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..89efaf2 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306/sarbaseapp + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..265df42 --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/admin.py b/admin.py index fe28ab3..41edeb1 100644 --- a/admin.py +++ b/admin.py @@ -23,10 +23,10 @@ class UserModelView(AdminModelView): admin = Admin(app, name='SAR Admin', template_mode='bootstrap3') admin.add_view(UserModelView(User, db.session)) -admin.add_view(AdminModelView(Role, db.session)) admin.add_view(AdminModelView(SARCall, db.session)) admin.add_view(AdminModelView(Comment, db.session)) admin.add_view(AdminModelView(GPSTrack, db.session)) +admin.add_view(AdminModelView(Role, db.session, category="Dictionaries")) admin.add_view(AdminModelView(SARCategory, db.session, category="Dictionaries")) admin.add_view(AdminModelView(SARStatus, db.session, category="Dictionaries")) admin.add_view(AdminModelView(SARResult, db.session, category="Dictionaries")) diff --git a/app.py b/app.py index 8d2bb8f..cd4850e 100644 --- a/app.py +++ b/app.py @@ -47,7 +47,7 @@ import dashboard @app.route('/') def hello_world(): # put application's code here - return redirect(url_for('dashboard')) + return redirect(url_for('list_sar')) @app.route('/set_language/') diff --git a/models.py b/models.py index 2f0cf59..4193812 100644 --- a/models.py +++ b/models.py @@ -30,6 +30,7 @@ class SARCall(db.Model): def __repr__(self): return self.title + class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) created = db.Column(db.DateTime, nullable=False, default=datetime.now) diff --git a/sar_calls.py b/sar_calls.py index 7e1c699..54f84e6 100644 --- a/sar_calls.py +++ b/sar_calls.py @@ -1,10 +1,11 @@ from dateutil import parser from flask import request, redirect, flash, render_template, url_for, jsonify, Response from flask_login import login_required, current_user -from sqlalchemy import or_ +from sqlalchemy import or_, and_ +from sqlalchemy.orm import aliased from app import app, db -from models import SARCall, Comment, GPSTrack, SARCategory, SARStatus, User, Role +from models import SARCall, Comment, GPSTrack, SARCategory, SARStatus, User, Role, SARResult @app.route('/create_sar', methods=['GET', 'POST']) @@ -12,8 +13,7 @@ from models import SARCall, Comment, GPSTrack, SARCategory, SARStatus, User, Rol def create_sar(): categories = SARCategory.query.all() statuses = SARStatus.query.order_by('id').all() - managers = User.query.join(Role).filter(or_(Role.name == 'search manager', Role.name =='admin')).all() - + managers = User.query.join(Role).filter(or_(Role.name == 'search manager', Role.name == 'admin')).all() if request.method == 'POST': start_date = parser.parse(request.form.get('start_date')) @@ -50,12 +50,20 @@ def create_sar(): @app.route('/list_sar') -@login_required def list_sar(): - sar_calls = SARCall.query.join(User, SARCall.search_officer_id == User.id).join(SARCategory, - SARCall.category == SARCategory.id).add_columns( - SARCategory, User, SARCall).all() - return render_template('list_sar.html', sar_calls=sar_calls) + is_logged_in = current_user.is_authenticated + search_officer = aliased(User) + coordination_officer = aliased(User) + + sar_calls = (SARCall.query + .outerjoin(search_officer, and_ (SARCall.search_officer_id == search_officer.id, SARCall.search_officer_id != None)) + .join(coordination_officer, SARCall.coordination_officer_id == coordination_officer.id) + .join(SARCategory, SARCall.category == SARCategory.id) + .join(SARStatus, SARCall.status == SARStatus.id) + .add_columns(SARCategory, SARCall, SARStatus) + .all()) + + return render_template('list_sar.html', sar_calls=sar_calls, is_logged_in=is_logged_in) @app.route('/edit_sar/', methods=['GET', 'POST']) @@ -64,7 +72,7 @@ def edit_sar(id): sar_call = SARCall.query.get_or_404(id) categories = SARCategory.query.all() statuses = SARStatus.query.order_by('id').all() - managers = User.query.join(Role).filter(or_(Role.name == 'search manager', Role.name =='admin')).all() + managers = User.query.join(Role).filter(or_(Role.name == 'search manager', Role.name == 'admin')).all() if request.method == 'POST': sar_call.start_date = parser.parse(request.form.get('start_date')) @@ -94,12 +102,27 @@ def edit_sar(id): @app.route('/sar_details/') def sar_details(id): - sar = SARCall.query.get_or_404(id) # Fetch the SARCall record or return 404 + is_logged_in = current_user.is_authenticated + search_officer = aliased(User) + coordination_officer = aliased(User) + + sar = (SARCall.query + .outerjoin(search_officer, + and_(SARCall.search_officer_id == search_officer.id, SARCall.search_officer_id != None)) + .join(coordination_officer, SARCall.coordination_officer_id == coordination_officer.id) + .join(SARCategory, SARCall.category == SARCategory.id) + .join(SARStatus, SARCall.status == SARStatus.id) + .outerjoin(SARResult, and_(SARCall.result == SARResult.id, SARCall.result != None)) + .add_columns(SARCall, SARCategory, SARStatus, SARResult) + .filter(SARCall.id == id).first()) + + comments = Comment.query.filter_by(sar_call_id=id).all() + gpx_files = [id[0] for id in GPSTrack.query.with_entities(GPSTrack.id).filter_by( sar_call_id=id).all()] # Fetch all GPX files for this SARCall comments_with_gpx = [] - for comment in sar.comments: + for comment in comments: gpx_tracks = GPSTrack.query.filter_by(comment_id=comment.id).all() for track in gpx_tracks: comments_with_gpx.append({ @@ -109,7 +132,9 @@ def sar_details(id): "comment": track.gpx_name }) - return render_template('sar_details.html', sar=sar, gpx_ids=gpx_files, comments_with_gpx=comments_with_gpx) + print(sar) + + return render_template('sar_details.html', sar=sar, gpx_ids=gpx_files, comments_with_gpx=comments_with_gpx,is_logged_in=is_logged_in) @app.route('/delete_sar/') @@ -180,7 +205,6 @@ def upload_gpx(): @app.route('/get_gpx/') -@login_required def get_gpx(gpx_id): gpx_file = GPSTrack.query.get_or_404(gpx_id) return Response(gpx_file.gpx_data, mimetype='application/gpx+xml') diff --git a/templates/base.html b/templates/base.html index 821564d..dbafc80 100644 --- a/templates/base.html +++ b/templates/base.html @@ -21,9 +21,11 @@ + {% if current_user.is_authenticated %} + {% endif %} diff --git a/templates/list_sar.html b/templates/list_sar.html index c232a76..4be3fb4 100644 --- a/templates/list_sar.html +++ b/templates/list_sar.html @@ -18,7 +18,10 @@ Category Created by Manager + + {% if is_logged_in %} Actions + {% endif %} @@ -26,25 +29,27 @@ {{ sar.SARCall.id }} {{ sar.SARCall.title }} - {{ sar.SARCall.status }} + {{ sar.SARStatus.name }} {{ sar.SARCall.start_date }} {{ sar.SARCall.finish_date }} {{ sar.SARCategory.name }} - {{ sar.User.full_name }} - {{ sar.SARCall.manager }} + {{ sar.SARCall.coordination_officer.full_name }} + {{ sar.SARCall.search_officer.full_name }} + {% if is_logged_in %} - | - - +{# #} +{# #} +{# #} + {% endif %} {% endfor %} - Back to Dashboard +{# Back to Dashboard#}