Skip to content

Commit

Permalink
feat: allow to provide a markdown description for team
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Feb 19, 2024
1 parent c5c938a commit 9ba4257
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 42 deletions.
29 changes: 29 additions & 0 deletions alembic/versions/aa8f047f7e49_add_a_description_to_team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
"""add a description to team
Revision ID: aa8f047f7e49
Revises: 2947cd9d37a5
Create Date: 2024-02-19 21:09:57.683065
"""
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "aa8f047f7e49"
down_revision = "2947cd9d37a5"
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("team", sa.Column("description", sa.Text(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("team", "description")
# ### end Alembic commands ###
4 changes: 3 additions & 1 deletion backend/models/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import datetime
from typing import List, Optional

from sqlalchemy import ForeignKey, Integer, String
from sqlalchemy import ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship

from ..database import Base
Expand Down Expand Up @@ -50,6 +50,8 @@ class Team(Base):
)
name: Mapped[str] = mapped_column(String(32))
headline: Mapped[str] = mapped_column(String(64), default="", nullable=True)
# markdown description
description: Mapped[str] = mapped_column(Text, default="", nullable=True)
created_at: Mapped[datetime] = mapped_column(default=datetime.utcnow)

owner_permissions: Mapped[int] = mapped_column(
Expand Down
19 changes: 19 additions & 0 deletions backend/routes/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,25 @@ async def update_team_headline(
)


@router.post("/{team_name}/description", response_class=PlainTextResponse)
async def update_team_description(
request: Request,
description: str = Form(default=""),
team: Team = Depends(get_team),
user: User = Depends(require_user),
db: Session = Depends(get_session),
):
team_repo = TeamRepo(db)
if not team.user_id == user.id:
return """<p id="validate-team-name" class="help is-danger">You cannot update the description!</p>"""
if len(description) > 63:
return (
"""<p id="validate-team-name" class="help is-danger">Max length 63!</p>"""
)
team_repo.update(team, description=description)
return """<p id="validate-team-name" class="help is-success">description updated!</p>"""


@router.post("/{team_name}/toggle/hide", response_class=PlainTextResponse)
async def update_team_hide(
request: Request,
Expand Down
7 changes: 1 addition & 6 deletions backend/templates.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
import pypugjs
from fastapi.templating import Jinja2Templates
from markdown import markdown as markdown2html

Expand All @@ -10,11 +9,7 @@
)

templates.env.globals["config"] = get_config()
templates.env.filters["markdown"] = lambda text: markdown2html(text)

# Jade templating is nice for faster prototyping
templates.env.add_extension("pypugjs.ext.jinja.PyPugJSExtension")


@pypugjs.register_filter("markdown")
def markdown(text, ast):
return markdown2html(text)
13 changes: 11 additions & 2 deletions backend/templates/team-admin.pug
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,22 @@ td.has-text-light
.block
.title.is-3 Team Settings
.field.is-horizontal
.field-label.is-normal Description/Headline
.field-label.is-normal Headline
.field-body
.control.has-icons-left
input.input#team_name(type="string" placeholder="Description" name="headline" hx-post="{{url_for('update_team_headline', team_name=team.name)}}" hx-trigger="input changed delay:500ms, search" hx-target="#updated_team_headline")
input.input(type="string" placeholder="Tagline" name="headline" hx-post="{{url_for('update_team_headline', team_name=team.name)}}" hx-trigger="input changed delay:500ms, search" hx-target="#updated_team_headline" value="{{team.headline}}")
span.icon.is-left
i.fas.fa-expand
span(id="updated_team_headline")
form(hx-post="{{url_for('update_team_description', team_name=team.name)}}" hx-target="#updated_team_description")
.field.is-horizontal
.field-label.is-normal Description
.field-body
.control
textarea.textarea(type="string" placeholder="Description" name="description") {{team.description}}
small.helper Markdown supported
span#updated_team_description
button.button.is-block.is-link.is-fullwidth.is-normal.m-0 Subscribe

// .field.is-horizontal
// .field-label.is-normal Hide Team
Expand Down
65 changes: 32 additions & 33 deletions backend/templates/team.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
.columns
.column.is-8.is-offset-2
.block
.title.is-1 {{team.name}}
.subtitle.is-5.text-icon
.columns
.column.is-half
.title.is-1 {{team.name}}
.subtitle.is-5.text-icon {{team.headline}}
.column.is-half.has-text-right
{% if team.is_paid %}
span.icon-text
span.icon
Expand All @@ -17,40 +20,36 @@
i.fas.fa-globe
span Team
{% endif %}
.block
{% if user_repo.is_member(user, team) %}
a(href="{{url_for('leave', team_name=team.name)}}").button.is-small
span.icon.is-small
i.fas.fa-signature
span Leave
{% else %}
{% if team.can(Permissions.can_join, user, membership) %}
a(href="{{url_for('join', team_name=team.name)}}").button.is-small
span.icon.is-small
i.fas.fa-signature
span Join Team
{% else %}
p.notification.is-warning.is-light You cannot join this team. You must be invited.
{% endif %}
{% endif %}

.block
{% if user_repo.is_member(user, team) %}
a(href="{{url_for('leave', team_name=team.name)}}").button
span.icon.is-small
i.fas.fa-signature
span Leave
{% else %}
{% if team.can(Permissions.can_join, user, membership) %}
a(href="{{url_for('join', team_name=team.name)}}").button
span.icon.is-small
i.fas.fa-signature
span Join Team
{% else %}
p.notification.is-warning.is-light You cannot join this team. You must be invited.
{% endif %}
{% endif %}

{% if user and team.user_id == user.id %}
a(href="{{url_for('settings', team_name=team.name)}}").button.is-warning
span.icon-text
span.icon.is-small
i.fas.fa-edit
span Admin Setting
{% endif %}
{% if user and team.user_id == user.id %}
a(href="{{url_for('settings', team_name=team.name)}}").button.is-warning.is-small
span.icon-text
span.icon.is-small
i.fas.fa-edit
span Admin Setting
{% endif %}

{% if team.description %}
.block
.title.is-3 Description
.box
{% if team.headline %}
p {{team.headline}}
{% else %}
p.is-italic no description provided
{% endif %}
.box.content.p-2.m-0
p {{team.description | markdown | safe}}
{% endif %}

.block
.title.is-3 Topics
Expand Down

0 comments on commit 9ba4257

Please sign in to comment.