Initial commit

This commit is contained in:
Raphael Michel 2018-02-27 23:12:01 +01:00
commit 90e50b8084
18 changed files with 331 additions and 0 deletions

63
.gitignore vendored Normal file
View file

@ -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
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
#Ipython Notebook
.ipynb_checkpoints

13
LICENSE Normal file
View file

@ -0,0 +1,13 @@
Copyright 2018 Raphael Michel
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.

3
MANIFEST.in Normal file
View file

@ -0,0 +1,3 @@
recursive-include pretix_servicefees/static *
recursive-include pretix_servicefees/templates *
recursive-include pretix_servicefees/locale *

8
Makefile Normal file
View file

@ -0,0 +1,8 @@
all: localecompile
localecompile:
django-admin compilemessages
localegen:
django-admin makemessages -l de_Informal -l de -i build -i dist -i "*egg*"

32
README.rst Normal file
View file

@ -0,0 +1,32 @@
pretix Service Fees
==========================
This is a plugin for `pretix`_.
Development setup
-----------------
1. Make sure that you have a working `pretix development setup`_.
2. Clone this repository, eg to ``local/pretix-servicefees``.
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.
License
-------
Copyright 2018 Raphael Michel
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

View file

@ -0,0 +1,20 @@
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy
class PluginApp(AppConfig):
name = 'pretix_servicefees'
verbose_name = 'pretix Service Fees'
class PretixPluginMeta:
name = ugettext_lazy('pretix Service Fees')
author = 'Raphael Michel'
description = ugettext_lazy('Allows you to impose a service fee on all non-free orders.')
visible = True
version = '1.0.0'
def ready(self):
from . import signals # NOQA
default_app_config = 'pretix_servicefees.PluginApp'

View file

@ -0,0 +1,12 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-03-07 19:01+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: Raphael Michel\n"
"Language-Team: \n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View file

@ -0,0 +1,12 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-03-07 19:01+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: Raphael Michel\n"
"Language-Team: \n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View file

@ -0,0 +1,60 @@
from decimal import Decimal
from django.urls import resolve, reverse
from django.dispatch import receiver
from django.http import HttpRequest
from django.utils.translation import ugettext_lazy as _
from pretix.base.models import Event, Order, TaxRule
from pretix.base.models.orders import OrderFee
from pretix.base.signals import order_fee_calculation
from pretix.control.signals import nav_event_settings
from pretix.presale.signals import fee_calculation_for_cart
@receiver(nav_event_settings, dispatch_uid='service_fee_nav_settings')
def navbar_settings(sender, request, **kwargs):
url = resolve(request.path_info)
return [{
'label': _('Service Fee'),
'url': reverse('plugins:pretix_servicefees:settings', kwargs={
'event': request.event.slug,
'organizer': request.organizer.slug,
}),
'active': url.namespace == 'plugins:pretix_servicefees' and url.url_name.startswith('settings'),
}]
def get_fees(event, total, invoice_address):
fee = event.settings.get('service_fee_abs', as_type=Decimal)
if fee and total != Decimal('0.00'):
tax_rule = event.settings.tax_rate_default or TaxRule.zero()
if tax_rule.tax_applicable(invoice_address):
tax = tax_rule.tax(fee)
return [OrderFee(
fee_type=OrderFee.FEE_TYPE_SERVICE,
internal_type='',
value=fee,
tax_rate=tax.rate,
tax_value=tax.tax,
tax_rule=tax_rule
)]
else:
return [OrderFee(
fee_type=OrderFee.FEE_TYPE_SERVICE,
internal_type='',
value=fee,
tax_rate=Decimal('0.00'),
tax_value=Decimal('0.00'),
tax_rule=tax_rule
)]
return []
@receiver(fee_calculation_for_cart, dispatch_uid="service_fee_calc_cart")
def cart_fee(sender: Event, request: HttpRequest, invoice_address, total, **kwargs):
return get_fees(sender, total, invoice_address)
@receiver(order_fee_calculation, dispatch_uid="service_fee_calc_order")
def order_fee(sender: Event, invoice_address, total, **kwargs):
return get_fees(sender, total, invoice_address)

View file

@ -0,0 +1,18 @@
{% extends "pretixcontrol/event/settings_base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% block inside %}
<form action="" method="post" class="form-horizontal" enctype="multipart/form-data">
{% csrf_token %}
{% bootstrap_form_errors form %}
<fieldset>
<legend>{% trans "Service fees" %}</legend>
{% bootstrap_field form.service_fee_abs layout="control" %}
</fieldset>
<div class="form-group submit-group">
<button type="submit" class="btn btn-primary btn-save">
{% trans "Save" %}
</button>
</div>
</form>
{% endblock %}

View file

@ -0,0 +1,8 @@
from django.conf.urls import url
from .views import SettingsView
urlpatterns = [
url(r'^control/event/(?P<organizer>[^/]+)/(?P<event>[^/]+)/settings/servicefees/$',
SettingsView.as_view(), name='settings'),
]

View file

@ -0,0 +1,22 @@
from django import forms
from django.urls import reverse
from pretix.base.forms import SettingsForm
from pretix.base.models import Event
from pretix.control.views.event import EventSettingsViewMixin, EventSettingsFormView
class ServiceFeeSettingsForm(SettingsForm):
service_fee_abs = forms.DecimalField()
class SettingsView(EventSettingsViewMixin, EventSettingsFormView):
model = Event
form_class = ServiceFeeSettingsForm
template_name = 'pretix_servicefees/settings.html'
permission = 'can_change_event_settings'
def get_success_url(self) -> str:
return reverse('plugins:pretix_servicefees:settings', kwargs={
'organizer': self.request.event.organizer.slug,
'event': self.request.event.slug
})

2
pytest.ini Normal file
View file

@ -0,0 +1,2 @@
[pytest]
DJANGO_SETTINGS_MODULE=pretix.testutils.settings

14
setup.cfg Normal file
View file

@ -0,0 +1,14 @@
[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 = 5
not_skip = __init__.py
skip = setup.py

44
setup.py Normal file
View file

@ -0,0 +1,44 @@
import os
from distutils.command.build import build
from django.core import management
from setuptools import setup, find_packages
try:
with open(os.path.join(os.path.dirname(__file__), 'README.rst'), encoding='utf-8') as f:
long_description = f.read()
except:
long_description = ''
class CustomBuild(build):
def run(self):
management.call_command('compilemessages', verbosity=1, interactive=False)
build.run(self)
cmdclass = {
'build': CustomBuild
}
setup(
name='pretix-servicefees',
version='1.0.0',
description='Allows you to impose a service fee on all non-free orders.',
long_description=long_description,
url='https://github.com/pretix/pretix-servicefees',
author='Raphael Michel',
author_email='michel@rami.io',
license='Apache Software License',
install_requires=[],
packages=find_packages(exclude=['tests', 'tests.*']),
include_package_data=True,
cmdclass=cmdclass,
entry_points="""
[pretix.plugin]
pretix_servicefees=pretix_servicefees:PretixPluginMeta
""",
)