MVP version 0

This commit is contained in:
Vadim Likholetov 2023-11-23 11:08:14 +02:00
parent 81858e309d
commit f5dc55eff8
4 changed files with 102 additions and 56 deletions

2
app.py
View File

@ -53,7 +53,7 @@ def hello_world(): # put application's code here
@app.route('/set_language/<lang_code>')
def set_language(lang_code):
session['language'] = lang_code
return redirect(request.referrer or url_for('dashboard'))
return redirect(request.referrer or url_for('list_sar'))

View File

@ -13,7 +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 officer', Role.name == 'admin')).all()
if request.method == 'POST':
start_date = parser.parse(request.form.get('start_date'))
@ -22,12 +22,6 @@ def create_sar():
longitude = request.form.get('longitude')
status = request.form.get('status')
title = request.form.get('title')
# gpx_data_list = request.form.getlist('gpx_data[]')
# gpx_color_list = request.form.getlist('gpx_color[]')
# for data, color in zip(gpx_data_list, gpx_color_list):
# track = GPSTrack(data=data, color=color, sar_call=new_sar_call)
# db.session.add(track)
new_sar_call = SARCall(
start_date=start_date,
@ -56,7 +50,8 @@ def list_sar():
coordination_officer = aliased(User)
sar_calls = (SARCall.query
.outerjoin(search_officer, and_ (SARCall.search_officer_id == search_officer.id, SARCall.search_officer_id != None))
.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)
@ -72,7 +67,10 @@ 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()
results = SARResult.query.all()
search_officers = User.query.join(Role).filter(or_(Role.name == 'search officer', Role.name == 'admin')).all()
coordination_officers = User.query.join(Role).filter(
or_(Role.name == 'coordination officer', Role.name == 'admin')).all()
if request.method == 'POST':
sar_call.start_date = parser.parse(request.form.get('start_date'))
@ -83,9 +81,16 @@ def edit_sar(id):
sar_call.longitude = request.form.get('longitude')
sar_call.status = request.form.get('status')
sar_call.result = request.form.get('result')
if (request.form.get('latitude_found') and request.form.get('longitude_found')
and request.form.get('latitude_found') != 'None' and request.form.get('longitude_found') != 'None'):
sar_call.latitude_found = request.form.get('latitude_found')
sar_call.longitude_found = request.form.get('longitude_found')
sar_call.title = request.form.get('title')
sar_call.description = request.form.get('description')
sar_call.description_hidden = request.form.get('description_hidden')
sar_call.search_officer_id = request.form.get('search_officer')
sar_call.coordination_officer_id = request.form.get('coordination_officer')
db.session.commit()
flash('SAR call updated successfully!', 'success')
@ -97,7 +102,8 @@ def edit_sar(id):
sar_call.finish_date = sar_call.finish_date.strftime('%Y-%m-%d')
return render_template('edit_sar.html', sar_call=sar_call, categories=categories, statuses=statuses,
managers=managers)
coordination_officers=coordination_officers, results=results,
search_officers=search_officers)
@app.route('/sar_details/<int:id>')
@ -132,9 +138,8 @@ def sar_details(id):
"comment": track.gpx_name
})
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)
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/<int:id>')
@ -207,4 +212,5 @@ def upload_gpx():
@app.route('/get_gpx/<int:gpx_id>')
def get_gpx(gpx_id):
gpx_file = GPSTrack.query.get_or_404(gpx_id)
return Response(gpx_file.gpx_data, mimetype='application/gpx+xml')
return Response(gpx_file.gpx_data, mimetype='application/gpx+xml',
headers={'Content-Disposition': 'attachment;filename=' + gpx_file.file_name + '.gpx'})

View File

@ -30,6 +30,11 @@
<!-- Display user info and logout link if user is authenticated -->
<ul class="navbar-nav ml-auto">
{% if current_user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="/admin">{{ _('DB Admin') }}</a>
</li>
{% endif %}
<!-- Language Dropdown in Bootstrap -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button"
@ -98,6 +103,5 @@
</script>
</body>
</html>

View File

@ -49,11 +49,27 @@
</div>
<div class="form-group">
<label for="coordinates">Geographical Coordinates:</label>
<label for="result">Job result:</label>
<select name="result" id="result" class="form-control">
{% for result in results %}
<option value="{{ result.id }}" {% if result.id == sar_call.result %}selected{% endif %}>
{{ result.name }}
</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="coordinates">IPP Coordinates:</label>
<input type="text" name="longitude" class="form-control" value="{{ sar_call.longitude }}" required>
<input type="text" name="latitude" class="form-control" value="{{ sar_call.latitude }}" required>
</div>
<div class="form-group">
<label for="coordinates">Victim found coordinates:</label>
<input type="text" name="longitude_found" class="form-control" value="{{ sar_call.longitude_found }}">
<input type="text" name="latitude_found" class="form-control" value="{{ sar_call.latitude_found }}">
<div class="form-group">
<label for="title">Title:</label>
<input type="text" name="title" class="form-control" value="{{ sar_call.title }}" required>
@ -67,14 +83,34 @@
<div class="form-group">
<label for="description_hidden">Hidden Description:</label>
<textarea name="description_hidden" class="form-control">{{ sar_call.description_hidden }}</textarea>
<textarea name="description_hidden"
class="form-control">{{ sar_call.description_hidden }}</textarea>
</div>
<div class="form-group">
<label for="coordination_officer">Created by:</label>
<select name="coordination_officer" id="coordination_officer" class="form-control">
{% for coordination_officer in coordination_officers %}
<option value="{{ coordination_officer.id }}"
{% if coordination_officer.id == sar_call.coordination_officer_id %}selected{% endif %}>
{{ coordination_officer.full_name }}
</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="search_officer">Search officer:</label>
<select name="search_officer" id="search_officer" class="form-control">
{% for search_officer in search_officers %}
<option value="{{ search_officer.id }}"
{% if search_officer.id == sar_call.search_officer_id %}selected{% endif %}>
{{ search_officer.full_name }}
</option>
{% endfor %}
</select>
</div>
{# <!-- GPX Track Fields (You can expand upon this based on the previous discussion about multiple tracks) -->#}
{# <div class="form-group">#}
{# <label for="gpx_file">Upload GPX Track:</label>#}
{# <input type="file" name="gpx_file">#}
{# </div>#}
<button type="submit" class="btn btn-primary">Update</button>
</form>