diff options
author | Matt Arnold | 2025-04-11 01:33:39 -0400 |
---|---|---|
committer | Matt Arnold | 2025-04-11 01:33:39 -0400 |
commit | dc557895b1bd517bbdc2821a79f2be12624010d6 (patch) | |
tree | 39ad52fae6c5688720f36d608e001c994a76d96f | |
parent | c51aebd896459f65c675d719347f60fc3aefa781 (diff) |
Faccets phase 1 changes, to include
Add a view for a faccets details
-rw-r--r-- | app.py | 29 | ||||
-rw-r--r-- | models.py | 12 | ||||
-rw-r--r-- | static/style.css | 9 | ||||
-rw-r--r-- | template_filters.py | 10 | ||||
-rw-r--r-- | templates/details.html | 22 | ||||
-rw-r--r-- | templates/faccet_list.html | 12 | ||||
-rw-r--r-- | templates/post.html | 10 |
7 files changed, 97 insertions, 7 deletions
diff --git a/app.py b/app.py index 02c4693..a860060 100644 --- a/app.py +++ b/app.py @@ -4,7 +4,7 @@ from urllib.parse import urlparse as url_parse from flask import Flask, render_template, request, redirect, url_for, flash from markdown import markdown, Markdown from config import config -from models import Post, db, get_replies, Faccet, get_previous +from models import Post, db, get_replies, Faccet, get_previous, get_attribed_posts from models import User as NewUser from forms import PostForm, LoginForm from flask_login import ( @@ -14,6 +14,8 @@ from flask_login import ( current_user, LoginManager, ) +from template_filters import format_datetime + import os @@ -26,6 +28,7 @@ app.jinja_options = app.jinja_options.copy() app.jinja_env.add_extension(Markdown) app.jinja_env.filters["markdown"] = markdown +app.jinja_env.filters["datetime"] = format_datetime login = LoginManager(app) login.login_view = "login" @@ -105,5 +108,29 @@ def create(): return render_template("create.html", form=form) +@app.route("/details/<string:light>") +@login_required +def details(light): + cfaccet = Faccet.get(Faccet.name == light) + faccet_uctx = NewUser.get(NewUser.id == cfaccet.user_belongs) + fposts = get_attribed_posts(cfaccet.id) + + return render_template( + "details.html", faccet=cfaccet, creator=faccet_uctx, posts=fposts + ) + + +@app.route("/faccets") +@login_required +def faccets(): + userctx = NewUser.get(NewUser.username == current_user.username) + faccet_list = ( + Faccet.select() + .where(Faccet.user_belongs == userctx) + .order_by(Faccet.birth.asc()) + ) + return render_template("faccet_list.html", faccet=faccet_list) + + if __name__ == "__main__": app.run(debug=True, port=5052) diff --git a/models.py b/models.py index 4f76da7..6e5a5b0 100644 --- a/models.py +++ b/models.py @@ -32,6 +32,7 @@ class Faccet(BaseModel): name = TextField(unique=True) picture = BlobField() bio = TextField() + birth = DateTimeField(default=datetime.now) class Post(BaseModel): @@ -50,10 +51,17 @@ def get_replies(post_id): def get_previous(post_id): tlist = [] lp = Post.get(Post.id == post_id) - while lp.parent != 0: - tlist.append(lp) + while True: + if lp.parent == 0: + break + if lp.id != post_id: + tlist.append(lp) lp = Post.get(Post.id == lp.parent) return tlist +def get_attribed_posts(uid): + return Post.select().where(Post.authour == uid).order_by(Post.created_at.desc()) + + db.create_tables([User, Post, Faccet]) diff --git a/static/style.css b/static/style.css index affd975..97b98f4 100644 --- a/static/style.css +++ b/static/style.css @@ -122,4 +122,13 @@ footer { display: none; overflow: hidden; background-color: #f1f1f1; +} + +.container { + max-width: 800px; + margin: 0 auto; + padding: 20px; + background: rgba(255, 255, 255, 0.8); + border-radius: 10px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } \ No newline at end of file diff --git a/template_filters.py b/template_filters.py new file mode 100644 index 0000000..14db228 --- /dev/null +++ b/template_filters.py @@ -0,0 +1,10 @@ +import datetime + + +def format_datetime(value, format="%d %b %Y %I:%M %p"): + """Format a date time to (Default): d Mon YYYY HH:MM P""" + if value is None: + return "" + dt = datetime.datetime.fromtimestamp(value) + + return dt.strftime(format) diff --git a/templates/details.html b/templates/details.html new file mode 100644 index 0000000..3b16fe3 --- /dev/null +++ b/templates/details.html @@ -0,0 +1,22 @@ +{% extends 'base.html' %} + +{% block content %} +<div class="container"> + <h2>Details of {{faccet.name}}</h2> + <p> {{faccet.name}} is a part of <b> {{creator.username}} </b> and was born on {{faccet.birth|datetime('%m-%d-%Y')}} + </p> + <h3> Biographical or Reference Information</h3> + <p> {{faccet.bio}}</p> +</div> +<div class="container"> + <h3> Posts by {{faccet.name}}</h3> + + <ul> + {% for post in posts %} + <li><a href="{{ url_for('post', post_id=post.id) }}">{{ post.title }}</a> - {{ + post.created_at.strftime('%Y-%m-%d') }}</li> + {% endfor %} + </ul> + +</div> +{% endblock %} \ No newline at end of file diff --git a/templates/faccet_list.html b/templates/faccet_list.html new file mode 100644 index 0000000..226e684 --- /dev/null +++ b/templates/faccet_list.html @@ -0,0 +1,12 @@ +{% extends 'base.html' %} + +{% block content %} +<div class="container"> + <h2>Faccets of {{current_user.username}}</h2> + <ul> + {% for light in faccet %} + <li><a href="{{ url_for('details', light=light.name )}}">{{ light.name }}</a> </li> + {% endfor %} + </ul> +</div> +{% endblock %} \ No newline at end of file diff --git a/templates/post.html b/templates/post.html index 107b1a2..eef4c93 100644 --- a/templates/post.html +++ b/templates/post.html @@ -24,10 +24,12 @@ <a href="{{url_for('post', post_id=post.parent)}}"> Previous</a> <hr> {% endif %} -<h2>{{ post.title }}</h2> -<p>{{ post.created_at.strftime('%Y-%m-%d %H:%M') }}</p> -<p> Authour: {{post.authour.name}}</p> -<div>{{ post.content|markdown|safe }}</div> +<div class="container"> + <h2>{{ post.title }}</h2> + <p>{{ post.created_at.strftime('%Y-%m-%d %H:%M') }}</p> + <p> Authour: <a href="{{url_for('details', light=post.authour.name)}}"> {{post.authour.name}} </a></p> + <div>{{ post.content|markdown|safe }}</div> +</div> <div class="post-actions"> <a href="{{ url_for('create', reply=post.id)}}"> Reply</a> ~ <a href="{{ url_for('index') }}">Back to posts</a> |