Skip to content

Commit

Permalink
Added field for organization that defaults to any named SAC
Browse files Browse the repository at this point in the history
  • Loading branch information
imaegg11 committed Nov 1, 2024
1 parent 50478a7 commit 5aeb97c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,12 @@ def late_start_view(self, request):
start_date = datetime.combine(start_date_value, time(hour=10))
end_date = datetime.combine(start_date_value, time(hour=10, second=1))

organization = form.cleaned_data.get('organization')

data = {
'name': 'Late Start',
'term': models.Term.get_current(start_date),
'organization': models.Organization.objects.get(name='SAC'),
'organization': organization,
'schedule_format': 'late-start',
'start_date': start_date,
'end_date': end_date
Expand Down
13 changes: 13 additions & 0 deletions core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,19 @@ class UserCreationAdminForm(CaseInsensitiveUsernameMixin, ContribAdminUserCreati

class LateStartEventForm(forms.Form):
start_date = forms.DateField(widget=AdminDateWidget())
organization = forms.ModelChoiceField(
queryset=models.Organization.objects.all(),
required=True
)

def __init__(self, *args, **kwargs):
super(LateStartEventForm, self).__init__(*args, **kwargs)

try:
self.fields["organization"].initial = models.Organization.objects.get(name='SAC')
except models.Organization.DoesNotExist:
pass


def clean(self):
cleaned_data = super().clean()
Expand Down
9 changes: 9 additions & 0 deletions templates/admin/custom_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
{% block content %}
<form action="{{ url }}" method="post">
{% csrf_token %}
{% if form.errors %}
<p class="errornote">
{% if form.errors|length == 1 %}
{% translate "Please correct the error below." %}
{% else %}
{% translate "Please correct the errors below." %}
{% endif %}
</p>
{% endif %}
<fieldset class="module aligned ">
{% for field in form %}
<div class="form-row field-name">
Expand Down

0 comments on commit 5aeb97c

Please sign in to comment.