Skip to content

Commit

Permalink
Merge branch 'master' into feature/#71/keycloak-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveratfoodcoopx committed Dec 19, 2022
2 parents b1deae8 + c250aa1 commit 2474b55
Show file tree
Hide file tree
Showing 44 changed files with 266 additions and 64 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
no-cache: true
build-args: TAPIR_VERSION=${{ github.sha }}
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM python:3.10
ARG TAPIR_VERSION
ENV TAPIR_VERSION=$TAPIR_VERSION
ENV PYTHONUNBUFFERED=1
WORKDIR /app
COPY . /app

RUN apt update -y && apt install -y libldap2-dev libsasl2-dev gettext

RUN pip install poetry && poetry install && poetry run python manage.py compilemessages
RUN echo "Building Tapir Version: $TAPIR_VERSION" && pip install poetry && poetry install && poetry run python manage.py compilemessages
2 changes: 1 addition & 1 deletion tapir/accounts/templates/accounts/user_detail.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "accounts/base.html" %}

{% load django_bootstrap5 %}
{% load static %}
{% load tapir_static %}
{% load i18n %}
{% load log %}
{% load accounts %}
Expand Down
2 changes: 1 addition & 1 deletion tapir/accounts/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "core/base.html" %}

{% load django_bootstrap5 %}
{% load static %}
{% load tapir_static %}
{% load i18n %}

{% block head %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "core/base.html" %}

{% load django_bootstrap5 %}
{% load static %}
{% load tapir_static %}
{% load i18n %}

{% block content %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "core/base.html" %}

{% load django_bootstrap5 %}
{% load static %}
{% load tapir_static %}
{% load i18n %}

{% block content %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "core/base.html" %}

{% load django_bootstrap5 %}
{% load static %}
{% load tapir_static %}
{% load i18n %}

{% block content %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "core/base.html" %}

{% load django_bootstrap5 %}
{% load static %}
{% load tapir_static %}
{% load i18n %}

{% block content %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% load django_bootstrap5 %}
{% load i18n %}
{% load static %}
{% load tapir_static %}

{% block content %}
<div style="margin-top: 2em; margin-bottom: 1em" class="container">
Expand Down
2 changes: 1 addition & 1 deletion tapir/core/templates/core/base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load django_bootstrap5 %}
{% load static %}
{% load tapir_static %}
{% load i18n %}
{% load core %}

Expand Down
3 changes: 2 additions & 1 deletion tapir/core/templatetags/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.utils.translation import gettext_lazy as _

from tapir.core.models import SidebarLinkGroup
from tapir.wirgarten.constants import Permission # FIXME: circular dependency :(

register = template.Library()

Expand All @@ -23,7 +24,7 @@ def sidebar_links(context):
def get_sidebar_link_groups(request):
groups = []

if request.user.has_perm("coop.admin"):
if request.user.has_perm(Permission.Coop.VIEW):
add_admin_links(groups)

# misc_group = SidebarLinkGroup(name=_("Miscellaneous"))
Expand Down
163 changes: 163 additions & 0 deletions tapir/core/templatetags/tapir_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
from urllib.parse import quote, urljoin

from django import template
from django.apps import apps
from django.utils.encoding import iri_to_uri
from django.utils.html import conditional_escape

from tapir import settings

register = template.Library()


# copied from django/templatetags/static.py
# and adjusted to attach a version string for cache busting
class PrefixNode(template.Node):
def __repr__(self):
return "<PrefixNode for %r>" % self.name

def __init__(self, varname=None, name=None):
if name is None:
raise template.TemplateSyntaxError(
"Prefix nodes must be given a name to return."
)
self.varname = varname
self.name = name

@classmethod
def handle_token(cls, parser, token, name):
"""
Class method to parse prefix node and return a Node.
"""
# token.split_contents() isn't useful here because tags using this
# method don't accept variable as arguments.
tokens = token.contents.split()
if len(tokens) > 1 and tokens[1] != "as":
raise template.TemplateSyntaxError(
"First argument in '%s' must be 'as'" % tokens[0]
)
if len(tokens) > 1:
varname = tokens[2]
else:
varname = None
return cls(varname, name)

@classmethod
def handle_simple(cls, name):
try:
from django.conf import settings
except ImportError:
prefix = ""
else:
prefix = iri_to_uri(getattr(settings, name, ""))
return prefix

def render(self, context):
prefix = self.handle_simple(self.name)
if self.varname is None:
return prefix
context[self.varname] = prefix
return ""


@register.tag
def get_static_prefix(parser, token):
"""
Populate a template variable with the static prefix,
``settings.STATIC_URL``.
Usage::
{% get_static_prefix [as varname] %}
Examples::
{% get_static_prefix %}
{% get_static_prefix as static_prefix %}
"""
return PrefixNode.handle_token(parser, token, "STATIC_URL")


@register.tag
def get_media_prefix(parser, token):
"""
Populate a template variable with the media prefix,
``settings.MEDIA_URL``.
Usage::
{% get_media_prefix [as varname] %}
Examples::
{% get_media_prefix %}
{% get_media_prefix as media_prefix %}
"""
return PrefixNode.handle_token(parser, token, "MEDIA_URL")


class StaticNode(template.Node):
child_nodelists = ()

def __init__(self, varname=None, path=None):
if path is None:
raise template.TemplateSyntaxError(
"Static template nodes must be given a path to return."
)
self.path = path
self.varname = varname

def __repr__(self):
return (
f"{self.__class__.__name__}(varname={self.varname!r}, path={self.path!r})"
)

def url(self, context):
path = self.path.resolve(context)
return f"{self.handle_simple(path)}?v={settings.TAPIR_VERSION}"

def render(self, context):
url = self.url(context)
if context.autoescape:
url = conditional_escape(url)
if self.varname is None:
return url
context[self.varname] = url
return ""

@classmethod
def handle_simple(cls, path):
if apps.is_installed("django.contrib.staticfiles"):
from django.contrib.staticfiles.storage import staticfiles_storage

return staticfiles_storage.url(path)
else:
return urljoin(PrefixNode.handle_simple("STATIC_URL"), quote(path))

@classmethod
def handle_token(cls, parser, token):
"""
Class method to parse prefix node and return a Node.
"""
bits = token.split_contents()

if len(bits) < 2:
raise template.TemplateSyntaxError(
"'%s' takes at least one argument (path to file)" % bits[0]
)

path = parser.compile_filter(bits[1])

if len(bits) >= 2 and bits[-2] == "as":
varname = bits[3]
else:
varname = None

return cls(varname, path)


@register.tag("static")
def do_static(parser, token):
"""
Join the given path with the STATIC_URL setting.
Usage::
{% static path [as varname] %}
Examples::
{% static "myapp/css/base.css" %}
{% static variable_with_path %}
{% static "myapp/css/base.css" as admin_base_css %}
{% static variable_with_path as varname %}
"""
return StaticNode.handle_token(parser, token)
9 changes: 9 additions & 0 deletions tapir/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@

ALLOWED_HOSTS = env("ALLOWED_HOSTS", cast=list, default=["*"])

TAPIR_VERSION = env(
"TAPIR_VERSION", cast=str, default=os.environ.get("TAPIR_VERSION", "")
)
print(
f"Tapir Version: {TAPIR_VERSION}"
if TAPIR_VERSION
else "\033[93m>>> WARNING: TAPIR_VERSION is not set, cache busting will not work!\033[0m"
)

ENABLE_SILK_PROFILING = False

# Application definition
Expand Down
11 changes: 7 additions & 4 deletions tapir/wirgarten/forms/member/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.core.validators import (
EmailValidator,
)
from django.db.models import Sum

from tapir.configuration.parameter import get_parameter_value
from tapir.utils.forms import TapirPhoneNumberField, DateInput
Expand Down Expand Up @@ -91,7 +92,9 @@ def __init__(self, *args, **kwargs):
super(CoopShareTransferForm, self).__init__(*args)
member_id = kwargs["pk"]
orig_member = Member.objects.get(pk=member_id)
orig_share_ownership = ShareOwnership.objects.get(member_id=member_id)
orig_share_ownership_quantity = ShareOwnership.objects.filter(
member_id=member_id
).aggregate(quantity_sum=Sum("quantity"))["quantity_sum"]

def member_to_string(m):
return f"{m.first_name} {m.last_name} ({m.email})"
Expand All @@ -105,7 +108,7 @@ def member_to_string(m):

self.fields["origin"] = CharField(
label=_("Ursprünglicher Anteilseigner")
+ f" ({orig_share_ownership.quantity} Anteile)",
+ f" ({orig_share_ownership_quantity} Anteile)",
disabled=True,
initial=member_to_string(orig_member),
)
Expand All @@ -114,9 +117,9 @@ def member_to_string(m):
)
self.fields["quantity"] = IntegerField(
label=_("Anzahl der Anteile"),
initial=orig_share_ownership.quantity,
initial=orig_share_ownership_quantity,
min_value=1,
max_value=orig_share_ownership.quantity,
max_value=orig_share_ownership_quantity,
)
self.fields["security_check"] = BooleanField(
label=_("Ich weiß was ich tue und bin mir der Konsequenzen bewusst."),
Expand Down
Loading

0 comments on commit 2474b55

Please sign in to comment.