Skip to content

Commit

Permalink
Merge pull request #19 from fredagscafeen/Bootstrap5
Browse files Browse the repository at this point in the history
Bootstrap5
  • Loading branch information
AndersSeverinsen authored Oct 17, 2024
2 parents 8421444 + d07f64e commit 2f3bdd2
Show file tree
Hide file tree
Showing 38 changed files with 499 additions and 299 deletions.
2 changes: 1 addition & 1 deletion bartab/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from .models import BarTabSnapshot

Expand Down
2 changes: 1 addition & 1 deletion bartab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db.models import F, Sum, Value
from django.db.models.functions import Coalesce
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from bartenders.models import BartenderShift

Expand Down
2 changes: 1 addition & 1 deletion bartab/sumfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django import forms
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

SumValue = namedtuple("SumValue", ["string", "value"])

Expand Down
7 changes: 5 additions & 2 deletions bartenders/forms.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from urllib.parse import urljoin

from captcha.fields import ReCaptchaField
from django import forms
from django.conf import settings
from django.contrib.auth.models import User
from django.urls import reverse
from django.utils.safestring import mark_safe
from django_recaptcha.fields import ReCaptchaField
from django_recaptcha.widgets import ReCaptchaV2Invisible

from bartab.models import BarTabUser
from fredagscafeen.email import send_template_email
Expand All @@ -14,7 +15,7 @@


class BartenderApplicationForm(forms.ModelForm):
captcha = ReCaptchaField()
captcha = ReCaptchaField(widget=ReCaptchaV2Invisible)

class Meta:
model = BartenderApplication
Expand All @@ -23,6 +24,7 @@ class Meta:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["tshirt_size"].widget.attrs.update({"class": "form-control"})
for name in self.fields:
self.fields[name].required = name != "info"

Expand Down Expand Up @@ -81,6 +83,7 @@ class Meta:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.fields["tshirt_size"].widget.attrs.update({"class": "form-control"})
self.fields["username"].disabled = True

def save(self, *args, **kwargs):
Expand Down
49 changes: 49 additions & 0 deletions bartenders/migrations/0004_alter_bartender_tshirt_size_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated by Django 4.2 on 2024-10-17 19:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("bartenders", "0003_auto_20240915_2045"),
]

operations = [
migrations.AlterField(
model_name="bartender",
name="tshirt_size",
field=models.IntegerField(
blank=True,
choices=[
(0, "XS"),
(1, "S"),
(2, "M"),
(3, "L"),
(4, "XL"),
(5, "XXL"),
(6, "XXXL"),
],
null=True,
verbose_name="T-shirt størrelse",
),
),
migrations.AlterField(
model_name="bartenderapplication",
name="tshirt_size",
field=models.IntegerField(
blank=True,
choices=[
(0, "XS"),
(1, "S"),
(2, "M"),
(3, "L"),
(4, "XL"),
(5, "XXL"),
(6, "XXXL"),
],
null=True,
verbose_name="T-shirt størrelse",
),
),
]
35 changes: 35 additions & 0 deletions bartenders/migrations/0005_alter_bartender_email_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 5.1.2 on 2024-10-17 21:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("bartenders", "0004_alter_bartender_tshirt_size_and_more"),
]

operations = [
migrations.AlterField(
model_name="bartender",
name="email",
field=models.EmailField(
blank=True,
help_text="En post.au mail fungerer ikke",
max_length=254,
unique=True,
verbose_name="E-mail",
),
),
migrations.AlterField(
model_name="bartenderapplication",
name="email",
field=models.EmailField(
blank=True,
help_text="En post.au mail fungerer ikke",
max_length=254,
unique=True,
verbose_name="E-mail",
),
),
]
27 changes: 14 additions & 13 deletions bartenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from enum import IntEnum
from urllib.parse import urljoin

from django import forms
from django.conf import settings
from django.db import models
from django.db.models import Q
Expand All @@ -10,7 +11,7 @@
from django.urls import reverse
from django.utils import timezone
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from fredagscafeen.email import send_template_email

Expand All @@ -36,13 +37,13 @@ def date_format(dt, format):
# but we enforce that in BartenderApplicationForm for new applications.
class BartenderCommon(models.Model):
TSHIRT_SIZE_CHOICES = (
("XS", "XS"),
("S", "S"),
("M", "M"),
("L", "L"),
("XL", "XL"),
("XXL", "XXL"),
("XXXL", "XXXL"),
(0, "XS"),
(1, "S"),
(2, "M"),
(3, "L"),
(4, "XL"),
(5, "XXL"),
(6, "XXXL"),
)

class Meta:
Expand All @@ -52,8 +53,7 @@ class Meta:
username = models.CharField(
max_length=140, unique=True, verbose_name=_("Brugernavn")
)
email = models.CharField(
max_length=255,
email = models.EmailField(
unique=True,
blank=True,
verbose_name=_("E-mail"),
Expand All @@ -65,9 +65,8 @@ class Meta:
phoneNumber = models.IntegerField(
blank=True, null=True, verbose_name=_("Telefonnummer")
)
tshirt_size = models.CharField(
tshirt_size = models.IntegerField(
choices=TSHIRT_SIZE_CHOICES,
max_length=10,
blank=True,
null=True,
verbose_name=_("T-shirt størrelse"),
Expand Down Expand Up @@ -337,7 +336,9 @@ def next_bartender_shift_start(last_date=None):

next_date = next_date_with_weekday(last_date, Weekday.FRIDAY)
dt = datetime.datetime.combine(next_date, BartenderShift.DEFAULT_START_TIME)
return timezone.get_default_timezone().localize(dt)
tz = timezone.get_current_timezone()
aware_datetime = timezone.make_aware(dt, tz)
return aware_datetime


def next_bartender_shift_dates(count):
Expand Down
2 changes: 1 addition & 1 deletion bartenders/templates/ballots.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}

{% load static %}
{% load bootstrap3 %}
{% load bootstrap5 %}

{% block content %}

Expand Down
6 changes: 4 additions & 2 deletions bartenders/templates/ballots_update.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% load bootstrap3 %}
{% load bootstrap5 bootstrap_icons %}

{% block content %}

Expand All @@ -16,7 +16,9 @@ <h2>Tilføj poll</h2>
{% bootstrap_form form %}
{% buttons %}
{% translate "Gem" as BUTTON_TEXT %}
{% bootstrap_button BUTTON_TEXT button_type="submit" icon="floppy-disk" button_class="btn-primary" %}
<button type="submit" class="btn btn-primary" style="margin-top: 15px; margin-bottom: 15px;">
<i>{% bs_icon 'floppy2' size='1.0em' %}</i> {{ BUTTON_TEXT }}
</button>
{% endbuttons %}
</form>

Expand Down
10 changes: 7 additions & 3 deletions bartenders/templates/bartender_info.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% load bootstrap3 %}
{% load bootstrap5 bootstrap_icons %}

{% block extrahead %}
<script type="text/javascript">
Expand Down Expand Up @@ -39,7 +39,9 @@
{% csrf_token %}
{% buttons %}
{% translate "Gem" as BUTTON_TEXT %}
{% bootstrap_button BUTTON_TEXT button_type="submit" icon="floppy-disk" button_class="btn-primary" %}
<button type="submit" class="btn btn-primary" style="margin-top: 15px; margin-bottom: 15px;">
<i>{% bs_icon 'floppy2' size='1.0em' %}</i> {{ BUTTON_TEXT }}
</button>
{% endbuttons %}
<p><b>{% translate "Bartender status" %}:</b>
{% if object.isActiveBartender %}
Expand Down Expand Up @@ -87,7 +89,9 @@
</table>
{% buttons %}
{% translate "Gem" as BUTTON_TEXT %}
{% bootstrap_button BUTTON_TEXT button_type="submit" icon="floppy-disk" button_class="btn-primary" %}
<button type="submit" class="btn btn-primary" style="margin-top: 15px; margin-bottom: 15px;">
<i>{% bs_icon 'floppy2' size='1.0em' %}</i> {{ BUTTON_TEXT }}
</button>
{% endbuttons %}
</form>
{% else %}
Expand Down
6 changes: 4 additions & 2 deletions bartenders/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% load bootstrap3 %}
{% load bootstrap5 bootstrap_icons %}

{% block content %}

Expand All @@ -21,7 +21,9 @@ <h2>{% translate "Bartendertilmelding" %}</h2>
{% bootstrap_form form %}
{% buttons %}
{% translate "Indsend" as BUTTON_TEXT %}
{% bootstrap_button BUTTON_TEXT button_type="submit" icon="send" button_class="btn-primary" %}
<button type="submit" class="btn btn-primary" style="margin-top: 15px; margin-bottom: 15px;">
<i>{% bs_icon 'send-fill' size='1.0em' %}</i> {{ BUTTON_TEXT }}
</button>
{% endbuttons %}
</form>
{% else %}
Expand Down
4 changes: 2 additions & 2 deletions bartenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_accepting_application(self):
phoneNumber=42345123,
)
ap = BartenderApplication.objects.create(
**d, tshirt_size="L", study="Datalogi", study_year=1
**d, tshirt_size=2, study="Datalogi", study_year=1
)
ap.accept()

Expand Down Expand Up @@ -66,7 +66,7 @@ def test_sending_application(self):
email="[email protected]",
studentNumber=123123,
phoneNumber=12312312,
tshirt_size="L",
tshirt_size=2,
study="Datalogi",
study_year=1,
info="Hkll",
Expand Down
2 changes: 1 addition & 1 deletion bartenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.db import IntegrityError
from django.shortcuts import get_object_or_404, redirect, reverse
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.views.generic import (
CreateView,
FormView,
Expand Down
2 changes: 1 addition & 1 deletion events/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from bartenders.models import Bartender

Expand Down
6 changes: 5 additions & 1 deletion events/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from .models import EventChoiceOption, EventResponse

Expand Down Expand Up @@ -58,6 +58,9 @@ def __init__(self, *args, event, bartender, **kwargs):
self.fields["attending"] = forms.TypedChoiceField(
label=_("Deltager"), choices=attending_choices, coerce=self._to_bool
)
for field in self.fields.values():
field.widget.attrs.update({"class": "form-control"})

if event_response:
self.fields["attending"].initial = event_response.attending

Expand All @@ -68,6 +71,7 @@ def __init__(self, *args, event, bartender, **kwargs):
required=False,
widget=SelectWithDisabledOptions(is_enabled=self._option_enabled),
)
field.widget.attrs.update({"class": "form-control"})
if event_response:
field.initial = event_response.get_option(choice)

Expand Down
6 changes: 4 additions & 2 deletions events/templates/events.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html' %}

{% load bootstrap3 %}
{% load bootstrap5 bootstrap_icons %}

{% block content %}
{% load i18n %}
Expand Down Expand Up @@ -47,7 +47,9 @@ <h4>{% translate "Tilmelding" %}</h4>
{% bootstrap_form events_data.form %}
{% buttons %}
{% translate "Gem" as BUTTON_TEXT %}
{% bootstrap_button BUTTON_TEXT button_type="submit" icon="floppy-disk" button_class="btn-primary" %}
<button type="submit" class="btn btn-primary" style="margin-top: 15px; margin-bottom: 15px;">
<i>{% bs_icon 'floppy2' size='1.0em' %}</i> {{ BUTTON_TEXT }}
</button>
{% endbuttons %}
</fieldset>
</form>
Expand Down
2 changes: 1 addition & 1 deletion events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib import messages
from django.http import HttpResponseBadRequest, HttpResponseForbidden
from django.shortcuts import redirect
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView
from django_ical.views import ICalFeed

Expand Down
Loading

0 comments on commit 2f3bdd2

Please sign in to comment.