From f11dd091f1e908688583dee1158c596ee9a91407 Mon Sep 17 00:00:00 2001 From: ImAlpha Date: Thu, 8 Aug 2024 21:27:49 -0700 Subject: [PATCH] flask file upload working --- backend/.env | 4 + backend/__pycache__/config.cpython-312.pyc | Bin 0 -> 1600 bytes backend/__pycache__/models.cpython-312.pyc | Bin 0 -> 1964 bytes backend/config.py | 8 ++ backend/instance/mydatabase.db | Bin 0 -> 20480 bytes backend/main.py | 45 +++++-- backend/models.py | 34 ++++++ backend/requirements.txt | 5 +- backend/static/styles.css | 130 +++++++++++++++++++++ backend/templates/index.html | 18 +-- 10 files changed, 226 insertions(+), 18 deletions(-) create mode 100644 backend/.env create mode 100644 backend/__pycache__/config.cpython-312.pyc create mode 100644 backend/__pycache__/models.cpython-312.pyc create mode 100644 backend/instance/mydatabase.db create mode 100644 backend/models.py create mode 100644 backend/static/styles.css diff --git a/backend/.env b/backend/.env new file mode 100644 index 0000000..128b3a6 --- /dev/null +++ b/backend/.env @@ -0,0 +1,4 @@ +SECRET_KEY=MVPhXY*yNXPE2MbXDdpxXk +REDIS_PASSWORD=eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81 +POSTGRESQL_DATABASE_URL='postgresql+psycopg2://arufa:Plop2099@localhost:5432/arufalab' +# POSTGRESQL_DATABASE_URL => 'postgresql+psycopg2://arufa:password@host:port/database' \ No newline at end of file diff --git a/backend/__pycache__/config.cpython-312.pyc b/backend/__pycache__/config.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..30cb93779a45e26c0c83b8592d38d24f8637a1bf GIT binary patch literal 1600 zcmaJ>OHUhD6u#rfc>Ffx0g1to)Gf7=c%W&M2BAd89>Bra)MM1(&1mpk8=HA`#vs`% zqEsqUH=JeSL&FVX2cN)Eh*t0qN#1)CiAgzc<&=UasL@ zLqqs_%bl3|m$aU6Aoq$antRC8Fg3MaZ6zq=vL;G`q&1;> zkjI!_t{5%7i7gKgO|!14C2U_c_jO$}nx;@Opaj)sU6jrCg!zqJZ^A{EWtEmBHpLy$ zgh^=!O^{N#^cuIZEo4%q)N+dFgsozB1;vJxQZbcY7d8r+>`FGBDrF0K9)*W=F1=R3 zU32LoR}$8_ZREza>m~~D9M5BKp|ripp|Jtl|2+}&A zm_Y6-*^uGH84dC~KoN@&@K8m2O@^D$KAWy+hH21*pzUoL9s(R19*FI+V{Oi0Fl~g1 z7VIaq_h@(t#|VNdDo_xRQ`B`t+d+t~Xlk`yLmvDY)D2BVOx4g7Vc(FE11~gWLgN4$ zf@!Dv6}-i{z`J>NS5qJ>%KEOzuHsKYWcT2KX5JH<&AI{E9kH?pRf)BeC-v4lW=YYc zeHlJB5;y_*Cz)Y`Wwvlz+4YRdm#22cza;xH3;;;t#jIcwDv+fbe;j%A%EQb z3&hWW|J&f1H~fS1`{*HkL4(9Hb?E%g_uTi&AMb#VyX@x!c&7vIc4y-QIMo5u-RSho z#goOKUqeR!-M%B Dtwnp> literal 0 HcmV?d00001 diff --git a/backend/__pycache__/models.cpython-312.pyc b/backend/__pycache__/models.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cbe0aa102c784f62f9bb9a6577c385a4ef31c3dc GIT binary patch literal 1964 zcmb_cO-vhC5Pth-dyOgJ#(qc%VD(_E9Bhykr_QX64VJ4aQb*d^*?Hfa zoq6w@`K`MUfE&RqJxzTy&Fy}XVNTT zSZm8hV$yV(kyvF9GtM=`bxqC^^Txs|vuProq0DlwujRa;o6%RCjQw3t;|Q-e97rzb z3aC7J9qlh)E?uq-Ufk)~?x_u2C_gSeuEpZzR4MhBs`Q565Je3i0hUZ_5ig|s`RTeB z)^+$()?#2sbp1iru&@YS=XlUwU_4`G)3z6!vR$^sc)i-dJ(rvI67K^DkD|gtc?{Ig zg!iL;4i%oQukh%dN1!%HO^t3wi}6ByYovU$baQXCst)JJYJKOoqUCrgUP)F)c9Pr4 z-I=GipT%Cps(q9BuWP;WEwQYY)QVQQw4-fnyJJtUJyTvN)!vExR4o$Q94k&0rnbzj z`LbCuccmxx-rV!KYGgcr=SU7H;d)M(&Y6Bjp7?zF1dK9qn_Sz6ZTaXlviT8`8v|=3unu806M8`Pb#k+448axO! z_jct}E$qp24&yLoK|6;-fS=VQ9)venL3u&S7LBasn)l&WG{JXHz#B;q6y^hn97GjI zc(<;*I5bX?m!HSgi>QWBVWav)_2gN$?s}m$!*L#EIBmN?ehGo7kjc({P(a&r7xH&o z+)V;|lci*3=E?0n`h4`|U{##~7I$RgY&9~Hzf=g&ThpF#U}F0g+>Ng8%>k literal 0 HcmV?d00001 diff --git a/backend/config.py b/backend/config.py index aaf4a7d..c1ec7e4 100644 --- a/backend/config.py +++ b/backend/config.py @@ -21,8 +21,16 @@ app.config["SESSION_TYPE"] = 'redis' app.config["SESSION_PERMANENT"] = False app.config["SESSION_USE_SIGNER"] = True app.config["SESSION_REDIS"] = redis.from_url("redis://192.168.50.107:6379") +# upload directory +app.config["UPLOAD_DIRECTORY"] = 'uploads/' # app.config["REDIS_PASSWORD"] = os.environ["REDIS_PASSWORD"] +# File value limit +app.config["MAX_CONTENT_LENGTH"] = 16 * 1024 * 1024 # 16MB + +# List of allowed file extensions +app.config['ALLOWED_EXTENSIONS'] = ['.jpg', '.jpeg', '.png', '.gif'] + db = SQLAlchemy(app) server_session = Session(app) diff --git a/backend/instance/mydatabase.db b/backend/instance/mydatabase.db new file mode 100644 index 0000000000000000000000000000000000000000..5c49581550a1ae2fa18c02e33e722bcfd4f099c8 GIT binary patch literal 20480 zcmeI%%SyvQ6oBDLTW)AHH?<)0R>^zA{} zOtPF}n5v~s-83_+#*v|kpxg34 z!nbyO*KK-(sHf&l^^whz8dl8o-=#%Wnp}d{lOq`(YimY6uZ`}N#dEJ4dC$>!NX>bS zlVg!;-L+3`XKr^dK|hR|U9aPRlN|2NgSEZCD&|RxrG*6+1$A>X*~eD$pdo+&0tg_0 z00IagfB*srAb`NK3UL2l){|vl2q1s}0tg_000IagfB*srOa=5L', methods=['GET']) +def serve_image(filename): + return send_from_directory(app.config['UPLOAD_DIRECTORY'], filename) + # Main if __name__ == "__main__": diff --git a/backend/models.py b/backend/models.py new file mode 100644 index 0000000..0bc5b6f --- /dev/null +++ b/backend/models.py @@ -0,0 +1,34 @@ +from config import db +from uuid import uuid4 + +class Contact(db.Model): + id = db.Column(db.Integer, primary_key=True) + first_name = db.Column(db.String(80), unique=False, nullable=False) + last_name = db.Column(db.String(80), unique=False, nullable=False) + email = db.Column(db.String(120), unique=False, nullable=False) + + def to_json(self): + return { + "id": self.id, + "firstName":self.first_name, + "lastName":self.last_name, + "email": self.email, + } + + +def get_uuid(): + return uuid4().hex + +class User(db.Model): + __tablename__ = "users" + id = db.Column(db.String(32), primary_key=True, unique=True, default=get_uuid) + email = db.Column(db.String(345), unique=True) + password = db.Column(db.Text, nullable=False) + +# class Category(db.Model): +# __tablename__ = "categories" +# id = db.Column(db.String(32), primary_key=True, unique=True, default=get_uuid) +# name = db.Column(db.String(345), default='New Shirt') +# number = db.Column(db.Integer) +# sale = db.Column(db.Boolean, default=False) + \ No newline at end of file diff --git a/backend/requirements.txt b/backend/requirements.txt index ed950a5..352b66f 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -4,4 +4,7 @@ flask-bcrypt flask-cors python-dotenv flask-session -redis \ No newline at end of file +redis +Flask-Migrate +flask_validator +psycopg2-binary \ No newline at end of file diff --git a/backend/static/styles.css b/backend/static/styles.css new file mode 100644 index 0000000..c8da789 --- /dev/null +++ b/backend/static/styles.css @@ -0,0 +1,130 @@ +:root { + --black: #000000; + --almost-black: #080708; + --blue: #3772FF; + --blue-light: #3787ff; + --red: #DF2935; + --yellow: #FDCA40; + --light: #E6E8E6; + --white: #FFFFFF; + } + + * { + position: relative; + box-sizing: border-box; + } + + body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + font-size: 22px; + line-height: 1.5; + color: var(--white); + background: var(--black); + background-image: linear-gradient(to bottom right, var(--almost-black), var(--black)); + } + + .app { + height: 100vh; + display: flex; + } + + .form-section { + padding: 15px 0 0 15px; + width: 25%; + color: var(--light); + flex-shrink: 0; + } + + .images-section { + padding: 15px 0 0 15px; + width: 75%; + height: 100vh; + align-content: flex-start; + flex-wrap: wrap; + display: flex; + overflow-y: auto; + } + + .images-section a { + margin: 0 15px 15px 0; + padding-bottom: 20%; + content: ''; + width: calc(33.33% - 15px); + height: 0; + display: block; + } + + .images-section img { + position: absolute; + top: 0; + width: 100%; + height: 100%; + border-radius: 4px; + object-fit: cover; + display: block; + } + + @media screen and (max-width: 1200px) { + + .app { + flex-direction: column; + } + + .form-section { + padding-right: 15px; + padding-bottom: 15px; + width: 100%; + } + + .images-section { + padding-top: 0; + width: 100%; + height: auto; + } + } + + @media screen and (max-width: 800px) { + + .images-section a { + padding-bottom: 60%; + width: calc(100% - 15px); + } + } + + /* Forms */ + form { + width: 100%; + flex-direction: column; + display: flex; + } + + input[type='file'] { + margin: 0 0 12px; + padding: 10px 10px; + border-radius: 4px; + font-size: 22px; + color: var(--almost-black); + background: var(--white); + } + + input[type='submit'], + button[type='button'] { + padding: 13px 20px; + font-size: 22px; + font-weight: bold; + color: var(--white); + border: none; + border-radius: 4px; + outline: none; + box-shadow: none; + cursor: pointer; + background: var(--blue); + background-image: linear-gradient(to bottom, var(--blue-light), var(--blue)); + transition: box-shadow .2s ease; + } + + input[type='submit']:hover, + button[type='button']:hover { + box-shadow: inset 0 -25px 25px var(--blue-light); + } \ No newline at end of file diff --git a/backend/templates/index.html b/backend/templates/index.html index 9e73d78..a5bc31d 100644 --- a/backend/templates/index.html +++ b/backend/templates/index.html @@ -11,20 +11,20 @@
-
- - - -
- +
+ + +
- - - + {% for image in images %} + + + + {% endfor %}