diff --git a/src/main.py b/src/main.py index 413e887..f0bba3a 100644 --- a/src/main.py +++ b/src/main.py @@ -1,13 +1,14 @@ from flask import Flask, render_template, request, redirect, url_for, flash, session from flask_sqlalchemy import SQLAlchemy +from sqlalchemy import text from datetime import date import gnupg import secrets import os from werkzeug.utils import secure_filename -# defines where the upload folder is and creates it -UPLOAD_FOLDER = "static/uploads" +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +UPLOAD_FOLDER = os.path.join(BASE_DIR, "static", "uploads") os.makedirs(UPLOAD_FOLDER, exist_ok=True) # configures the app @@ -77,27 +78,24 @@ def calculate_age(dob: date) -> int: return today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day)) # saves files to the upload folder and returns their URL + def save_files(username: str, profile_file, pictures_files): - # creates a path for the user inside the upload forlder user_folder = os.path.join(app.config['UPLOAD_FOLDER'], username) os.makedirs(user_folder, exist_ok=True) - # prevents unsafe characters to be used in the filename profile_filename = secure_filename(profile_file.filename) profile_path = os.path.join(user_folder, profile_filename) - - # saves the profile picture to the path profile_file.save(profile_path) - profile_url = f"/{profile_path.replace(os.sep, '/')}" - # saves all of the other pictures + profile_url = f"/static/uploads/{username}/{profile_filename}" + pictures_urls = [] for pic in pictures_files: if pic.filename: filename = secure_filename(pic.filename) path = os.path.join(user_folder, filename) pic.save(path) - pictures_urls.append(f"/{path.replace(os.sep, '/')}") + pictures_urls.append(f"/static/uploads/{username}/{filename}") return profile_url, pictures_urls @@ -119,8 +117,58 @@ def pgp_encrypt_and_import(pgp_key: str, message: str): @app.route("/") def home(): - return render_template("index.html") + query = User.query + country = request.args.get("country") + city = request.args.get("city") + sex = request.args.get("sex") + age_min = request.args.get("age_min") + age_max = request.args.get("age_max") + race = request.args.get("race") + likes = request.args.get("likes") + dislikes = request.args.get("dislikes") + + if country: + query = query.filter(User.country.ilike(f"%{country}%")) + if city: + query = query.filter(User.city.ilike(f"%{city}%")) + if sex: + query = query.filter(User.sex==sex) + if race: + query = query.filter(User.race.ilike(f"%{race}%")) + + today = date.today() + if age_min: + try: + min_age = int(age_min) + dob_max = date(today.year - min_age, today.month, today.day) + query = query.filter(User.date_of_birth <= dob_max) + except ValueError: + pass + if age_max: + try: + max_age = int(age_max) + dob_min = date(today.year - max_age - 1, today.month, today.day) + query = query.filter(User.date_of_birth >= dob_min) + except ValueError: + pass + + if likes: + likes_list = [x.strip().lower() for x in likes.split(",") if x.strip()] + for like in likes_list: + query = query.filter( + text(f"JSON_CONTAINS(likes, '\"{like}\"')") + ) + + if dislikes: + dislikes_list = [x.strip().lower() for x in dislikes.split(",") if x.strip()] + for dislike in dislikes_list: + query = query.filter( + text(f"JSON_CONTAINS(dislikes, '\"{dislike}\"')") + ) + + users = query.all() + return render_template("index.html", users=users, date=date) @app.route("/register", methods=["GET", "POST"]) def register(): diff --git a/src/templates/index.html b/src/templates/index.html index 9ac697a..575c8e6 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -1,5 +1,47 @@ {% extends "page.html" %} {% block content %} -

Main Page

+

Discover Users

+ +
+

Search Users

+
+ + + + + + + + + + + + + +
+
+ +
+

Users

+ {% if users %} +
+ {% for user in users %} +
+ + {{ user.username }}
+ Age: {{ (date.today() - user.date_of_birth).days // 365 }}
+ Country: {{ user.country }} +
+
+ {% endfor %} +
+ {% else %} +

No users found.

+ {% endif %} +
{% endblock %} diff --git a/src/templates/page.html b/src/templates/page.html index 02f1cbd..9cd5589 100644 --- a/src/templates/page.html +++ b/src/templates/page.html @@ -19,9 +19,7 @@ -
{% block content %}{% endblock %} -
diff --git a/src/templates/user.html b/src/templates/user.html index cfa71bf..eae8f80 100644 --- a/src/templates/user.html +++ b/src/templates/user.html @@ -1,37 +1,97 @@ {% extends "page.html" %} {% block content %} -

{{ user.firstname }} {{ user.lastname }}

-Profile Picture
+ +
+

{{ user.firstname }} {{ user.lastname }}

+ + Profile Picture

+ +

Age: {{ (date.today() - user.date_of_birth).days // 365 }}

+

Sex: {{ user.sex|capitalize }}

+
+ {% if user.pictures %} -

Pictures

-{% for pic in user.pictures %} - -{% endfor %} +
+

Gallery

+ {% for pic in user.pictures %} + + {% endfor %} +
{% endif %} -

Personal Info

-

Sex: {{ user.sex }}

-

Date of Birth: {{ user.date_of_birth }}

-

Age: {{ (date.today() - user.date_of_birth).days // 365 }}

-

Race: {{ user.race or 'Not specified' }}

-

Location

-

Country: {{ user.country }}

-

City: {{ user.city or 'Not specified' }}

+
+

Personal Info

+

Date of Birth: {{ user.date_of_birth }}

+

Race: {{ user.race or 'Not specified' }}

+
-

Physical Attributes

-

Height: {{ user.height or 'Not specified' }} m

-

Weight: {{ user.weight or 'Not specified' }} kg

-

Preferences

-

Preferred Age Range: {{ user.prefered_age_range or 'Not specified' }}

-

Likes: {{ user.likes | join(', ') if user.likes else 'Not specified' }}

-

Dislikes: {{ user.dislikes | join(', ') if user.dislikes else 'Not specified' }}

+
+

Location

+

Country: {{ user.country }}

+

City: {{ user.city or 'Not specified' }}

+
+ + +
+

Physical Attributes

+

Height: + {% if user.height %} + {{ user.height }} m + {% else %} + Not specified + {% endif %} +

+ +

Weight: + {% if user.weight %} + {{ user.weight }} kg + {% else %} + Not specified + {% endif %} +

+
+ + +
+

Preferences

+ +

Preferred Age Range: + {{ user.prefered_age_range or 'Not specified' }} +

+ +

Likes:

+ {% if user.likes %} + + {% else %} +

Not specified

+ {% endif %} + +

Dislikes:

+ {% if user.dislikes %} + + {% else %} +

Not specified

+ {% endif %} +
+ + +
+

Contacts

+

XMPP: {{ user.xmpp }}

+

Email: {{ user.email or 'Not specified' }}

+

Phone: {{ user.phone or 'Not specified' }}

+
-

Contacts

-

XMPP: {{ user.xmpp }}

-

Email: {{ user.email or 'Not specified' }}

-

Phone: {{ user.phone or 'Not specified' }}

{% endblock %} diff --git a/static/uploads/bacalhau/DSCF6163.JPG b/static/uploads/bacalhau/DSCF6163.JPG new file mode 100644 index 0000000..589f1a7 Binary files /dev/null and b/static/uploads/bacalhau/DSCF6163.JPG differ diff --git a/static/uploads/bacalhau/DSCF6169.JPG b/static/uploads/bacalhau/DSCF6169.JPG new file mode 100644 index 0000000..608543c Binary files /dev/null and b/static/uploads/bacalhau/DSCF6169.JPG differ diff --git a/static/uploads/bacalhau/DSCF6170.JPG b/static/uploads/bacalhau/DSCF6170.JPG new file mode 100644 index 0000000..c42cc0a Binary files /dev/null and b/static/uploads/bacalhau/DSCF6170.JPG differ diff --git a/static/uploads/bacalhau/DSCF6171.JPG b/static/uploads/bacalhau/DSCF6171.JPG new file mode 100644 index 0000000..c547aba Binary files /dev/null and b/static/uploads/bacalhau/DSCF6171.JPG differ diff --git a/static/uploads/bacalhau/DSCF6236.JPG b/static/uploads/bacalhau/DSCF6236.JPG new file mode 100644 index 0000000..d655f58 Binary files /dev/null and b/static/uploads/bacalhau/DSCF6236.JPG differ diff --git a/static/uploads/bacalhau/DSCF6238.JPG b/static/uploads/bacalhau/DSCF6238.JPG new file mode 100644 index 0000000..6aea430 Binary files /dev/null and b/static/uploads/bacalhau/DSCF6238.JPG differ diff --git a/static/uploads/bacalhau/DSCF6242.JPG b/static/uploads/bacalhau/DSCF6242.JPG new file mode 100644 index 0000000..0a02c65 Binary files /dev/null and b/static/uploads/bacalhau/DSCF6242.JPG differ