From b36273a848e6dd1a7971283cb3134b6a1e5e39ee Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Tue, 2 Jul 2019 00:45:04 +0100 Subject: [PATCH] Add website and donation support --- app/flatpages/policy_and_guidance.md | 10 ++++---- app/models.py | 4 +++ app/templates/packages/view.html | 7 +++++ app/templates/users/user_profile_page.html | 25 +++++++++++++++--- app/views/users/users.py | 6 ++++- migrations/versions/d6ae9682c45f_.py | 30 ++++++++++++++++++++++ 6 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 migrations/versions/d6ae9682c45f_.py diff --git a/app/flatpages/policy_and_guidance.md b/app/flatpages/policy_and_guidance.md index 16de1db6..0fe110d7 100644 --- a/app/flatpages/policy_and_guidance.md +++ b/app/flatpages/policy_and_guidance.md @@ -125,15 +125,15 @@ Public domain is not a valid license in many countries, please use CC0 or MIT in ## 5. Promotions and Advertisements (inc. asking for donations) -Any information other than the long description - including screenshots - must -not contain any promotions or advertisements. This includes asking for donations, -promoting online shops, or linking to personal websites and social media. +You may note place any promotions or advertisements in any meta data including +screensthos. This includes asking for donations, promoting online shops, +or linking to personal websites and social media. Please instead use the +fields provided on your user profile page to place links to websites and +donation pages. ContentDB is for the community. We may remove any promotions if we feel that they're inappropriate. -Paid promotions are not allowed at all, anywhere. - ## 6. Reporting Violations diff --git a/app/models.py b/app/models.py index cecf7658..583c92a9 100644 --- a/app/models.py +++ b/app/models.py @@ -129,6 +129,10 @@ class User(db.Model, UserMixin): active = db.Column("is_active", db.Boolean, nullable=False, server_default="0") display_name = db.Column(db.String(100), nullable=False, server_default="") + # Links + website_url = db.Column(db.String(255), nullable=True, default=None) + donate_url = db.Column(db.String(255), nullable=True, default=None) + # Content notifications = db.relationship("Notification", primaryjoin="User.id==Notification.user_id") diff --git a/app/templates/packages/view.html b/app/templates/packages/view.html index b725dbea..8216c712 100644 --- a/app/templates/packages/view.html +++ b/app/templates/packages/view.html @@ -217,6 +217,13 @@ + {% if package.author.donate_url %} +
+ Like {{ package.author.display_name }}'s work? + Donate now! +
+ {% endif %} + {% if package.type == package.type.MOD %}
Dependencies
diff --git a/app/templates/users/user_profile_page.html b/app/templates/users/user_profile_page.html index 8fdca3fe..fc197e87 100644 --- a/app/templates/users/user_profile_page.html +++ b/app/templates/users/user_profile_page.html @@ -7,7 +7,7 @@ {% block content %} {% if not current_user.is_authenticated and user.rank == user.rank.NOT_JOINED and user.forums_username %} -
+
Claim @@ -40,7 +40,7 @@ - Accounts: + Links: {% if user.forums_username %} @@ -50,7 +50,7 @@ No forum account {% endif %} - {% if (user.forums_username and user.github_username) or user == current_user %} + {% if user.github_username or user == current_user %} | {% endif %} @@ -60,8 +60,16 @@ Link Github {% endif %} + {% if user.website_url %} + | Website + {% endif %} + {% if user == current_user %} - 🌎 +
+ + 🌎 + Visible to everyone + {% endif %} @@ -136,6 +144,8 @@ {% if user.checkPerm(current_user, "CHANGE_DNAME") %} {{ render_field(form.display_name, tabindex=230) }} + {{ render_field(form.website_url, tabindex=232) }} + {{ render_field(form.donate_url, tabindex=233) }} {% endif %} {% if user.checkPerm(current_user, "CHANGE_EMAIL") %} @@ -158,6 +168,13 @@ {% from "macros/packagegridtile.html" import render_pkggrid %} {{ render_pkggrid(packages, show_author=False) }} +{% if user.donate_url %} +
+ Like {{ user.display_name }}'s work? + Donate now! +
+{% endif %} + {% if current_user == user or (current_user.is_authenticated and current_user.rank.atLeast(current_user.rank.EDITOR)) %}
diff --git a/app/views/users/users.py b/app/views/users/users.py index 02def255..040950e7 100644 --- a/app/views/users/users.py +++ b/app/views/users/users.py @@ -32,6 +32,8 @@ from app.tasks.phpbbparser import getProfile class UserProfileForm(FlaskForm): display_name = StringField("Display name", [Optional(), Length(2, 20)]) email = StringField("Email", [Optional(), Email()]) + website_url = StringField("Website URL", [Optional(), URL()]) + donate_url = StringField("Donation URL", [Optional(), URL()]) rank = SelectField("Rank", [Optional()], choices=UserRank.choices(), coerce=UserRank.coerce, default=UserRank.NEW_MEMBER) submit = SubmitField("Save") @@ -60,6 +62,8 @@ def user_profile_page(username): # Copy form fields to user_profile fields if user.checkPerm(current_user, Permission.CHANGE_DNAME): user.display_name = form["display_name"].data + user.website_url = form["website_url"].data + user.donate_url = form["donate_url"].data if user.checkPerm(current_user, Permission.CHANGE_RANK): newRank = form["rank"].data @@ -74,7 +78,7 @@ def user_profile_page(username): token = randomString(32) ver = UserEmailVerification() - ver.user = user + ver.user = user ver.token = token ver.email = newEmail db.session.add(ver) diff --git a/migrations/versions/d6ae9682c45f_.py b/migrations/versions/d6ae9682c45f_.py new file mode 100644 index 00000000..7ab8de8a --- /dev/null +++ b/migrations/versions/d6ae9682c45f_.py @@ -0,0 +1,30 @@ +"""empty message + +Revision ID: d6ae9682c45f +Revises: 7ff57806ffd5 +Create Date: 2019-07-01 23:27:42.666877 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = 'd6ae9682c45f' +down_revision = '7ff57806ffd5' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('user', sa.Column('donate_url', sa.String(length=255), nullable=True)) + op.add_column('user', sa.Column('website_url', sa.String(length=255), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('user', 'website_url') + op.drop_column('user', 'donate_url') + # ### end Alembic commands ###