1
0
forked from orson/bachemap

camera progress

This commit is contained in:
Orson 2025-03-14 18:00:31 -06:00
parent e6e6620eb7
commit 1e51771917
5 changed files with 132 additions and 64 deletions

50
app.py
View File

@ -205,6 +205,37 @@ def create_app(config=Config):
else: else:
return redirect(url_for('index')) return redirect(url_for('index'))
@app.route("/edit_pin/<pin_id>", methods=['POST'])
@login_required
def edit_pin(pin_id):
actual_pin = mongo.db.pins.find_one({"_id": ObjectId(pin_id)})
if not actual_pin:
flash('Pin no encontrado')
return redirect(url_for('dashboard'))
added_by = actual_pin.get("added_by")
if current_user.is_admin or current_user.id == added_by:
# Get form data
typeofpin = request.form.get('typeofpin')
description = request.form.get('description')
address = request.form.get('address')
# Update the pin
mongo.db.pins.update_one(
{"_id": ObjectId(pin_id)},
{"$set": {
"typeofpin": typeofpin,
"description": description,
"address": address
}}
)
flash('Pin actualizado exitosamente')
return redirect(url_for('dashboard'))
else:
flash('No tienes permiso para editar este pin')
return render_template('error.html', message='No tienes permiso para editar este pin'), 403
@app.route('/manifest.json') @app.route('/manifest.json')
def manifest(): def manifest():
return send_from_directory('static', 'manifest.json') return send_from_directory('static', 'manifest.json')
@ -260,9 +291,22 @@ def create_app(config=Config):
photo_path = os.path.join(app.config['UPLOAD_FOLDER'], photo.filename) photo_path = os.path.join(app.config['UPLOAD_FOLDER'], photo.filename)
photo.save(photo_path) photo.save(photo_path)
# TODO: Optionally embed latitude/longitude into the photos EXIF here # Create a new pin with the uploaded photo data
# using piexif or Pillow pin = {
'time': datetime.now(),
'photo': photo_path,
'lat': latitude,
'lng': longitude,
'typeofpin': request.form.get('typeofpin', 'bache'), # Default to bache if not specified
'added_by': current_user.id,
'description': request.form.get('description', 'Foto desde cámara'), # Default description
'reviewed': False, # Added reviewed field set to False
'address': str(geolocator.reverse(f"{latitude}, {longitude}")) if latitude and longitude else "Ubicación desconocida"
}
# Insert the new pin into the database
mongo.db.pins.insert_one(pin)
flash('¡Gracias por tu aportación!')
# For demonstration, just redirect or return a success message # For demonstration, just redirect or return a success message
return f"Photo uploaded! Lat: {latitude}, Lng: {longitude}" return f"Photo uploaded! Lat: {latitude}, Lng: {longitude}"

View File

@ -347,7 +347,13 @@ section#pinner-modal::-webkit-scrollbar-thumb {
box-shadow: 0 4px 15px var(--shadow-color); box-shadow: 0 4px 15px var(--shadow-color);
animation: fadeOut 15s forwards; animation: fadeOut 15s forwards;
} }
ul.flashes li {
list-style: none;
padding: 0;
margin: 0;
font-size: 1.2rem;
color: black;
}
/* Animations */ /* Animations */
@keyframes fadeOut { @keyframes fadeOut {
0% { opacity: 1; transform: translateY(0); } 0% { opacity: 1; transform: translateY(0); }

View File

@ -157,6 +157,9 @@
}).then(response => { }).then(response => {
if (response.redirected) { if (response.redirected) {
window.location.href = response.url; window.location.href = response.url;
} else (response.ok) {
console.log('Success:', response);
window.location.href = '{{ url_for('dashboard') }}';
} }
}).catch(error => console.error('Error:', error)); }).catch(error => console.error('Error:', error));
}, 'image/jpeg', 0.9); }, 'image/jpeg', 0.9);

View File

@ -32,41 +32,77 @@
{% for pin in pins %} {% for pin in pins %}
<table border="1" cellpadding="5" cellspacing="0"> <table border="1" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td><b>Agregado el</b></td>
<td>{{ pin.time }}</td>
</tr>
<tr>
<td><b>Tipo de Mejora Urbana:</b></td>
<td>{{ pin.typeofpin }}</td>
</tr>
<tr>
<td><b>Descripción</b></td>
<td>{{ pin.description }}</td>
</tr>
<tr>
<td><b>Dirección</b></td>
<td>{{ pin.address }}</td>
</tr>
<tr>
<td><b>Foto</b></td>
<td><img style="max-height: 66px;" src="{{ pin.photo }}"></td>
</tr>
<tr>
<td><b>Latitud:</b></td>
<td>{{ pin.lat }}</td>
</tr>
<tr>
<td><b>Longitud:</b></td>
<td>{{ pin.lng }}</td>
</tr>
<tr>
<td><b>Acciones:</b></td>
<td>
<a href="/remove_pin/{{pin._id}}"><button type="button">Eliminar</button></a>
<button type="button" onclick="openEditModal('{{pin._id}}')">Editar</button>
</td>
</tr>
</tbody>
</table>
<tbody> <!-- Modal para editar pin -->
<tr> <div id="editModal{{pin._id}}" class="modal" style="display:none; position:fixed; z-index:1000; left:0; top:0; width:100%; height:100%; background-color:rgba(0,0,0,0.4);">
<td><b>Agregado el</b></td> <div class="modal-content" style="background-color:#fff; margin:10% auto; padding:20px; width:70%; border-radius:5px;">
<td>{{ pin.time }}</td> <span class="close" onclick="closeEditModal('{{pin._id}}')" style="color:#aaa; float:right; font-size:28px; font-weight:bold; cursor:pointer;">&times;</span>
</tr> <h2>Editar Pin</h2>
<tr> <form action="/edit_pin/{{pin._id}}" method="post">
<td><b>Tipo de Mejora Urbana:</b></td> <div style="margin-bottom:15px;">
<td>{{ pin.typeofpin }}</td> <label for="typeofpin{{pin._id}}"><b>Tipo de Mejora Urbana:</b></label>
</tr> <input type="text" id="typeofpin{{pin._id}}" name="typeofpin" value="{{pin.typeofpin}}" style="width:100%; padding:8px;">
<tr> </div>
<td><b>Descripción</b></td> <div style="margin-bottom:15px;">
<td>{{ pin.description }}</td> <label for="description{{pin._id}}"><b>Descripción:</b></label>
</tr> <textarea id="description{{pin._id}}" name="description" style="width:100%; padding:8px; height:100px;">{{pin.description}}</textarea>
<tr> </div>
<td><b>Dirección</b></td> <div style="margin-bottom:15px;">
<td>{{ pin.address }}</td> <label for="address{{pin._id}}"><b>Dirección:</b></label>
</tr> <input type="text" id="address{{pin._id}}" name="address" value="{{pin.address}}" style="width:100%; padding:8px;">
<tr> </div>
<td><b>Foto</b></td> <button type="submit" style="background-color:#4CAF50; color:white; padding:10px 15px; border:none; cursor:pointer; border-radius:4px;">Guardar cambios</button>
<td><img style="max-height: 66px;" src="{{ pin.photo }}"></td> </form>
</tr> </div>
<tr> </div>
<td><b>Latitud:</b></td>
<td>{{ pin.lat }}</td> <script type="text/javascript">
</tr> function openEditModal(id) {
<tr> document.getElementById('editModal'+id).style.display = 'block';
<td><b>Longitud:</b></td> }
<td>{{ pin.lng }}</td>
</tr> function closeEditModal(id) {
<tr> document.getElementById('editModal'+id).style.display = 'none';
<td><b>Eliminar este Pin:</b></td> }
<td><a href="/remove_pin/{{pin._id}}"><button type="submit" formmethod="get">Eliminar</button></a></td> </script></div>
</tr>
</tbody>
{% endfor %} {% endfor %}
{% endif %} {% endif %}

View File

@ -34,34 +34,13 @@
</head> </head>
<body style="color: black; height: 100%; margin: 0;"> <body style="color: black; height: 100%; margin: 0;">
{% include 'nav.html' %} {% include 'nav.html' %}
<!-- <nav style="height: auto;">
<ul>
<a href="/">
<li style="display: flex; align-items: center;">
<img id="logo" src="{{ url_for('static', filename='images/bachemapalogo.png') }}" alt="Bachemapa Logo" style="height: 10vh; margin-right: 10px;">
<h3 style="margin-bottom: 0;"><span style="color: #4a8522;">Bache</span><span style="color: #fa8721;">mapa</span></h3>
</li>
</a>
</ul>
<ul>
<li><button id="pinner-top" ><a href="/">Al mapa</a></button></li>
<li><button><a href="/quienes">Somos</a></button></li>
{% if current_user.is_authenticated %}
<li><button><a href="/dashboard">Perfil</a></button></li>
{% endif %}
</ul>
</nav> -->
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages() %}
{% if messages %} {% if messages %}
<div style="position:sticky; z-index: 9999;">
<ul class="flashes"> <div class="flashes">
{% for message in messages %} {% for message in messages %}
<li>{{message}}</li> <h3>{{message}}</h3>
{% endfor %} {% endfor %}
</ul>
</div> </div>
{% endif %} {% endif %}
{% endwith %} {% endwith %}