From 6428dd08c54a382f4765ad9065800b09d925d962 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 11 Jul 2022 18:46:08 +0200 Subject: [PATCH] add pronouns --- files/classes/user.py | 1 + files/helpers/regex.py | 2 ++ files/routes/settings.py | 20 ++++++++++++++++++++ files/templates/comments.html | 3 +++ files/templates/settings_profile.html | 19 +++++++++++++++++++ files/templates/submission.html | 3 +++ files/templates/submission_listing.html | 3 +++ files/templates/util/assetcache.html | 2 +- sql/20220711-pronouns.sql | 2 ++ 9 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 sql/20220711-pronouns.sql diff --git a/files/classes/user.py b/files/classes/user.py index ad28b757a..59782e57b 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -129,6 +129,7 @@ class User(Base): total_held_lottery_tickets = Column(Integer, default=0) total_lottery_winnings = Column(Integer, default=0) last_viewed_post_notifs = Column(Integer, default=0) + pronouns = Column(String, default='they/them') badges = relationship("Badge", order_by="Badge.created_utc", back_populates="user") subscriptions = relationship("Subscription", back_populates="user") diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 10a5fc242..bbb92d140 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -101,6 +101,8 @@ search_token_regex = re.compile('"([^"]*)"|(\S+)', flags=re.A) git_regex = re.compile("ref: (refs/.+)", flags=re.A) +pronouns_regex = re.compile("[a-z]{1-5}\/[a-z]{1-5}", flags=re.A) + def sub_matcher(match, upper=False): if match.group(0).startswith('<'): return match.group(0) diff --git a/files/routes/settings.py b/files/routes/settings.py index 97f01bdf9..f3fe6572c 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -880,6 +880,26 @@ def settings_title_change(v): return redirect("/settings/profile") +@app.post("/settings/pronouns_change") +@limiter.limit("1/second;30/minute;200/hour;1000/day") +@limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{request.host}-{session.get("lo_user")}') +@auth_required +def settings_pronouns_change(v): + + pronouns = request.values.get("pronouns").replace("𒐪","").lower().strip() + + if pronouns == v.pronouns: + return render_template("settings_profile.html", v=v, error="You didn't change anything") + + if not pronouns_regex.fullmatch(pronouns): + return render_template("settings_profile.html", v=v, error="The pronouns you entered don't match the required format {1-5 characters}/{1-5 characters}") + + v.pronouns = pronouns + g.db.add(v) + + return redirect("/settings/profile") + + @app.post("/settings/checkmark_text") @limiter.limit("1/second;30/minute;200/hour;1000/day") @limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{request.host}-{session.get("lo_user")}') diff --git a/files/templates/comments.html b/files/templates/comments.html index fc0bdee93..e9e7fcad4 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -206,6 +206,9 @@ {% endif %} {{c.author_name}} + {% if SITE_NAME == 'rDrama' %} + {{c.author.pronouns}} + {% endif %} {% if c.author.customtitle %}   {{c.author.customtitle | safe}} {% endif %} diff --git a/files/templates/settings_profile.html b/files/templates/settings_profile.html index bcddeb366..1a2da7193 100644 --- a/files/templates/settings_profile.html +++ b/files/templates/settings_profile.html @@ -458,6 +458,25 @@ + +
+ + + +
+
+ + +
+ {1-5 characters} / {1-5 characters} + +
+
+
+ +
+ +
diff --git a/files/templates/submission.html b/files/templates/submission.html index 24745b2ba..a1af5757e 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -676,6 +676,9 @@ {% endif %} {{p.author_name}} + {% if SITE_NAME == 'rDrama' %} + {{p.author.pronouns}} + {% endif %} {% if p.author.customtitle %}   {{p.author.customtitle | safe}} {% endif %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index dc4abf869..da8e777ff 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -207,6 +207,9 @@ {% endif %} {{p.author_name}} + {% if SITE_NAME == 'rDrama' %} + {{p.author.pronouns}} + {% endif %} {% if p.author.customtitle %}   {{p.author.customtitle | safe}} {% endif %} diff --git a/files/templates/util/assetcache.html b/files/templates/util/assetcache.html index 0637d5f3c..7b57e44a4 100644 --- a/files/templates/util/assetcache.html +++ b/files/templates/util/assetcache.html @@ -1,6 +1,6 @@ {%- set CACHE_VER = { - 'css/main.css': 385, + 'css/main.css': 386, 'css/4chan.css': 61, 'css/classic.css': 61, diff --git a/sql/20220711-pronouns.sql b/sql/20220711-pronouns.sql new file mode 100644 index 000000000..22d3d68f5 --- /dev/null +++ b/sql/20220711-pronouns.sql @@ -0,0 +1,2 @@ +alter table users add column pronouns varchar(11) not null default 'they/them'; +alter table users alter column pronouns drop default;