forked from orson/bachemap
camera progress
This commit is contained in:
parent
e6e6620eb7
commit
1e51771917
48
app.py
48
app.py
@ -205,6 +205,37 @@ def create_app(config=Config):
|
||||
else:
|
||||
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')
|
||||
def manifest():
|
||||
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.save(photo_path)
|
||||
|
||||
# TODO: Optionally embed latitude/longitude into the photo’s EXIF here
|
||||
# using piexif or Pillow
|
||||
# Create a new pin with the uploaded photo data
|
||||
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
|
||||
return f"Photo uploaded! Lat: {latitude}, Lng: {longitude}"
|
||||
|
||||
|
||||
@ -347,7 +347,13 @@ section#pinner-modal::-webkit-scrollbar-thumb {
|
||||
box-shadow: 0 4px 15px var(--shadow-color);
|
||||
animation: fadeOut 15s forwards;
|
||||
}
|
||||
|
||||
ul.flashes li {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font-size: 1.2rem;
|
||||
color: black;
|
||||
}
|
||||
/* Animations */
|
||||
@keyframes fadeOut {
|
||||
0% { opacity: 1; transform: translateY(0); }
|
||||
|
||||
@ -157,6 +157,9 @@
|
||||
}).then(response => {
|
||||
if (response.redirected) {
|
||||
window.location.href = response.url;
|
||||
} else (response.ok) {
|
||||
console.log('Success:', response);
|
||||
window.location.href = '{{ url_for('dashboard') }}';
|
||||
}
|
||||
}).catch(error => console.error('Error:', error));
|
||||
}, 'image/jpeg', 0.9);
|
||||
|
||||
@ -32,7 +32,6 @@
|
||||
{% for pin in pins %}
|
||||
|
||||
<table border="1" cellpadding="5" cellspacing="0">
|
||||
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><b>Agregado el</b></td>
|
||||
@ -63,10 +62,47 @@
|
||||
<td>{{ pin.lng }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>Eliminar este Pin:</b></td>
|
||||
<td><a href="/remove_pin/{{pin._id}}"><button type="submit" formmethod="get">Eliminar</button></a></td>
|
||||
<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>
|
||||
|
||||
<!-- Modal para editar pin -->
|
||||
<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);">
|
||||
<div class="modal-content" style="background-color:#fff; margin:10% auto; padding:20px; width:70%; border-radius:5px;">
|
||||
<span class="close" onclick="closeEditModal('{{pin._id}}')" style="color:#aaa; float:right; font-size:28px; font-weight:bold; cursor:pointer;">×</span>
|
||||
<h2>Editar Pin</h2>
|
||||
<form action="/edit_pin/{{pin._id}}" method="post">
|
||||
<div style="margin-bottom:15px;">
|
||||
<label for="typeofpin{{pin._id}}"><b>Tipo de Mejora Urbana:</b></label>
|
||||
<input type="text" id="typeofpin{{pin._id}}" name="typeofpin" value="{{pin.typeofpin}}" style="width:100%; padding:8px;">
|
||||
</div>
|
||||
<div style="margin-bottom:15px;">
|
||||
<label for="description{{pin._id}}"><b>Descripción:</b></label>
|
||||
<textarea id="description{{pin._id}}" name="description" style="width:100%; padding:8px; height:100px;">{{pin.description}}</textarea>
|
||||
</div>
|
||||
<div style="margin-bottom:15px;">
|
||||
<label for="address{{pin._id}}"><b>Dirección:</b></label>
|
||||
<input type="text" id="address{{pin._id}}" name="address" value="{{pin.address}}" style="width:100%; padding:8px;">
|
||||
</div>
|
||||
<button type="submit" style="background-color:#4CAF50; color:white; padding:10px 15px; border:none; cursor:pointer; border-radius:4px;">Guardar cambios</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
function openEditModal(id) {
|
||||
document.getElementById('editModal'+id).style.display = 'block';
|
||||
}
|
||||
|
||||
function closeEditModal(id) {
|
||||
document.getElementById('editModal'+id).style.display = 'none';
|
||||
}
|
||||
</script></div>
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
@ -34,34 +34,13 @@
|
||||
</head>
|
||||
<body style="color: black; height: 100%; margin: 0;">
|
||||
{% 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() %}
|
||||
{% if messages %}
|
||||
<div style="position:sticky; z-index: 9999;">
|
||||
<ul class="flashes">
|
||||
|
||||
<div class="flashes">
|
||||
{% for message in messages %}
|
||||
<li>{{message}}</li>
|
||||
<h3>{{message}}</h3>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user