Skip to content

Commit

Permalink
Made accessible from events page (More templates!!!)
Browse files Browse the repository at this point in the history
  • Loading branch information
imaegg11 committed Nov 6, 2024
1 parent 5aeb97c commit 2606157
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
37 changes: 33 additions & 4 deletions core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,24 @@ class EventAdmin(CustomTimeMixin, admin.ModelAdmin):
list_filter = [OrganizationListFilter]
ordering = ["-start_date", "-end_date"]
search_fields = ["name"]
change_list_template = 'admin/change_list_custom_buttons.html'

def changelist_view(self, request, extra_context=None):
extra_context = extra_context or {}
extra_context['buttons'] = [
{
'name': 'Add Late Start',
'url': reverse('admin:late_start'),
},
]
return super().changelist_view(request, extra_context=extra_context)

def get_urls(self):
return [
path(
"createLateStart/",
self.admin_site.admin_view(self.late_start_view)
self.admin_site.admin_view(self.late_start_view),
name="late_start"
),
*super().get_urls(),
]
Expand All @@ -586,17 +598,34 @@ 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': organization,
'schedule_format': 'late-start',
'start_date': start_date,
'end_date': end_date
}

try:
data["organization"] = models.Organization.objects.get(name='SAC')
except models.Organization.DoesNotExist:

earliest_superuser = models.User.objects.filter(is_superuser=True).earliest("date_joined")

organization_data = {
'bio': 'WLMAC Student Activity Council',
'is_open': False,
'name': 'SAC',
'slug': 'wlmac',
'owner': earliest_superuser
}

sac_org = models.Organization.objects.create(**organization_data)
sac_org.execs.add(earliest_superuser)
sac_org.save()

data["organization"] = sac_org

models.Event.objects.create(**data)
return redirect("/admin/core/event")
else:
Expand Down
13 changes: 0 additions & 13 deletions core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,6 @@ 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
2 changes: 1 addition & 1 deletion core/models/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def get_events(cls, user=None):
return events

def clean(self):
if self.start_date != None and self.end_date != None and self.start_date > self.end_date:
if self.start_date > self.end_date:
raise ValidationError(
{
"start_date": _("Start date must be before end date"),
Expand Down
10 changes: 10 additions & 0 deletions templates/admin/change_list_buttons.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "admin/change_list.html" %}
{% load i18n admin_urls static admin_list %}
{% block object-tools-items %}
{% for button in buttons %}
<li>
<a href="{{ button.url }}" class="grp-state-focus addlink">{{ button.name }}</a>
</li>
{% endfor %}
{{ block.super }}
{% endblock %}

0 comments on commit 2606157

Please sign in to comment.