diff --git a/files/classes/user.py b/files/classes/user.py index ad28b757aa..59782e57ba 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 10a5fc242e..bbb92d140e 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 97f01bdf99..f3fe6572cd 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 fc0bdee933..e9e7fcad41 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 bcddeb366c..1a2da7193c 100644 --- a/files/templates/settings_profile.html +++ b/files/templates/settings_profile.html @@ -458,6 +458,25 @@ + +