Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.6 #40

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

1.6 #40

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/juntagrico-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ jobs:
CC_TEST_REPORTER_ID: ${{ secrets.CODECOV_TOKEN }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: install dependencies
run: |
pip install --root-user-action=ignore --upgrade -r requirements-local.txt
- name: flake 8
pip install --root-user-action=ignore --upgrade -r requirements.txt
- name: ruff
run: |
flake8 --count --ignore E501 juntagrico_custom_sub
flake8 --count --ignore E501 test
ruff check juntagrico_custom_sub
ruff check test
- name: install CodeClimate reporter
if: ${{ env.CC_TEST_REPORTER_ID != null && github.event_name == 'push'}}
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install dependencies
Expand All @@ -28,7 +28,7 @@ jobs:
- name: Build package
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
Expand All @@ -46,7 +46,7 @@ jobs:

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ Install juntagrico-badge via `pip`

or add it in your projects `requirements.txt`

In `settings.py` add `'juntagrico_custom_sub',`.
In `settings.py` add `'juntagrico_custom_sub',`, *above* `'juntagrico'`.

```python
INSTALLED_APPS = [
...
'juntagrico',
'juntagrico_custom_sub',
'juntagrico',
]
```

Expand Down
3 changes: 1 addition & 2 deletions juntagrico_custom_sub/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
name = 'juntagrico-custom-sub'
version = '0.3.0'
__version__ = '1.6.0'
5 changes: 5 additions & 0 deletions juntagrico_custom_sub/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.contrib import admin
from juntagrico.admins import BaseAdmin
from juntagrico.entity.subtypes import SubscriptionSize
from juntagrico.util import addons

from juntagrico_custom_sub.entity.custom_delivery import CustomDelivery, CustomDeliveryProduct
from juntagrico_custom_sub.entity.product import Product
Expand Down Expand Up @@ -71,3 +73,6 @@ class CustomDeliveryProductAdmin(BaseAdmin):
admin.site.register(Product, CustomDeliveryProductAdmin)
admin.site.register(SubscriptionContent, SubscriptionContentAdmin)
admin.site.register(CustomDelivery, CustomDeliveryAdmin)

# extend the inline of SubscriptionSize
addons.config.register_model_inline(SubscriptionSize, MandatoryProductInline)
13 changes: 13 additions & 0 deletions juntagrico_custom_sub/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,16 @@
class JuntagricoCustomSubAppconfig(AppConfig):
name = "juntagrico_custom_sub"
default_auto_field = 'django.db.models.AutoField'

def ready(self):
from juntagrico.util import addons
addons.config.register_version(self.name)

# for compatibility to downgraded subscription views
addons.config.register_sub_overview('cs/hooks/subscription_content_overview.html')
addons.config.register_sub_change('cs/hooks/subscription_content_change.html')

# Basimilch specific
from juntagrico.forms import SubscriptionPartBaseForm
from juntagrico_custom_sub.basimilch import quantity_error
SubscriptionPartBaseForm.validators.append(quantity_error)
38 changes: 38 additions & 0 deletions juntagrico_custom_sub/basimilch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.core.exceptions import ValidationError
from juntagrico.entity.subtypes import SubscriptionType


def quantity_error(form):
"""
validates the selected quantities for Basimilch's usecase
selected is a dictionnary with SubscriptionType objects as keys and amounts as values
"""
present4 = 0
present8 = 0
present2 = 0

if hasattr(form, 'subscription'):
active_parts = form.subscription.active_and_future_parts
present4 = active_parts.filter(type__size__units=4).count()
present8 = active_parts.filter(type__size__units=8).count()
present2 = active_parts.filter(type__size__units=2).count()

selected = form.get_selected()
selected4 = selected[SubscriptionType.objects.get(size__units=4)]
selected8 = selected[SubscriptionType.objects.get(size__units=8)]
selected2 = selected[SubscriptionType.objects.get(size__units=2)]

totalNew4 = present4 + selected4
totalNew8 = present8 + selected8
totalNew2 = present2 + selected2

total_liters = totalNew4 * 4 + totalNew8 * 8 + totalNew2 * 2
if total_liters == 2:
raise ValidationError("Falls ein Abo gewünscht ist, müssen mindestens 4 Liter in einem Abo sein.")
required8 = total_liters // 8
required4 = (total_liters % 8) // 4
if not (totalNew8 == required8 and totalNew4 == required4):
raise ValidationError(
"Du musst immer die grösstmögliche Abogrösse nehmen. "
"Es ist zum Beispiel nicht möglich, 8 Liter auf zwei Vierliter-Abos aufzuteilen."
)
10 changes: 10 additions & 0 deletions juntagrico_custom_sub/downgrade/urls_1_5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
""" include this if you include juntagrico.downgrade.urls_1_5
"""
from django.urls import path

from juntagrico_custom_sub.downgrade import views_1_5

urlpatterns = [
# urls overriden from core to make the management of custom composition of subscriptions possible
path('my/subscription/change/size/<int:subscription_id>/', views_1_5.size_change, name='size-change'),
]
35 changes: 35 additions & 0 deletions juntagrico_custom_sub/downgrade/views_1_5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.shortcuts import get_object_or_404, redirect, render

from juntagrico.config import Config
from juntagrico.dao.subscriptiontypedao import SubscriptionTypeDao
from juntagrico.view_decorators import primary_member_of_subscription
from juntagrico.entity.subs import Subscription
from juntagrico.util import temporal
from juntagrico.util.management import create_subscription_parts

from juntagrico.forms import SubscriptionPartOrderForm


@primary_member_of_subscription
def size_change(request, subscription_id):
"""
Overriden from core
change the size of a subscription
"""
subscription = get_object_or_404(Subscription, id=subscription_id)
if request.method == 'POST':
form = SubscriptionPartOrderForm(subscription, request.POST)
if form.is_valid():
create_subscription_parts(subscription, form.get_selected(), True)
return redirect("content_edit", subscription_id=subscription_id)
else:
form = SubscriptionPartOrderForm()
renderdict = {
'form': form,
'subscription': subscription,
'hours_used': Config.assignment_unit() == 'HOURS',
'next_cancel_date': temporal.next_cancelation_date(),
'parts_order_allowed': not subscription.canceled,
'can_change_part': SubscriptionTypeDao.get_normal_visible().count() > 1
}
return render(request, 'size_change.html', renderdict)
12 changes: 0 additions & 12 deletions juntagrico_custom_sub/juntagricoapp.py

This file was deleted.

12 changes: 12 additions & 0 deletions juntagrico_custom_sub/templates/createsubscription/summary.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "createsubscription/summary.html" %}
{% load i18n %}
{% load juntagrico.config %}
{% load crispy_forms_tags %}
{% block subscription %}
{{ block.super }}

<h4>{% trans "Inhalt" %} <a href="{% url 'custom_sub_initial_select' %}" class="edit"><i class="fas fa-pen"></i></a></h4>
{% for product, amount in custom_prod.items %}
<b>{{ amount }}</b>&times; {{ product|striptags }}<br>
{% endfor %}
{% endblock %}
Empty file.
6 changes: 4 additions & 2 deletions juntagrico_custom_sub/templates/cs/content_edit_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ <h3>{% vocabulary "subscription" %} Zusammenstellung</h3>

{% block content %}
<div class="alert alert-success" role="alert">
Der Inhalt deines {% vocabulary "subscription" %}s wurde gespeichert. <br/> <a href='/my/subscription/detail/'>
Zurück zur {% vocabulary "subscription" %}-Übersicht </a>
Der Inhalt deines {% vocabulary "subscription" %}s wurde gespeichert. <br/>
<a href="{% url 'subscription-landing' %}">
Zurück zur {% vocabulary "subscription" %}-Übersicht
</a>
</div>
{% endblock %}

This file was deleted.

5 changes: 0 additions & 5 deletions juntagrico_custom_sub/templates/cs/initial_select_size.html

This file was deleted.

108 changes: 0 additions & 108 deletions juntagrico_custom_sub/templates/cs/initial_summary.html

This file was deleted.

33 changes: 33 additions & 0 deletions juntagrico_custom_sub/templates/cs/snippets/content_overview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% load i18n %}
<div class="row mb-5 custom-sub">
<div class="col-md-3">
{% trans "Inhalt" %}
</div>
<div class="col-md-9">
{% if subscription.content.content_changed %}
<strong>{% trans "Aktuell" %}</strong>
{% endif %}
<ul>
{% for content in subscription.content.display_content %}
<li>{{ content }}</li>
{% endfor %}
</ul>
{% if subscription.content.content_changed %}
<strong>{% trans "Zukünftig" %}</strong>
<ul>
{% for content in subscription.content.display_future_content %}
<li>{{ content }}</li>
{% endfor %}
</ul>
{% endif %}
{% block edit_info %}
<p>
{% trans "Deine Bedürfnisse haben sich geändert und du möchtest die Zusammenstellung deines Abos ändern?" %}<br>
{% trans "Du kannst diese jederzeit ändern - die Änderung werden drei mal jahrlich jeweils Anfang Jahr, ende April und mitte August aktiv." %}
</p>
{% endblock %}
<a href="{% url 'content_edit' subscription.id %}" class="btn btn-success">
{% blocktrans %}Inhalt ändern{% endblocktrans %}
</a>
</div>
</div>
Loading
Loading