From 417fc05d293f0d0209826ee77d45104287b81596 Mon Sep 17 00:00:00 2001 From: Lephe Date: Thu, 16 Jun 2022 17:00:59 +0100 Subject: [PATCH] program: add metadata and a basic model for events (#114) This commit adds most of the optional metadata for programs. The event related to the program's publication is an actual relationship to an Event model. The idea is to expand on that model in the future to include: - A link to the event's main topic - List of programs published in the event - Possibly, a list of all related topics (announcement, start, results, etc) all sharing a common 1-line header so they are linked together - This would be used for event-related trophies - And possibly for an event calendar --- app/models/__init__.py | 1 + app/models/event.py | 11 +++ app/models/program.py | 17 ++++- app/templates/programs/index.html | 11 ++- app/templates/programs/program.html | 72 ++----------------- ...59_add_program_metadata_and_a_base_for_.py | 48 +++++++++++++ 6 files changed, 89 insertions(+), 71 deletions(-) create mode 100644 app/models/event.py create mode 100644 migrations/versions/ba47de949e59_add_program_metadata_and_a_base_for_.py diff --git a/app/models/__init__.py b/app/models/__init__.py index 58c31dd..1337ad3 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -5,3 +5,4 @@ from app.models.topic import Topic from app.models.notification import Notification from app.models.program import Program from app.models.tag import Tag +from app.models.event import Event diff --git a/app/models/event.py b/app/models/event.py new file mode 100644 index 0000000..ddfb17b --- /dev/null +++ b/app/models/event.py @@ -0,0 +1,11 @@ +from app import db + +class Event(db.Model): + __tablename__ = 'event' + id = db.Column(db.Integer, primary_key=True) + + # Pretty event name, eg. "CPC #28" + name = db.Column(db.Unicode(128)) + + # Main topic, used to automatically insert links + main_topic = db.Column(db.Integer, db.ForeignKey('topic.id')) diff --git a/app/models/program.py b/app/models/program.py index 46aef41..02a2dfd 100644 --- a/app/models/program.py +++ b/app/models/program.py @@ -10,10 +10,21 @@ class Program(Post): # Program name name = db.Column(db.Unicode(128)) + # Author, when different from the poster + real_author = db.Column(db.Unicode(128)) + # Version + version = db.Column(db.Unicode(64)) + # Approximate size as indicated by poster + size = db.Column(db.Unicode(64)) + # License identifier + license = db.Column(db.String(32)) - # TODO: Category (games/utilities/lessons) - # TODO: Compatible calculator models - # TODO: Number of views, statistics, etc + # Label de qualité + label = db.Column(db.Boolean, nullable=False, server_default="FALSE") + # Event for which the program was posted + event = db.Column(db.Integer, db.ForeignKey('event.id'), nullable=True) + + # TODO: Number of views and downloads # Thread with the program description (top comment) and comments thread_id = db.Column(db.Integer,db.ForeignKey('thread.id'),nullable=False) diff --git a/app/templates/programs/index.html b/app/templates/programs/index.html index 29ec171..7f888f6 100644 --- a/app/templates/programs/index.html +++ b/app/templates/programs/index.html @@ -17,12 +17,19 @@

Tous les programmes

- + {% for p in programs %} - + +
IDNomAuteurPublié leProgrankTags
IDNomAuteurLabelProgrankTags
{{ p.id }} {{ p.name }}{{ p.author.name }} + {%- if p.real_author -%} + {{ p.real_author }} (posté par {{ p.author.name }}) + {%- else -%} + {{ p.author.name }} + {%- endif -%} + {{ p.date_created | dyndate }}{{ "Oui" if p.label else "Non" }} {{ p.progrank }} {%- for tag in p.tags %} diff --git a/app/templates/programs/program.html b/app/templates/programs/program.html index 2c83c47..207ad02 100644 --- a/app/templates/programs/program.html +++ b/app/templates/programs/program.html @@ -12,78 +12,18 @@ {% block content %}
-
-
- {{ widget_user.profile(p.author) }} -
-
-
- {{ p.title }} -
-
-

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae - feugiat ante. Pellentesque luctus lorem tincidunt vestibulum condimentum. - Nullam sed tempus sem. Phasellus quis diam vitae sapien luctus consequat - ac eget lacus. Sed rutrum condimentum sagittis. Nullam erat nibh, euismod - ac metus at, consequat tincidunt ipsum. Fusce sagittis iaculis orci sedporta. - Etiam bibendum purus et ipsum pellentesque, quis sodales libero congue. Nunc - lectus quam, cursus non dictum nec, volutpat eget felis. Praesent sollicitudin - massa erat, nec venenatis lorem lacinia et. Etiam ullamcorper neque quis - nisi sodales vulputate. Integer scelerisque luctus arcu, ut elementum justo - auctor a. Praesent sit amet libero risus.

- - - -

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae - feugiat ante. Pellentesque luctus lorem tincidunt vestibulum condimentum. - Nullam sed tempus sem. Phasellus quis diam vitae sapien luctus consequat - ac eget lacus. Sed rutrum condimentum sagittis. Nullam erat nibh, euismod - ac metus at, consequat tincidunt ipsum. Fusce sagittis iaculis orci sedporta. - Etiam bibendum purus et ipsum pellentesque, quis sodales libero congue. Nunc - lectus quam, cursus non dictum nec, volutpat eget felis. Praesent sollicitudin - massa erat, nec venenatis lorem lacinia et. Etiam ullamcorper neque quis - nisi sodales vulputate. Integer scelerisque luctus arcu, ut elementum justo - auctor a. Praesent sit amet libero risus.

- - - -

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae - feugiat ante. Pellentesque luctus lorem tincidunt vestibulum condimentum. - Nullam sed tempus sem. Phasellus quis diam vitae sapien luctus consequat - ac eget lacus. Sed rutrum condimentum sagittis. Nullam erat nibh, euismod - ac metus at, consequat tincidunt ipsum. Fusce sagittis iaculis orci sedporta. - Etiam bibendum purus et ipsum pellentesque, quis sodales libero congue. Nunc - lectus quam, cursus non dictum nec, volutpat eget felis. Praesent sollicitudin - massa erat, nec venenatis lorem lacinia et. Etiam ullamcorper neque quis - nisi sodales vulputate. Integer scelerisque luctus arcu, ut elementum justo - auctor a. Praesent sit amet libero risus.

-
- {% if p.thread.top_comment %} {% call widget_thread.thread_leader(p.thread.top_comment) %}
Posté le {{ p.date_created | dyndate }}
{{ widget_thread.post_actions(p) }}
+

{{ p.name }}

+ + Infos infos infos + +
+ {{ p.thread.top_comment.text | md }} {{ widget_attachments.attachments(p.thread.top_comment) }} {% endcall %} diff --git a/migrations/versions/ba47de949e59_add_program_metadata_and_a_base_for_.py b/migrations/versions/ba47de949e59_add_program_metadata_and_a_base_for_.py new file mode 100644 index 0000000..8a2cc50 --- /dev/null +++ b/migrations/versions/ba47de949e59_add_program_metadata_and_a_base_for_.py @@ -0,0 +1,48 @@ +"""add program metadata and a base for events + +Revision ID: ba47de949e59 +Revises: daa5d5913ef8 +Create Date: 2022-06-16 12:05:40.797694 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'ba47de949e59' +down_revision = 'daa5d5913ef8' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('event', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('name', sa.Unicode(length=128), nullable=True), + sa.Column('main_topic', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['main_topic'], ['topic.id'], ), + sa.PrimaryKeyConstraint('id') + ) + op.add_column('program', sa.Column('real_author', sa.Unicode(length=128), nullable=True)) + op.add_column('program', sa.Column('version', sa.Unicode(length=64), nullable=True)) + op.add_column('program', sa.Column('size', sa.Unicode(length=64), nullable=True)) + op.add_column('program', sa.Column('license', sa.String(length=32), nullable=True)) + op.add_column('program', sa.Column('label', sa.Boolean(), server_default='FALSE', nullable=False)) + op.add_column('program', sa.Column('event', sa.Integer(), nullable=True)) + op.create_foreign_key(None, 'program', 'event', ['event'], ['id']) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'program', type_='foreignkey') + op.drop_column('program', 'event') + op.drop_column('program', 'label') + op.drop_column('program', 'license') + op.drop_column('program', 'size') + op.drop_column('program', 'version') + op.drop_column('program', 'real_author') + op.drop_table('event') + # ### end Alembic commands ###