~homeworkprod/byceps

b94b8ed992ad8a3f5d1ab006cc096920c53d2e32 — Jochen Kupperschmidt 8 months ago 63e8101
Replace script to create ticket category with admin UI
A byceps/blueprints/admin/ticketing/category/forms.py => byceps/blueprints/admin/ticketing/category/forms.py +20 -0
@@ 0,0 1,20 @@
"""
byceps.blueprints.admin.ticketing.category.forms
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from flask_babel import lazy_gettext
from wtforms import StringField
from wtforms.validators import InputRequired, Length

from .....util.l10n import LocalizedForm


class CreateForm(LocalizedForm):
    title = StringField(
        lazy_gettext('Title'),
        validators=[InputRequired(), Length(min=1, max=40)],
    )

A byceps/blueprints/admin/ticketing/category/templates/admin/ticketing/category/create_form.html => byceps/blueprints/admin/ticketing/category/templates/admin/ticketing/category/create_form.html +20 -0
@@ 0,0 1,20 @@
{% extends 'layout/admin/base.html' %}
{% from 'macros/forms.html' import form_buttons, form_field, form_fieldset %}
{% from 'macros/icons.html' import render_icon %}
{% set current_page_party = party %}
{% set current_page = 'ticketing_admin' %}
{% set title = 'Ticket-Kategorie erstellen' %}

{% block body %}

  <h1>{{ render_icon('add') }} {{ title }}</h1>

  <form action="{{ url_for('.create', party_id=party.id) }}" method="post">
    {% call form_fieldset() %}
      {{ form_field(form.title, maxlength=40, autofocus='autofocus') }}
    {% endcall %}

    {{ form_buttons(_('Create'), cancel_url=url_for('.index', party_id=party.id)) }}
  </form>

{%- endblock %}

M byceps/blueprints/admin/ticketing/category/templates/admin/ticketing/category/index.html => byceps/blueprints/admin/ticketing/category/templates/admin/ticketing/category/index.html +13 -1
@@ 1,12 1,24 @@
{% extends 'layout/admin/ticketing.html' %}
{% from 'macros/admin.html' import render_extra_in_heading %}
{% from 'macros/icons.html' import render_icon %}
{% set current_page_party = party %}
{% set current_tab = 'categories' %}
{% set title = '%s - Ticket-Kategorien'|format(party.title) %}

{% block body %}

  <h1>Ticket-Kategorien {{ render_extra_in_heading(categories_with_ticket_counts|length) }}</h1>
  <div class="row row--space-between">
    <div class="column-auto">
      <h1>Ticket-Kategorien {{ render_extra_in_heading(categories_with_ticket_counts|length) }}</h1>
    </div>
    {%- if g.user.has_permission(TicketingPermission.administrate) %}
    <div class="column-auto">
      <div class="button-row button-row--right">
        <a class="button" href="{{ url_for('.create_form', party_id=party.id) }}">{{ render_icon('add') }} <span>Kategorie erstellen</span></a>
      </div>
    </div>
    {%- endif %}
  </div>

  {%- if categories_with_ticket_counts %}
  <table class="index wide">

M byceps/blueprints/admin/ticketing/category/views.py => byceps/blueprints/admin/ticketing/category/views.py +45 -2
@@ 6,18 6,22 @@ byceps.blueprints.admin.ticketing.category.views
:License: Revised BSD (see `LICENSE` file for details)
"""

from flask import abort
from flask import abort, request
from flask_babel import gettext

from .....services.party import service as party_service
from .....services.ticketing import (
    category_service as ticketing_category_service,
)
from .....util.framework.blueprint import create_blueprint
from .....util.framework.flash import flash_success
from .....util.framework.templating import templated
from .....util.views import permission_required
from .....util.views import permission_required, redirect_to

from ...ticketing.authorization import TicketingPermission

from .forms import CreateForm


blueprint = create_blueprint('ticketing_category_admin', __name__)



@@ 41,6 45,45 @@ def index(party_id):
    }


@blueprint.route('/for_party/<party_id>/create')
@permission_required(TicketingPermission.administrate)
@templated
def create_form(party_id, erroneous_form=None):
    """Show form to create a ticket category."""
    party = _get_party_or_404(party_id)

    form = erroneous_form if erroneous_form else CreateForm()

    return {
        'party': party,
        'form': form,
    }


@blueprint.route('/for_party/<party_id>', methods=['POST'])
@permission_required(TicketingPermission.administrate)
def create(party_id):
    """Create a ticket category."""
    party = _get_party_or_404(party_id)

    form = CreateForm(request.form)
    if not form.validate():
        return create_form(party.id, form)

    title = form.title.data.strip()

    category = ticketing_category_service.create_category(party.id, title)

    flash_success(
        gettext(
            'Ticket category "%(title)s" has been created.',
            title=category.title,
        )
    )

    return redirect_to('.index', party_id=party.id)


def _get_party_or_404(party_id):
    party = party_service.find_party(party_id)


M byceps/translations/de/LC_MESSAGES/messages.po => byceps/translations/de/LC_MESSAGES/messages.po +8 -1
@@ 7,7 7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2021-01-31 06:42+0100\n"
"POT-Creation-Date: 2021-01-31 06:43+0100\n"
"PO-Revision-Date: 2021-01-24 11:05+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: de\n"


@@ 82,6 82,7 @@ msgstr "Slug"
#: byceps/blueprints/admin/party/forms.py:19
#: byceps/blueprints/admin/site/forms.py:24
#: byceps/blueprints/admin/snippet/forms.py:43
#: byceps/blueprints/admin/ticketing/category/forms.py:18
#: byceps/blueprints/admin/tourney/category/forms.py:18
#: byceps/blueprints/admin/tourney/tourney/forms.py:21
#: byceps/blueprints/site/board/forms.py:26


@@ 169,6 170,7 @@ msgstr "Die Kategorie \"%(category_title)s\" wurde gelöscht."
#: byceps/blueprints/admin/orga_team/templates/admin/orga_team/team_create_form.html:22
#: byceps/blueprints/admin/party/templates/admin/party/create_form.html:28
#: byceps/blueprints/admin/site/templates/admin/site/create_form.html:34
#: byceps/blueprints/admin/ticketing/category/templates/admin/ticketing/category/create_form.html:17
#: byceps/blueprints/admin/tourney/category/templates/admin/tourney/category/create_form.html:24
#: byceps/blueprints/admin/tourney/tourney/templates/admin/tourney/tourney/create_form.html:29
#: byceps/blueprints/admin/user/templates/admin/user/create_account_form.html:26


@@ 1090,6 1092,11 @@ msgstr ""
"%(screen_name)s wurde als Nutzer/in von Ticket %(ticket_code)s "
"eingetragen."

#: byceps/blueprints/admin/ticketing/category/views.py:78
#, python-format
msgid "Ticket category \"%(title)s\" has been created."
msgstr "Ticket-Kategorie \"%(title)s\" wurde erstellt."

#: byceps/blueprints/admin/ticketing/checkin/views.py:125
msgid ""
"The user account assigned to this ticket has been deleted. Check-in "

D scripts/create_ticket_category.py => scripts/create_ticket_category.py +0 -30
@@ 1,30 0,0 @@
#!/usr/bin/env python

"""Create a ticket category for a party.

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

import click

from byceps.services.ticketing import category_service
from byceps.util.system import get_config_filename_from_env_or_exit

from _util import app_context
from _validators import validate_party


@click.command()
@click.argument('party', callback=validate_party)
@click.argument('title')
def execute(party, title):
    category_service.create_category(party.id, title)

    click.secho('Done.', fg='green')


if __name__ == '__main__':
    config_filename = get_config_filename_from_env_or_exit()
    with app_context(config_filename):
        execute()

M tests/integration/blueprints/admin/ticketing/test_views.py => tests/integration/blueprints/admin/ticketing/test_views.py +6 -0
@@ 38,3 38,9 @@ def test_category_index(ticketing_admin_client, party):
    url = f'/admin/ticketing/categories/for_party/{party.id}'
    response = ticketing_admin_client.get(url)
    assert response.status_code == 200


def test_category_create_form(ticketing_admin_client, party):
    url = f'/admin/ticketing/categories/for_party/{party.id}/create'
    response = ticketing_admin_client.get(url)
    assert response.status_code == 200