diff options
author | Matt Arnold | 2025-04-15 09:58:58 -0400 |
---|---|---|
committer | Matt Arnold | 2025-04-15 09:58:58 -0400 |
commit | e8880e73a23571acf47845b1e38292239c5d71b2 (patch) | |
tree | 0f12139f68f7dd99646d257bc3519744ba5b2f2e | |
parent | dc557895b1bd517bbdc2821a79f2be12624010d6 (diff) |
finally got different profiles/faccets to work.
Unsure if it was just the typo in the template or we really needed backend changes but belt and suspenders logic applies
-rw-r--r-- | app.py | 24 | ||||
-rw-r--r-- | forms.py | 17 | ||||
-rw-r--r-- | static/style.css | 18 | ||||
-rw-r--r-- | template_filters.py | 8 | ||||
-rw-r--r-- | templates/create.html | 5 | ||||
-rw-r--r-- | templates/post.html | 11 |
6 files changed, 71 insertions, 12 deletions
diff --git a/app.py b/app.py index a860060..d5b0c8c 100644 --- a/app.py +++ b/app.py @@ -14,7 +14,7 @@ from flask_login import ( current_user, LoginManager, ) -from template_filters import format_datetime +from template_filters import format_datetime, svsbbcode import os @@ -27,7 +27,7 @@ app.config["SECRET_KEY"] = SECRET_KEY app.jinja_options = app.jinja_options.copy() app.jinja_env.add_extension(Markdown) app.jinja_env.filters["markdown"] = markdown - +app.jinja_env.filters["bbcode"] = svsbbcode app.jinja_env.filters["datetime"] = format_datetime login = LoginManager(app) login.login_view = "login" @@ -93,19 +93,31 @@ def post(post_id): @app.route("/create", methods=["GET", "POST"]) @login_required def create(): - form = PostForm() replyto = request.args.get("reply", 0) userctx = NewUser.get(NewUser.username == current_user.username) - asfaccet = Faccet.get(Faccet.name == userctx.default_faccet) + + asfaccet = ( + Faccet.select() + .where(Faccet.user_belongs == userctx) + .order_by(Faccet.birth.asc()) + ) + form = PostForm(faccets=asfaccet) + + if request.method == "GET": + return render_template("create.html", form=form) + if form.validate_on_submit(): Post.create( title=form.title.data, content=form.content.data, - authour=asfaccet, + authour=form.faccets.data, parent=replyto, ) return redirect(url_for("index")) - return render_template("create.html", form=form) + else: + return str(form.faccets.data), 504 + + return "you shouldn't be here", 420 @app.route("/details/<string:light>") diff --git a/forms.py b/forms.py index be0171a..ba427cd 100644 --- a/forms.py +++ b/forms.py @@ -1,13 +1,28 @@ from flask_wtf import FlaskForm -from wtforms import StringField, TextAreaField, SubmitField, PasswordField, BooleanField +from wtforms import ( + StringField, + TextAreaField, + SubmitField, + PasswordField, + BooleanField, + SelectField, +) from wtforms.validators import DataRequired class PostForm(FlaskForm): title = StringField("Title", validators=[DataRequired()]) content = TextAreaField("Content", validators=[DataRequired()]) + faccets = SelectField("Faccet", coerce=int) submit = SubmitField("Toot!") + def __init__(self, *args, **kwargs): + super(PostForm, self).__init__(*args, **kwargs) + # Populate the select field with profile from the database + self.faccets.choices = [(0, "Please select a profile")] + [ + (u.id, u.name) for u in kwargs["faccets"] + ] + class LoginForm(FlaskForm): """Login Form""" diff --git a/static/style.css b/static/style.css index 97b98f4..1868c63 100644 --- a/static/style.css +++ b/static/style.css @@ -131,4 +131,22 @@ footer { background: rgba(255, 255, 255, 0.8); border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + display: flex +} + +.userbox { + /* Optional: control width */ + width: 200px; + border-top: 2px solid #fff; + border-left: 2px solid #fff; + border-right: 2px solid #888; + border-bottom: 2px solid #888; + padding: 10px; +} + +.post-content { + /* Optional: make this div fill remaining space */ + margin-left: 20px; + padding-right: 15%; + flex: 1; } \ No newline at end of file diff --git a/template_filters.py b/template_filters.py index 14db228..70e29ed 100644 --- a/template_filters.py +++ b/template_filters.py @@ -1,4 +1,6 @@ import datetime +import bbcode +from jinja2 import pass_environment def format_datetime(value, format="%d %b %Y %I:%M %p"): @@ -8,3 +10,9 @@ def format_datetime(value, format="%d %b %Y %I:%M %p"): dt = datetime.datetime.fromtimestamp(value) return dt.strftime(format) + + +@pass_environment +def svsbbcode(env, value): + # for now just return the default + return bbcode.render_html(value) diff --git a/templates/create.html b/templates/create.html index ccbbc67..8c4ee84 100644 --- a/templates/create.html +++ b/templates/create.html @@ -10,7 +10,6 @@ <h1>Write to yourself </h1> - <div class="tab"> <button type="button" class="tablinks" id="defaultOpen" onclick="openTab(event, 'input-area')">Editor</button> <button type="button" class="tablinks" onclick="openTab(event, 'document-rendered')">Preview</button> @@ -18,7 +17,11 @@ <!-- Textarea for Markdown input --> <div id="input-area" class="tabcontent"> <form method="post" novalidate> + {{ form.hidden_tag() }} + <label for="faccets"> {{form.faccets.label}} </label> + {{form.faccets|safe}} + <p> {{form.title.label}}: {{form.title}} <br> {{ form.content.label }}<br> diff --git a/templates/post.html b/templates/post.html index eef4c93..4d37ed9 100644 --- a/templates/post.html +++ b/templates/post.html @@ -24,11 +24,14 @@ <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> + <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 class="userbox"> + <p> Authour: <a href="{{url_for('details', light=post.authour.name)}}"> {{post.authour.name}} </a></p> + </div> + <div class="post-content">{{ post.content|markdown|safe }}</div> </div> <div class="post-actions"> <a href="{{ url_for('create', reply=post.id)}}"> Reply</a> ~ |