From f3f3b0e68fad36a272f59dd2959492059b342ff6 Mon Sep 17 00:00:00 2001 From: Luca Date: Wed, 13 Dec 2023 23:58:00 +0100 Subject: [PATCH] initial commit --- .github/workflows/python-version.txt | 1 + .github/workflows/style.yml | 103 ++++++++++++++++++ .gitignore | 88 +++++++++++++++ LICENSE | 13 +++ MANIFEST.in | 6 + Makefile | 10 ++ README.rst | 48 ++++++++ pretalx_musicrate/__init__.py | 1 + pretalx_musicrate/apps.py | 20 ++++ pretalx_musicrate/forms.py | 17 +++ pretalx_musicrate/models.py | 13 +++ pretalx_musicrate/signals.py | 22 ++++ .../static/pretalx_musicrate/.gitkeep | 0 .../templates/pretalx_musicrate/.gitkeep | 0 pretalx_musicrate/urls.py | 14 +++ pretalx_musicrate/views.py | 30 +++++ pyproject.toml | 38 +++++++ 17 files changed, 424 insertions(+) create mode 100644 .github/workflows/python-version.txt create mode 100644 .github/workflows/style.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 MANIFEST.in create mode 100644 Makefile create mode 100644 README.rst create mode 100644 pretalx_musicrate/__init__.py create mode 100644 pretalx_musicrate/apps.py create mode 100644 pretalx_musicrate/forms.py create mode 100644 pretalx_musicrate/models.py create mode 100644 pretalx_musicrate/signals.py create mode 100644 pretalx_musicrate/static/pretalx_musicrate/.gitkeep create mode 100644 pretalx_musicrate/templates/pretalx_musicrate/.gitkeep create mode 100644 pretalx_musicrate/urls.py create mode 100644 pretalx_musicrate/views.py create mode 100644 pyproject.toml diff --git a/.github/workflows/python-version.txt b/.github/workflows/python-version.txt new file mode 100644 index 0000000..2c07333 --- /dev/null +++ b/.github/workflows/python-version.txt @@ -0,0 +1 @@ +3.11 diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml new file mode 100644 index 0000000..bdb74b4 --- /dev/null +++ b/.github/workflows/style.yml @@ -0,0 +1,103 @@ +name: Code Style + +on: + push: + branches: [ main ] + paths-ignore: + - 'pretalx_musicrate/locale/**' + - 'pretalx_musicrate/static/**' + pull_request: + branches: [ main ] + paths-ignore: + - 'pretalx_musicrate/locale/**' + - 'pretalx_musicrate/static/**' + +jobs: + isort: + name: isort + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: install gettext + run: sudo apt install gettext + - name: Set up Python 3.11 + uses: actions/setup-python@v1 + with: + python-version-file: ".github/workflows/python-version.txt" + cache: "pip" + - name: Install isort + run: pip3 install isort + - name: Run isort + run: isort -c . + flake: + name: flake8 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: install gettext + run: sudo apt install gettext + - name: Set up Python 3.11 + uses: actions/setup-python@v1 + with: + python-version-file: ".github/workflows/python-version.txt" + cache: "pip" + - name: Install Dependencies + run: pip3 install flake8 flake8-bugbear + - name: Run flake8 + run: flake8 . + working-directory: . + black: + name: black + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: install gettext + run: sudo apt install gettext + - name: Set up Python 3.11 + uses: actions/setup-python@v1 + with: + python-version-file: ".github/workflows/python-version.txt" + cache: "pip" + - name: Install Dependencies + run: pip3 install black + - name: Run black + run: black --check . + working-directory: . + djhtml: + name: djhtml + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: install gettext + run: sudo apt install gettext + - name: Set up Python 3.11 + uses: actions/setup-python@v1 + with: + python-version-file: ".github/workflows/python-version.txt" + cache: "pip" + - name: Install Dependencies + run: pip3 install djhtml + - name: Run docformatter + run: find -name "*.html" | xargs djhtml -c + working-directory: . + packaging: + name: packaging + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.11 + uses: actions/setup-python@v1 + with: + python-version-file: ".github/workflows/python-version.txt" + cache: "pip" + - name: Install Dependencies + run: pip3 install twine check-manifest -Ue . + - name: Run check-manifest + run: check-manifest . + working-directory: . + - name: Build package + run: python -m build + working-directory: . + - name: Check package + run: twine check dist/* + working-directory: . diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03bcc0c --- /dev/null +++ b/.gitignore @@ -0,0 +1,88 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg +.ropeproject/ + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ +*.toc + +# Environments +.env +.venv +env/ +venv/ +ENV/ + +# editors +*.swp +*.aux +*~ +.project +.pydevproject +.vscode + +# IDEA / pycharm +.idea/ +atlassian-ide-plugin.xml + +# generic local files +local/ +*.xml +pretalx.cfg + +# OS X +.DS_Store + +.pytest_cache +*.cfg diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ddb54b3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright 2023 Luca + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..9440ab8 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,6 @@ +recursive-include pretalx_musicrate/static * +recursive-include pretalx_musicrate/templates * +exclude pretalx_musicrate/locale/django.pot +recursive-include pretalx_musicrate/locale * +recursive-include pretalx_musicrate *.py +include Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e3c39f3 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +all: localecompile +LNGS:=`find pretalx_musicrate/locale/ -mindepth 1 -maxdepth 1 -type d -printf "-l %f "` + +localecompile: + django-admin compilemessages + +localegen: + django-admin makemessages -l de_DE -i build -i dist -i "*egg*" $(LNGS) + +.PHONY: all localecompile localegen diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..28bf90d --- /dev/null +++ b/README.rst @@ -0,0 +1,48 @@ +pretalx musicrate plugin +========================== + +This is a plugin for `pretalx`_. +pretalx plugin for rating music + +Development setup +----------------- + +1. Make sure that you have a working `pretalx development setup`_. + +2. Clone this repository, eg to ``local/pretalx-musicrate``. + +3. Activate the virtual environment you use for pretalx development. + +4. Run ``pip install -e .`` within this directory to register this application with pretalx's plugin registry. + +5. Run ``make`` within this directory to compile translations. + +6. Restart your local pretalx server. This plugin should show up in the plugin list shown on startup in the console. + You can now use the plugin from this repository for your events by enabling it in the 'plugins' tab in the settings. + +This plugin has CI set up to enforce a few code style rules. To check locally, you need these packages installed:: + + pip install flake8 flake8-bugbear isort black + +To check your plugin for rule violations, run:: + + black --check . + isort -c . + flake8 . + +You can auto-fix some of these issues by running:: + + isort . + black . + + +License +------- + +Copyright 2023 Luca + +Released under the terms of the Apache License 2.0 + + +.. _pretalx: https://github.com/pretalx/pretalx +.. _pretalx development setup: https://docs.pretalx.org/en/latest/developer/setup.html diff --git a/pretalx_musicrate/__init__.py b/pretalx_musicrate/__init__.py new file mode 100644 index 0000000..f102a9c --- /dev/null +++ b/pretalx_musicrate/__init__.py @@ -0,0 +1 @@ +__version__ = "0.0.1" diff --git a/pretalx_musicrate/apps.py b/pretalx_musicrate/apps.py new file mode 100644 index 0000000..af2506e --- /dev/null +++ b/pretalx_musicrate/apps.py @@ -0,0 +1,20 @@ +from django.apps import AppConfig +from django.utils.translation import gettext_lazy + +from . import __version__ + + +class PluginApp(AppConfig): + name = "pretalx_musicrate" + verbose_name = "pretalx musicrate plugin" + + class PretalxPluginMeta: + name = gettext_lazy("pretalx musicrate plugin") + author = "Luca" + description = gettext_lazy("pretalx plugin for rating music") + visible = True + version = __version__ + category = "FEATURE" + + def ready(self): + from . import signals # NOQA diff --git a/pretalx_musicrate/forms.py b/pretalx_musicrate/forms.py new file mode 100644 index 0000000..2b92a32 --- /dev/null +++ b/pretalx_musicrate/forms.py @@ -0,0 +1,17 @@ + +from i18nfield.forms import I18nModelForm + +from .models import MusicrateSettings + + +class MusicrateSettingsForm(I18nModelForm): + + def __init__(self, *args, event=None, **kwargs): + self.instance, _ = MusicrateSettings.objects.get_or_create(event=event) + super().__init__(*args, **kwargs, instance=self.instance, locales=event.locales) + + class Meta: + model = MusicrateSettings + fields = ("some_setting", ) + widgets = {} + diff --git a/pretalx_musicrate/models.py b/pretalx_musicrate/models.py new file mode 100644 index 0000000..d819642 --- /dev/null +++ b/pretalx_musicrate/models.py @@ -0,0 +1,13 @@ +from django.db import models + + + + +class MusicrateSettings(models.Model): + event = models.OneToOneField( + to="event.Event", + on_delete=models.CASCADE, + related_name="pretalx_musicrate_settings", + ) + some_setting = models.CharField(max_length=10, default="A") + diff --git a/pretalx_musicrate/signals.py b/pretalx_musicrate/signals.py new file mode 100644 index 0000000..a3eccf3 --- /dev/null +++ b/pretalx_musicrate/signals.py @@ -0,0 +1,22 @@ + +from django.dispatch import receiver +from django.urls import reverse +from pretalx.orga.signals import nav_event_settings + + +@receiver(nav_event_settings) +def pretalx_musicrate_settings(sender, request, **kwargs): + if not request.user.has_perm("orga.change_settings", request.event): + return [] + return [ + { + "label": "pretalx musicrate plugin", + "url": reverse( + "plugins:pretalx_musicrate:settings", + kwargs={"event": request.event.slug}, + ), + "active": request.resolver_match.url_name + == "plugins:pretalx_musicrate:settings", + } + ] + diff --git a/pretalx_musicrate/static/pretalx_musicrate/.gitkeep b/pretalx_musicrate/static/pretalx_musicrate/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/pretalx_musicrate/templates/pretalx_musicrate/.gitkeep b/pretalx_musicrate/templates/pretalx_musicrate/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/pretalx_musicrate/urls.py b/pretalx_musicrate/urls.py new file mode 100644 index 0000000..b0d0b19 --- /dev/null +++ b/pretalx_musicrate/urls.py @@ -0,0 +1,14 @@ + +from django.urls import re_path +from pretalx.event.models.event import SLUG_REGEX + +from .views import MusicrateSettings + +urlpatterns = [ + re_path( + rf"^orga/event/(?P{SLUG_REGEX})/settings/p/pretalx_musicrate/$", + MusicrateSettings.as_view(), + name="settings", + ), +] + diff --git a/pretalx_musicrate/views.py b/pretalx_musicrate/views.py new file mode 100644 index 0000000..8afbb0e --- /dev/null +++ b/pretalx_musicrate/views.py @@ -0,0 +1,30 @@ +from django.contrib import messages +from django.utils.translation import gettext_lazy as _ +from django.views.generic import FormView +from pretalx.common.mixins.views import PermissionRequired + + +from .forms import MusicrateSettingsForm + + +class MusicrateSettingsView(PermissionRequired, FormView): + permission_required = "orga.change_settings" + template_name = "pretalx_musicrate/settings.html" + form_class = MusicrateSettingsForm + + def get_success_url(self): + return self.request.path + + def get_object(self): + return self.request.event + + def get_form_kwargs(self): + kwargs = super().get_form_kwargs() + kwargs["event"] = self.request.event + return kwargs + + def form_valid(self, form): + form.save() + messages.success(self.request, _("The pretalx musicrate plugin settings were updated.")) + return super().form_valid(form) + diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f34ac37 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[project] +name = "pretalx-musicrate" +dynamic = ["version"] +description = "pretalx plugin for rating music" +readme = "README.rst" +license = {text = "Apache Software License"} +keywords = ["pretalx"] +authors = [ + {name = "Luca", email = "Luca@hackerspace-bamberg.de"}, +] +maintainers = [ + {name = "Luca", email = "Luca@hackerspace-bamberg.de"}, +] + +dependencies = [] + +[project.urls] +homepage = "https://git.luj0ga.de/kontakt/pretalx-musicrate" +repository = "https://git.luj0ga.de/kontakt/pretalx-musicrate.git" + +[project.entry-points."pretalx.plugin"] +pretalx_musicrate = "pretalx_musicrate:PretalxPluginMeta" + +[build-system] +build-backend = "setuptools.build_meta" +requires = ["setuptools"] + +[tool.setuptools] +include-package-data = true + +[tool.setuptools.dynamic] +version = {attr = "pretalx_musicrate.__version__"} + +[tool.setuptools.packages.find] +include = ["pretalx*"] + +[tool.check-manifest] +ignore = [".*"]