diff --git a/Dockerfile b/Dockerfile index 829c077..9e2edce 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.12-bullseye +FROM python:3.13.3-bullseye ENV PYTHONFAULTHANDLER=1 diff --git a/app/__init__.py b/app/__init__.py index a7999fd..47441e7 100755 --- a/app/__init__.py +++ b/app/__init__.py @@ -61,6 +61,7 @@ app.config['SECRET_KEY'] = ApplicationConfig.SECRET_KEY session.configure(bind=ApplicationConfig.SQLALCHEMY_DATABASE_URI) db = SQLAlchemy(app) bcrypt = Bcrypt(app) +app.config['SESSION_SQLALCHEMY'] = db server_session = Session(app) ma = Marshmallow(app) mail = Mail(app) diff --git a/app/customer/views.py b/app/customer/views.py index d8059c0..9c579ca 100755 --- a/app/customer/views.py +++ b/app/customer/views.py @@ -19,8 +19,15 @@ import string import random -def id_generator(size=6, chars=string.ascii_uppercase + string.digits): - return ''.join(random.choice(chars) for _ in range(size)) +def generate_random_number_string(length): + # Ensure the length is at least 1 + if length < 1: + raise ValueError("Length must be at least 1") + + # Generate a random number with the specified length + random_number = ''.join(random.choices(string.digits, k=length)) + + return random_number @@ -143,24 +150,31 @@ def create_customer(): .query(Admin_Company) .filter(Admin_Company.id == 1) .first()) - last_customer = (db.session - .query(Customer_Customer) - .order_by(Customer_Customer.id.desc()) - .first()) + + get_company = (db.session + .query(Admin_Company) + .filter(Admin_Company.id == 1) + .first()) + + + random_string = generate_random_number_string(6) + made_account_number = str(get_company.account_prefix) + '-' + str(random_string) + see_if_exists = (db.session.query(Customer_Customer).filter(Customer_Customer.account_number == made_account_number).first()) - new_customer_id = last_customer.id + 1 - if len(str(new_customer_id)) == 2: - new_customer_id = '000' + str(new_customer_id) - if len(str(new_customer_id)) == 3: - new_customer_id = '00' + str(new_customer_id) - if len(str(new_customer_id)) == 4: - new_customer_id = '0' + str(new_customer_id) + if see_if_exists is not None: - starter_digits = str(get_company.account_prefix) + '-' + str(new_customer_id) + random_string = generate_random_number_string(10) + + made_account_number = str(get_company.account_prefix) + '-' + str(random_string) + see_if_exists = (db.session.query(Customer_Customer).filter(Customer_Customer.account_number == made_account_number).first()) - made_account_number = starter_digits + if see_if_exists is not None: + random_string = generate_random_number_string(10) + + made_account_number = str(get_company.account_prefix) + '-' + str(random_string) + see_if_exists = (db.session.query(Customer_Customer).filter(Customer_Customer.account_number == made_account_number).first()) response_customer_last_name = request.json["customer_last_name"] response_customer_first_name = request.json["customer_first_name"] diff --git a/app/delivery/views.py b/app/delivery/views.py index 0861d6d..93591a8 100755 --- a/app/delivery/views.py +++ b/app/delivery/views.py @@ -136,6 +136,8 @@ def get_customer_past_delivery1(customer_id): get_customer_past_delivery = (db.session .query(Delivery_Delivery) .filter(Delivery_Delivery.customer_id == customer_id) + .filter(Delivery_Delivery.delivery_status == 10) + .order_by(Delivery_Delivery.id.desc()) .limit(5)) delivery_schema = Delivery_Delivery_schema(many=True) @@ -148,6 +150,8 @@ def get_customer_past_delivery2(customer_id): get_customer_past_delivery = (db.session .query(Delivery_Delivery) .filter(Delivery_Delivery.customer_id == customer_id) + + .order_by(Delivery_Delivery.id.desc()) .offset(5) .limit(5)) diff --git a/local_settings.py b/local_settings.py index 7e176fc..91671e9 100755 --- a/local_settings.py +++ b/local_settings.py @@ -1,4 +1,3 @@ -import redis class ApplicationConfig: @@ -33,6 +32,8 @@ class ApplicationConfig: SECRET_KEY = "youwillneverguessthiskeycia" # sessions + # Available SESSION_TYPE options: 'redis', 'sqlalchemy', 'mongodb', 'filesystem', 'memcached' + SESSION_TYPE = "sqlalchemy" SESSION_COOKIE_NAME = "eamco_session" SESSION_COOKIE_SECURE = False SESSION_COOKIE_HTTPONLY = True @@ -50,5 +51,3 @@ class ApplicationConfig: CORS_ALLOW_HEADERS = "*" CORS_ORIGIN_WHITELIST = ['*'] WHITE = ['*'] - - diff --git a/prod_settings.py b/prod_settings.py index ba76ae8..868b8a9 100644 --- a/prod_settings.py +++ b/prod_settings.py @@ -1,4 +1,3 @@ -import redis class ApplicationConfig: diff --git a/requirements.txt b/requirements.txt index cefd790..ac49817 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,20 +1,35 @@ -flask==2.3.3 -flask_sqlalchemy -flask_session==0.5.0 -flask-login==0.6.3 -flask-moment -flask-paranoid -flask-bcrypt -flask-cors -flask_marshmallow -gunicorn -python-dateutil -python-dotenv -marshmallow-sqlalchemy -psycopg2-binary -redis -sqlalchemy -flask_wtf -flask_mail -Werkzeug==2.3.8 -geopy \ No newline at end of file +bcrypt==4.3.0 +blinker==1.9.0 +cachelib==0.13.0 +click==8.1.8 +Flask==3.1.0 +Flask-Bcrypt==1.0.1 +flask-cors==5.0.1 +Flask-Login==0.6.3 +Flask-Mail==0.10.0 +flask-marshmallow==1.3.0 +Flask-Moment==1.0.6 +Flask-Paranoid==0.3.0 +Flask-Session==0.8.0 +Flask-SQLAlchemy==3.1.1 +Flask-WTF==1.2.2 +geographiclib==2.0 +geopy==2.4.1 +greenlet==3.2.2 +gunicorn==23.0.0 +itsdangerous==2.2.0 +Jinja2==3.1.6 +MarkupSafe==3.0.2 +marshmallow==4.0.0 +marshmallow-sqlalchemy==1.4.2 +msgspec==0.19.0 +packaging==25.0 +psycopg2-binary==2.9.10 +python-dateutil==2.9.0.post0 +python-dotenv==1.1.0 +redis==6.0.0 +six==1.17.0 +SQLAlchemy==2.0.40 +typing_extensions==4.13.2 +Werkzeug==3.1.3 +WTForms==3.2.1 diff --git a/requirements.txt.bak b/requirements.txt.bak new file mode 100755 index 0000000..cefd790 --- /dev/null +++ b/requirements.txt.bak @@ -0,0 +1,20 @@ +flask==2.3.3 +flask_sqlalchemy +flask_session==0.5.0 +flask-login==0.6.3 +flask-moment +flask-paranoid +flask-bcrypt +flask-cors +flask_marshmallow +gunicorn +python-dateutil +python-dotenv +marshmallow-sqlalchemy +psycopg2-binary +redis +sqlalchemy +flask_wtf +flask_mail +Werkzeug==2.3.8 +geopy \ No newline at end of file diff --git a/update_requirements.sh b/update_requirements.sh new file mode 100755 index 0000000..00bd085 --- /dev/null +++ b/update_requirements.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# Script to update pip packages and regenerate requirements.txt + +# Extract package names from requirements.txt, removing version specifiers +packages=$(cat requirements.txt | sed 's/==.*//' | sed 's/<.*//' | sed 's/>.*//' | tr '\n' ' ') + +# Upgrade all packages +pip3 install --upgrade $packages + +# Regenerate requirements.txt with the new versions +pip3 freeze > requirements.txt + +echo "Requirements updated successfully."