Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
Applied fixes supplied by @oberrauch
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Jan 15, 2023
1 parent c0fd4c8 commit 00ee9ed
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 1,767 deletions.
43 changes: 30 additions & 13 deletions meetings/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db.models import Q
from django.utils.translation import get_language
from django.utils.translation import gettext_lazy as _
from django.utils.formats import get_format

from toptool.forms import UserChoiceField, UserDualListField

Expand Down Expand Up @@ -101,7 +102,7 @@ def __init__(self, *args, **kwargs):
setup_time_formats(self.fields["topdeadline"])
# conditionally hide some fields
if not self.meetingtype.protokoll:
self.fields["minute_takers"].widget = forms.HiddenInput()
self.fields["minute_takers"].widget = forms.MultipleHiddenInput()
if not self.meetingtype.tops or not self.meetingtype.top_deadline:
self.fields["topdeadline"].widget = forms.HiddenInput()

Expand All @@ -125,26 +126,42 @@ def setup_time_formats(field):
@param field: a DateTimeField
@return: a DateTimeField with the time formats set
"""
field.input_formats = ["%d.%m.%Y %H:%M", "%m/%d/%Y %I:%M %p"]
field.widget.format = "%m/%d/%Y %I:%M %p" if get_language() == "en" else "%d.%m.%Y %H:%M"
locale_format = get_format('DATETIME_INPUT_FORMATS', lang=get_language())
field.input_formats = locale_format
field.widget.format = get_appropriate_format(locale_format)


def get_localized_formats(field_type: str):
return get_format(field_type, lang=get_language())


def get_appropriate_format(formats: list):
filtered = [f for f in formats if is_appropriate_format(f)]
assert (len(filtered) > 0)
return filtered[0]


def is_appropriate_format(date_format: str):
# we filter matching formats:
# - we don't need seconds,
# - want hours (and minutes),
# - want the long year and
# - don't want to start with the year
return "%S" not in date_format and "%H" in date_format and "%Y" in date_format and not date_format.startswith("%Y")


class MeetingSeriesForm(forms.Form):
locale_formats = get_localized_formats('DATETIME_INPUT_FORMATS')
locale_format = get_appropriate_format(locale_formats)
start = forms.DateTimeField(
input_formats=[
"%d.%m.%Y %H:%M",
"%m/%d/%Y %I:%M %p",
],
widget=DateTimePickerInput(format="%d.%m.%Y %H:%M"),
input_formats=locale_formats,
widget=DateTimePickerInput(format=locale_format),
label=_("Start"),
)

end = forms.DateTimeField(
input_formats=[
"%d.%m.%Y %H:%M",
"%m/%d/%Y %I:%M %p",
],
widget=DateTimePickerInput(format="%d.%m.%Y %H:%M"),
input_formats=locale_formats,
widget=DateTimePickerInput(format=locale_format),
label=_("Ende"),
)

Expand Down
8 changes: 4 additions & 4 deletions meetings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ def min_takers_mail_joined(self) -> str:
@return: pretty-format/join all the e-mail addresses of the min_takers
"""
min_takers = [minute_taker.email for minute_taker in self.minute_takers.all() if minute_taker.email]
return ", ".join(min_takers) or _("Kein/e Protokollant/in bestimmt")
return ", ".join(min_takers) or _("Kein*e Protokollant*in bestimmt")

@property
def min_takers_str_protokill(self) -> str:
def min_takers_str_protokoll(self) -> str:
"""
Refer to the Protokoll if imported, else pretty-format/join all the min_takers.
This method should be used in protokoll, as referring to a protokol makes no sense here.
@see Meeting.min_takers_str_html
@return: string referring to min_takers
"""
min_takers: list[str] = [minute_taker.get_full_name() for minute_taker in self.minute_takers.all()]
return ", ".join(min_takers) or _("Kein/e Protokollant/in bestimmt")
return ", ".join(min_takers) or _("Kein*e Protokollant*in bestimmt")

@property
def min_takers_str_html(self):
Expand All @@ -121,7 +121,7 @@ def min_takers_str_html(self):
"""
if self.imported:
return _("siehe Protokoll")
return self.min_takers_str_protokill
return self.min_takers_str_protokoll

@property
def previous(self):
Expand Down
10 changes: 6 additions & 4 deletions meetings/templates/meetings/add.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h1>{% trans "Sitzung erstellen" %}</h1>
</form>
<script src="{% static "moment/min/moment.min.js" %}"></script>
<script>
{# JS for dual list box #}
/* {# JS for dual list box #}
$(() => {
// activate DualListbox
$('.duallistbox').bootstrapDualListbox({
Expand All @@ -48,6 +48,7 @@ <h1>{% trans "Sitzung erstellen" %}</h1>
infoTextEmpty: '{% trans "Liste leer" %}',
});
});
*/
function htmlToElement(html) {
const template = document.createElement('template');
template.innerHTML = html.trim(); // trimmed to never return a text node of whitespace as the result
Expand All @@ -59,12 +60,12 @@ <h1>{% trans "Sitzung erstellen" %}</h1>
if (topdeadline.getAttribute('type') !== 'hidden') {
topdeadline.after(
htmlToElement(
'<a href="#" class="btn btn-secondary" onclick="relativeTOPDeadline(-1); return false;">/* trans "1 Stunde vor der Sitzung" */</a>',
'<a href="#" class="btn btn-secondary" onclick="relativeTOPDeadline(-1); return false;">{% trans "1 Stunde vor der Sitzung" %}</a>',
),
);
topdeadline.after(
htmlToElement(
'<a href="#" class="btn btn-secondary" onclick="relativeTOPDeadline(-24); return false;">/* trans "1 Tag vor der Sitzung" */</a>',
'<a href="#" class="btn btn-secondary" onclick="relativeTOPDeadline(-24); return false;">{% trans "1 Tag vor der Sitzung" %}</a>',
),
);
}
Expand All @@ -79,8 +80,9 @@ <h1>{% trans "Sitzung erstellen" %}</h1>
document.getElementById('id_topdeadline').value = time.format(timeFmt);
}

module.exports = {
/* module.exports = {
relativeTOPDeadline,
};
*/
</script>
{% endblock %}
4 changes: 2 additions & 2 deletions meetings/templates/meetings/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h1>{% trans "Sitzung bearbeiten" %}</h1>
</div>
</form>
<script src="{% static "moment/min/moment.min.js" %}"></script>
<script>
<!--<script>
{# JS for dual list box #}
$(() => {
// activate DualListbox
Expand Down Expand Up @@ -83,5 +83,5 @@ <h1>{% trans "Sitzung bearbeiten" %}</h1>
module.exports = {
relativeTOPDeadline,
};
</script>
</script>-->
{% endblock %}
Loading

0 comments on commit 00ee9ed

Please sign in to comment.