From 49a0bb34e05e30d5f3fc9a744b2eed56f6960174 Mon Sep 17 00:00:00 2001 From: Ember 'n0emis' Keske Date: Mon, 28 Feb 2022 12:53:29 +0100 Subject: [PATCH] Initial commit --- .gitignore | 63 +++++++++++++++++++++++++++++++++++++++++ .install-hooks.sh | 17 +++++++++++ LICENSE | 15 ++++++++++ MANIFEST.in | 5 ++++ Makefile | 10 +++++++ README.rst | 55 +++++++++++++++++++++++++++++++++++ pretix_poos/__init__.py | 28 ++++++++++++++++++ pretix_poos/signals.py | 19 +++++++++++++ pretix_poos/urls.py | 10 +++++++ pretix_poos/views.py | 45 +++++++++++++++++++++++++++++ setup.cfg | 41 +++++++++++++++++++++++++++ setup.py | 45 +++++++++++++++++++++++++++++ 12 files changed, 353 insertions(+) create mode 100644 .gitignore create mode 100755 .install-hooks.sh create mode 100644 LICENSE create mode 100644 MANIFEST.in create mode 100644 Makefile create mode 100644 README.rst create mode 100644 pretix_poos/__init__.py create mode 100644 pretix_poos/signals.py create mode 100644 pretix_poos/urls.py create mode 100644 pretix_poos/views.py create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0f6b8f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,63 @@ +# 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 + +# Django stuff: +*.log +data/ + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +#Ipython Notebook +.ipynb_checkpoints diff --git a/.install-hooks.sh b/.install-hooks.sh new file mode 100755 index 0000000..d95267e --- /dev/null +++ b/.install-hooks.sh @@ -0,0 +1,17 @@ +#!/bin/sh +REPO_DIR=$(git rev-parse --show-toplevel) +GIT_DIR=$REPO_DIR/.git +VENV_ACTIVATE=$VIRTUAL_ENV/bin/activate +if [[ ! -f $VENV_ACTIVATE ]] +then + echo "Could not find your virtual environment" +fi + +echo "#!/bin/sh" >> $GIT_DIR/hooks/pre-commit +echo "set -e" >> $GIT_DIR/hooks/pre-commit +echo "source $VENV_ACTIVATE" >> $GIT_DIR/hooks/pre-commit +echo "docformatter --check -r ." >> $GIT_DIR/hooks/pre-commit +echo "black --check ." >> $GIT_DIR/hooks/pre-commit +echo "isort -c ." >> $GIT_DIR/hooks/pre-commit +echo "flake8 ." >> $GIT_DIR/hooks/pre-commit +chmod +x $GIT_DIR/hooks/pre-commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6158b61 --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ + +Copyright 2022 n0emis + +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..6651e40 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +recursive-include pretix_poos/static * +recursive-include pretix_poos/templates * +recursive-include pretix_poos/locale * +include LICENSE +exclude .gitlab-ci.yml diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..29a0d2e --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +all: localecompile +LNGS:=`find pretix_poos/locale/ -mindepth 1 -maxdepth 1 -type d -printf "-l %f "` + +localecompile: + django-admin compilemessages + +localegen: + django-admin makemessages --keep-pot -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..83c5f22 --- /dev/null +++ b/README.rst @@ -0,0 +1,55 @@ +Pretix POOS +========================== + +This is a plugin for `pretix`_. + +Short description + +Development setup +----------------- + +1. Make sure that you have a working `pretix development setup`_. + +2. Clone this repository. + +3. Activate the virtual environment you use for pretix development. + +4. Execute ``python setup.py develop`` within this directory to register this application with pretix's plugin registry. + +5. Execute ``make`` within this directory to compile translations. + +6. Restart your local pretix server. 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 isort black docformatter + +To check your plugin for rule violations, run:: + + docformatter --check -r . + black --check . + isort -c . + flake8 . + +You can auto-fix some of these issues by running:: + + docformatter -r . + isort . + black . + +To automatically check for these issues before you commit, you can run ``.install-hooks``. + + +License +------- + + +Copyright 2022 n0emis + +Released under the terms of the Apache License 2.0 + + + +.. _pretix: https://github.com/pretix/pretix +.. _pretix development setup: https://docs.pretix.eu/en/latest/development/setup.html diff --git a/pretix_poos/__init__.py b/pretix_poos/__init__.py new file mode 100644 index 0000000..3f3dfb8 --- /dev/null +++ b/pretix_poos/__init__.py @@ -0,0 +1,28 @@ +from django.utils.translation import gettext_lazy + +try: + from pretix.base.plugins import PluginConfig +except ImportError: + raise RuntimeError("Please use pretix 2.7 or above to run this plugin!") + +__version__ = "1.0.0" + + +class PluginApp(PluginConfig): + name = "pretix_poos" + verbose_name = "Pretix POOS" + + class PretixPluginMeta: + name = gettext_lazy("Pretix POOS") + author = "n0emis" + description = gettext_lazy("Short description") + visible = True + version = __version__ + category = "CUSTOMIZATION" + compatibility = "pretix>=2.7.0" + + def ready(self): + from . import signals # NOQA + + +default_app_config = "pretix_poos.PluginApp" diff --git a/pretix_poos/signals.py b/pretix_poos/signals.py new file mode 100644 index 0000000..be745ec --- /dev/null +++ b/pretix_poos/signals.py @@ -0,0 +1,19 @@ +from django.dispatch import receiver + +from pretix.base.signals import register_sales_channels +from pretix.base.channels import SalesChannel + +class PoosSalesChannel(SalesChannel): + identifier = "pretixpos" + verbose_name = 'Box office (pretixPOS)' + icon = "shopping-basket" + + payment_restrictions_supported = False + customer_accounts_supported = False + +@receiver(register_sales_channels, dispatch_uid="poos_register_sales_channels") +def base_sales_channels(sender, **kwargs): + return ( + PoosSalesChannel(), + ) + diff --git a/pretix_poos/urls.py b/pretix_poos/urls.py new file mode 100644 index 0000000..a7cb1e4 --- /dev/null +++ b/pretix_poos/urls.py @@ -0,0 +1,10 @@ +from pretix.api.urls import router, orga_router +from django.conf.urls import url + + +from .views import * + +urlpatterns = [ + url(r'^api/v1/organizers/(?P[^/]+)/posdevices/(?P[^/.]+)/closings/', ClosingsView.as_view(), name='api.closings'), + url(r'^api/v1/organizers/(?P[^/]+)/pos/cashiers/', CashierView.as_view(), name='api.cashiers'), +] diff --git a/pretix_poos/views.py b/pretix_poos/views.py new file mode 100644 index 0000000..f89672c --- /dev/null +++ b/pretix_poos/views.py @@ -0,0 +1,45 @@ +from rest_framework.response import Response +from rest_framework.views import APIView + +class ClosingsView(APIView): + def get(self, request, organizer, device_id): + return Response({ + 'count': 0, + 'next': None, + 'previous': None, + 'results': [] + }) + +class CashierView(APIView): + def get(self, request, organizer): + return Response({ + "count": 1, + "next": None, + "previous": None, + "results": [ + { + "active": Trie, + "id": 1, + "last_modified": "2022-02-25T08:26:38.489714+01:00", + "name": "User", + "pin": None, + "team": { + "all_devices": True, + "can_accept_gift_cards": True, + "can_access_settings": True, + "can_manage_cash_close_sessions": False, + "can_open_drawer": True, + "can_perform_refunds": True, + "can_reprint_tickets": True, + "can_switch_events": True, + "can_view_all_orders": True, + "can_view_past_transactions": True, + "devices": [], + "id": 1, + "last_modified": "2022-02-25T08:26:38.484243+01:00", + "name": "Administrators" + }, + "userid": "0001" + } + ] + }) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..44f0353 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,41 @@ +[flake8] +ignore = N802,W503,E402 +max-line-length = 160 +exclude = migrations,.ropeproject,static,_static,build + +[isort] +combine_as_imports = true +default_section = THIRDPARTY +include_trailing_comma = true +known_third_party = pretix +known_standard_library = typing +multi_line_output = 3 +skip = setup.py +use_parentheses = True +force_grid_wrap = 0 +line_length = 88 +known_first_party = pretix_poos + +[tool:pytest] +DJANGO_SETTINGS_MODULE = pretix.testutils.settings + +[coverage:run] +source = pretix_poos +omit = */migrations/*,*/urls.py,*/tests/* + +[coverage:report] +exclude_lines = + pragma: no cover + def __str__ + der __repr__ + if settings.DEBUG + NOQA + NotImplementedError + +[check-manifest] +ignore = + .update-locales.sh + .install-hooks.sh + Makefile + manage.py + tests/* diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..7ca65ba --- /dev/null +++ b/setup.py @@ -0,0 +1,45 @@ +import os +from distutils.command.build import build + +from django.core import management +from setuptools import find_packages, setup + +from pretix_poos import __version__ + + +try: + with open( + os.path.join(os.path.dirname(__file__), "README.rst"), encoding="utf-8" + ) as f: + long_description = f.read() +except Exception: + long_description = "" + + +class CustomBuild(build): + def run(self): + management.call_command("compilemessages", verbosity=1) + build.run(self) + + +cmdclass = {"build": CustomBuild} + + +setup( + name="pretix-poos", + version=__version__, + description="Short description", + long_description=long_description, + url="GitHub repository URL", + author="n0emis", + author_email="git@N0emis.eu", + license="Apache", + install_requires=[], + packages=find_packages(exclude=["tests", "tests.*"]), + include_package_data=True, + cmdclass=cmdclass, + entry_points=""" +[pretix.plugin] +pretix_poos=pretix_poos:PretixPluginMeta +""", +)