Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
c0r2eX authored Jan 17, 2025
1 parent fa1096c commit b167630
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 68 deletions.
4 changes: 2 additions & 2 deletions create_Db.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ext import nag, db
from modelebi import Meme , User
from modelebi import Meme , User , Comment

with nag.app_context():


db.create_all()
Binary file modified instance/database.db
Binary file not shown.
17 changes: 16 additions & 1 deletion modelebi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask_login import LoginManager , UserMixin
from ext import db , login_manager
from werkzeug.security import generate_password_hash, check_password_hash
from datetime import datetime

class Meme(db.Model):
id = db.Column(db.Integer, primary_key=True)
Expand Down Expand Up @@ -54,10 +55,24 @@ class Vote(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
meme_id = db.Column(db.Integer, db.ForeignKey('meme.id'), nullable=False)
vote_type = db.Column(db.String(10), nullable=False) # 'upvote' or 'downvote'
vote_type = db.Column(db.String(10), nullable=False)


user = db.relationship('User', backref=db.backref('votes', lazy=True))
meme = db.relationship('Meme', backref=db.backref('votes', lazy=True))

def __repr__(self):
return f"<Vote user={self.user_id} meme={self.meme_id} type={self.vote_type}>"




class Comment(db.Model):
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.Text, nullable=False)
timestamp = db.Column(db.DateTime, default=datetime.utcnow)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
meme_id = db.Column(db.Integer, db.ForeignKey('meme.id'), nullable=False)

user = db.relationship('User', backref='comments')
meme = db.relationship('Meme', backref='comments')
2 changes: 1 addition & 1 deletion nag.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


from ext import nag, db
from routes import index, register, login, logout, profile, profilelist, aboutme, create, edit, upvote, downvote, delete_meme
from routes import index, register, login,users, logout, Comment, profile, profilelist, aboutme, create, edit, upvote, downvote, delete_meme


nag.run(host="0.0.0.0", debug=True)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Flask-WTF
email_validator
Flask-SQLAlchemy
Flask-Login
gunicorn
gunicorn
19 changes: 17 additions & 2 deletions routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from os import path
from uuid import uuid4
from ext import nag, db
from modelebi import Meme , User , Vote
from modelebi import Meme , User , Vote , Comment
from flask_login import login_user , logout_user , current_user , login_required

from datetime import datetime

users = {
"Dachi": {"name": "Dachi", "age": 38, "role": "Admin", "gender": "Male", "image": "drak.jpg"},
Expand Down Expand Up @@ -141,6 +141,19 @@ def edit(meme_id):



@nag.route('/add_comment/<int:meme_id>', methods=['POST'])
def add_comment(meme_id):
content = request.form['comment']
if not content:
flash('Comment cannot be empty', category='error')
return redirect(url_for('index'))

new_comment = Comment(content=content, meme_id=meme_id, user_id=current_user.id, timestamp=datetime.now())
db.session.add(new_comment)
db.session.commit()
flash('Comment added successfully', category='success')
return redirect(url_for('index'))



@nag.route("/upvote/<int:meme_id>", methods=["POST"])
Expand Down Expand Up @@ -169,6 +182,8 @@ def downvote(meme_id):





@nag.route("/delete_product/<int:meme_id>", methods=["POST" , "GET"])
def delete_meme(meme_id):
meme = Meme.query.get(meme_id)
Expand Down
Binary file added static/416d659a-764b-475e-911a-4a83961656ff.mp4
Binary file not shown.
Binary file not shown.
29 changes: 16 additions & 13 deletions templates/dynamic.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@

{% include "base.html" %}

<body style="background-image: url('/static/prf.jpg'); background-size: cover; background-position: center;">
{% include "navbar.html" %}
<div class="card d-flex align-items-center position-absolute top-50 start-50 translate-middle"
style="width: 20rem; background-color: rgba(90, 75, 122, 0.8); border-radius: 15px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);">
<body style="background-image: url('/static/prf.jpg'); background-size: cover; background-position: center;">
{% include "navbar.html" %}

<div class="d-flex flex-wrap justify-content-center gap-4 mt-5">
{% for user in users %}
<div class="card d-flex align-items-center" style="width: 20rem; background-color: rgba(90, 75, 122, 0.8); border-radius: 15px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6); margin-bottom: 20px;">

<div class="card-body text-center">
<img src="/static/{{ found_user['image'] }}" alt="Profile Picture" class="img-fluid rounded-circle mb-3" style="width: 120px; height: 120px; object-fit: cover; border: 2px solid #d1b3ff;" />

<img src="/static/{{ user['image'] }}" alt="Profile Picture" class="img-fluid rounded-circle mb-3" style="width: 120px; height: 120px; object-fit: cover; border: 2px solid #d1b3ff;" />
<h1 class="fs-3 text-light">
Name: {{ found_user['name'] }}
{% if found_user['role'] == "Admin" %}
Name: {{ user['name'] }}
{% if user['role'] == "Admin" %}
<span class="fs-6 badge rounded-pill text-bg-danger">Admin</span>
{% elif found_user['role'] == "Moderator" %}
{% elif user['role'] == "Moderator" %}
<span class="badge rounded-pill text-bg-primary" style="font-size: 14px; padding: 2% 0.4rem;">Moderator</span>
{% else %}
<span class="badge rounded-pill text-bg-success">User</span>
{% endif %}
</h1>

<p class="text-light">Gender: {{ found_user['gender'] }}</p>
<p class="text-light">Age: {{ found_user['age'] }}</p>
<p class="text-light">Gender: {{ user['gender'] }}</p>
<p class="text-light">Age: {{ user['age'] }}</p>
</div>
</div>
</body>
{% endfor %}
</div>
</body>
</html>
18 changes: 18 additions & 0 deletions templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
border-color: #1F0EB4;
border-radius: 40px;
}

.text-grey {
color: grey;
font-size: 14px;
}

.register-link {
text-decoration: none;
color: #8e44ad;
}

.register-link:hover {
text-decoration: underline;
}
</style>
</head>
<body style="background-image: url(/static/niganiga.jpg); background-size: cover; overflow: hidden;">
Expand All @@ -55,6 +69,10 @@ <h2 class="text-center mb-4">Login</h2>
</div>
<button type="submit" class="btn btn-purple w-100">{{ form.login_submit.label.text }}</button>
</form>

<div class="text-center mt-3">
<p class="text-grey">Don't have an account? <a href="{{ url_for('register') }}" class="register-link">Register here</a></p>
</div>
</div>
</div>

Expand Down
90 changes: 63 additions & 27 deletions templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div
class="card"
style="
width: 20rem;
width: 22rem;
background-color: #5a4b7a;
border-radius: 15px;
box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.4);
Expand All @@ -36,49 +36,85 @@
src="{{ url_for('static', filename=meme.img) }}"
alt="Meme image"
class="img-fluid rounded"
style="height: 200px; object-fit: cover"
style="height: 250px; object-fit: cover"
/>
{% elif meme.video %}
<video
controls
loop
autoplay
class="img-fluid rounded"
style="height: 200px; object-fit: cover"
style="height: 250px; object-fit: cover"
>
<source
src="{{ url_for('static', filename=meme.video) }}"
type="video/mp4"
/>
Your browser does not support the video tag.
</video>
{% endif %}
<h3
class="mt-3"
style="font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-weight: bold;
class="mt-3"
style="font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-weight: bold;
color: {{ meme.text_color | default('black') }};"
>
>
{{ meme.text }}
</h3>

<div class="d-flex justify-content-around align-items-center mt-3">
<form action="{{ url_for('upvote', meme_id=meme.id) }}" method="POST">
<button type="submit" class="btn btn-outline-success">
👍
</button>
<span class="text-success d-block mt-1">Likes: {{ meme.upvotes }}</span>
</form>

<form action="{{ url_for('downvote', meme_id=meme.id) }}" method="POST">
<button type="submit" class="btn btn-outline-danger">
👎
</button>
<span class="text-danger d-block mt-1">Dislikes: {{ meme.downvotes }}</span>
</form>
</div>



</h3>

<div class="d-flex justify-content-around align-items-center mt-3">
<form action="{{ url_for('upvote', meme_id=meme.id) }}" method="POST">
<button type="submit" class="btn btn-outline-success">
👍
</button>
<span class="text-success d-block mt-1">Likes: {{ meme.upvotes }}</span>
</form>

<form action="{{ url_for('downvote', meme_id=meme.id) }}" method="POST">
<button type="submit" class="btn btn-outline-danger">
👎
</button>
<span class="text-danger d-block mt-1">Dislikes: {{ meme.downvotes }}</span>
</form>
</div>

<div class="dropdown mt-3">
<button
class="btn btn-secondary dropdown-toggle"
type="button"
id="dropdownMenuButton"
data-bs-toggle="dropdown"
aria-expanded="false"
>
Comments
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<li>
<form action="{{ url_for('add_comment', meme_id=meme.id) }}" method="POST" class="px-3">
<div class="input-group">
<input
type="text"
name="comment"
class="form-control"
placeholder="Add a comment"
required
/>
<button type="submit" class="btn btn-primary">Send</button>
</div>
</form>
</li>
<li><hr class="dropdown-divider" /></li>
{% for comment in meme.comments %}
<li>
<div class="px-3">
<p>{{ comment.content }}</p>
<small style="color: #000000; margin-top: -5px; display: block;">
By {{ comment.user.username }}<span> on {{ comment.timestamp.strftime('%Y-%m-%d %H:%M:%S') }}
</span> </small>
</div>
</li>
{% endfor %}
</ul>
</div>

{% if current_user.is_authenticated and current_user.username == 'admin_user' %}
<div class="d-flex justify-content-around mt-3">
<a
Expand Down
Loading

0 comments on commit b167630

Please sign in to comment.