diff --git a/app/campaigns/__pycache__/models.cpython-311.pyc b/app/campaigns/__pycache__/models.cpython-311.pyc index 5a3c834..cd2c166 100644 Binary files a/app/campaigns/__pycache__/models.cpython-311.pyc and b/app/campaigns/__pycache__/models.cpython-311.pyc differ diff --git a/app/campaigns/models.py b/app/campaigns/models.py index 692b2b2..4a52dd0 100644 --- a/app/campaigns/models.py +++ b/app/campaigns/models.py @@ -11,5 +11,8 @@ class Campaign(db.Model): __tablename__ = 'campaign' id = Column('id', INTEGER(), primary_key=True) title = Column('title', TEXT(), nullable=False) - donation_id = Column(INTEGER, ForeignKey('donation.id')) - #ambassadors \ No newline at end of file + donations = db.relationship('Donation', backref='campaign', lazy='dynamic') + + def __repr__(self) -> str: + return f"{self.id} - {self.title}" + # donation_id = Column(INTEGER, ForeignKey('donation.id')) \ No newline at end of file diff --git a/app/main/__pycache__/models.cpython-311.pyc b/app/main/__pycache__/models.cpython-311.pyc index 3a0cb34..6b9baef 100644 Binary files a/app/main/__pycache__/models.cpython-311.pyc and b/app/main/__pycache__/models.cpython-311.pyc differ diff --git a/app/main/models.py b/app/main/models.py index 659f4b9..55502fa 100644 --- a/app/main/models.py +++ b/app/main/models.py @@ -11,5 +11,11 @@ class Donation(db.Model): id = Column('id', INTEGER(), primary_key=True, autoincrement=True) currency_type = Column('currency_type', TEXT(), nullable=False) amount = Column('amount', INTEGER(), nullable=False) - campaign = db.relationship('Campaign', backref='donation', lazy='dynamic') - user = db.relationship('User', backref='donation', lazy='dynamic') \ No newline at end of file + + user_id = Column(INTEGER, ForeignKey('user.id')) + campaign_id = Column(INTEGER, ForeignKey('campaign.id')) + + def __repr__(self) -> str: + return f"{self.id} - {self.currency_type} - {self.amount}" + # campaign = db.relationship('Campaign', backref='donation', lazy='dynamic') + # user = db.relationship('User', backref='donation', lazy='dynamic') \ No newline at end of file diff --git a/app/main/templates/base.html b/app/main/templates/base.html index b10b24b..39f6888 100644 --- a/app/main/templates/base.html +++ b/app/main/templates/base.html @@ -13,19 +13,20 @@ {% with messages = get_flashed_messages(with_categories=true) %} diff --git a/app/users/__pycache__/models.cpython-311.pyc b/app/users/__pycache__/models.cpython-311.pyc index 1101129..442408e 100644 Binary files a/app/users/__pycache__/models.cpython-311.pyc and b/app/users/__pycache__/models.cpython-311.pyc differ diff --git a/app/users/__pycache__/routes.cpython-311.pyc b/app/users/__pycache__/routes.cpython-311.pyc index 416f3b3..d2f67ed 100644 Binary files a/app/users/__pycache__/routes.cpython-311.pyc and b/app/users/__pycache__/routes.cpython-311.pyc differ diff --git a/app/users/models.py b/app/users/models.py index c6cb877..cfecb44 100644 --- a/app/users/models.py +++ b/app/users/models.py @@ -14,7 +14,13 @@ class User(db.Model, UserMixin): email = Column('email', TEXT(), nullable=False, unique=True) password = Column('password', TEXT(), nullable=False) user_type = Column('user_type', TEXT(), nullable=False) - donation_id = Column(INTEGER, ForeignKey('donation.id')) + donations = db.relationship('Donation', backref='user', lazy='dynamic') + + + + def __repr__(self) -> str: + return f"{self.id} - {self.first_name} - {self.last_name}" + # donation_id = Column(INTEGER, ForeignKey('donation.id')) def get_reset_token(self, expiration=600): reset_token = jwt.encode( diff --git a/app/users/routes.py b/app/users/routes.py index 0afaa25..9ee9d9c 100644 --- a/app/users/routes.py +++ b/app/users/routes.py @@ -1,6 +1,8 @@ from app import db from app.users import users from app.users.models import User +from app.campaigns.models import Campaign +from app.main.models import Donation from app.users.forms import LoginForm, RegisterUserForm#, RequestResetForm, ResetPasswordForm, EditUserForm, AddUserForm from flask import render_template, redirect, url_for, flash, request from flask_login import login_required, login_user, current_user, logout_user @@ -66,4 +68,17 @@ def register_user(): login_user(user) flash('Succesfully Registered!') return redirect(url_for('main.homepage')) - return render_template('register_user.html', form=form) \ No newline at end of file + return render_template('register_user.html', form=form) + +@users.route('/test') +def testing_route(): + user = User.query.filter_by(id=1).first() + donation = Donation.query.filter_by(id=1).first() + campaign = Campaign.query.filter_by(id=1).first() + + print(campaign) + + return render_template('test.html', + user=user, + donation=donation, + campaign=campaign) \ No newline at end of file diff --git a/app/users/templates/test.html b/app/users/templates/test.html new file mode 100644 index 0000000..105670c --- /dev/null +++ b/app/users/templates/test.html @@ -0,0 +1,10 @@ +{% extends 'base.html' %} +{% block title %}User Access{% endblock title %} +{% block content %} +{{user.first_name}}
+{{donation.amount}}
+ +{% for c in campaign.donations %} +{{c}} +{% endfor %} +{% endblock %} \ No newline at end of file diff --git a/python_files/db_population.py b/python_files/db_population.py index e69de29..11ddeb3 100644 --- a/python_files/db_population.py +++ b/python_files/db_population.py @@ -0,0 +1,97 @@ +from sqlalchemy import create_engine, MetaData, Table, select, insert, func, update, bindparam, delete +import os +import csv +from datetime import datetime, timedelta +from dateutil.parser import parse +import time +import json +from werkzeug.security import generate_password_hash + + + +def insert_users(): + engine = create_engine('sqlite:///C:/Users/Lenovo/Desktop/Pilzno/instance/site.db') + metadata_obj = MetaData() + metadata_obj.reflect(bind=engine) + user_table = Table("user", metadata_obj, autoload_with=engine) + + with engine.connect() as conn: + conn.execute(user_table.insert().values( + first_name = "Yisroel", + last_name = "Baum", + email = "yisroel.d.baum@gmail.com", + password = generate_password_hash('12'), + user_type = "User" + )) + conn.execute(user_table.insert().values( + first_name = "Yoni", + last_name = "Gerzi", + email = "yoni@gerzi.com", + password = generate_password_hash('12'), + user_type = "User" + )) + conn.commit() + +def insert_donations(): + engine = create_engine('sqlite:///C:/Users/Lenovo/Desktop/Pilzno/instance/site.db') + metadata_obj = MetaData() + metadata_obj.reflect(bind=engine) + user_table = Table("user", metadata_obj, autoload_with=engine) + donation_table = Table("donation", metadata_obj, autoload_with=engine) + campaign_table = Table("campaign", metadata_obj, autoload_with=engine) + + with engine.connect() as conn: + sruli = conn.execute(select(user_table).where(user_table.c.id == 1)).first() + yoni = conn.execute(select(user_table).where(user_table.c.id == 2)).first() + + campaign_one = conn.execute(select(campaign_table).where(campaign_table.c.id == 2)).first() + + conn.execute(donation_table.insert().values( + currency_type = "shekel", + amount = 50, + campaign_id=campaign_one.id, + user_id=sruli.id + )) + conn.commit() + +def insert_campaigns(): + engine = create_engine('sqlite:///C:/Users/Lenovo/Desktop/Pilzno/instance/site.db') + metadata_obj = MetaData() + metadata_obj.reflect(bind=engine) + campaign_table = Table("campaign", metadata_obj, autoload_with=engine) + + with engine.connect() as conn: + conn.execute(campaign_table.insert().values(title="general campaign")) + conn.execute(campaign_table.insert().values(title="special campaign")) + conn.commit() + +def test_selections(): + engine = create_engine('sqlite:///C:/Users/Lenovo/Desktop/Pilzno/instance/site.db') + metadata_obj = MetaData() + metadata_obj.reflect(bind=engine) + user_table = Table("user", metadata_obj, autoload_with=engine) + donation_table = Table("donation", metadata_obj, autoload_with=engine) + campaign_table = Table("campaign", metadata_obj, autoload_with=engine) + + with engine.connect() as conn: + campaign_one = conn.execute(select(campaign_table).where(campaign_table.c.id==1)).first() + donation_one = conn.execute(select(donation_table).where(donation_table.c.id==1)).first() + user_one = conn.execute(select(user_table).where(user_table.c.id==1)).first() + print(user_one.donations) + +def delete_all(): + engine = create_engine('sqlite:///C:/Users/Lenovo/Desktop/Pilzno/instance/site.db') + metadata_obj = MetaData() + metadata_obj.reflect(bind=engine) + user_table = Table("user", metadata_obj, autoload_with=engine) + donation_table = Table("donation", metadata_obj, autoload_with=engine) + campaign_table = Table("campaign", metadata_obj, autoload_with=engine) + + with engine.connect() as conn: + conn.execute(delete(user_table)) + conn.execute(delete(campaign_table)) + conn.execute(delete(donation_table)) + conn.commit() + +if __name__ == '__main__': + test_selections()