From 1e51771917295200519df934a11d4f55247f2456 Mon Sep 17 00:00:00 2001 From: orson Date: Fri, 14 Mar 2025 18:00:31 -0600 Subject: [PATCH] camera progress --- app.py | 50 ++++++++++++++++-- static/styles.css | 8 ++- templates/camera.html | 3 ++ templates/dashboard.html | 104 +++++++++++++++++++++++++------------- templates/secondbase.html | 31 ++---------- 5 files changed, 132 insertions(+), 64 deletions(-) diff --git a/app.py b/app.py index 1955810..c92a630 100644 --- a/app.py +++ b/app.py @@ -205,6 +205,37 @@ def create_app(config=Config): else: return redirect(url_for('index')) + @app.route("/edit_pin/", 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}" diff --git a/static/styles.css b/static/styles.css index ad749ea..10fa1f5 100644 --- a/static/styles.css +++ b/static/styles.css @@ -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); } diff --git a/templates/camera.html b/templates/camera.html index 226cd8d..bb273af 100644 --- a/templates/camera.html +++ b/templates/camera.html @@ -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); diff --git a/templates/dashboard.html b/templates/dashboard.html index d0bce47..ead8c1f 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -32,41 +32,77 @@ {% for pin in pins %} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Agregado el{{ pin.time }}
Tipo de Mejora Urbana:{{ pin.typeofpin }}
Descripción{{ pin.description }}
Dirección{{ pin.address }}
Foto
Latitud:{{ pin.lat }}
Longitud:{{ pin.lng }}
Acciones: + + +
- - - Agregado el - {{ pin.time }} - - - Tipo de Mejora Urbana: - {{ pin.typeofpin }} - - - Descripción - {{ pin.description }} - - - Dirección - {{ pin.address }} - - - Foto - - - - Latitud: - {{ pin.lat }} - - - Longitud: - {{ pin.lng }} - - - Eliminar este Pin: - - - + + + + {% endfor %} {% endif %} diff --git a/templates/secondbase.html b/templates/secondbase.html index 0c365d7..96cb914 100644 --- a/templates/secondbase.html +++ b/templates/secondbase.html @@ -34,34 +34,13 @@ {% include 'nav.html' %} - {% with messages = get_flashed_messages() %} {% if messages %} -
-
    - {% for message in messages %} -
  • {{message}}
  • - {% endfor %} -
+ +
+ {% for message in messages %} +

{{message}}

+ {% endfor %}
{% endif %} {% endwith %}