From ff7e3ae308d3047b49cbfa52855778fc8fac6f20 Mon Sep 17 00:00:00 2001 From: Stefan Dworschak Date: Tue, 29 Dec 2020 00:16:28 +0000 Subject: [PATCH 1/3] Adding missing fields to create form and extra info to list view --- hackathon/forms.py | 29 ++++++++++++++++--- .../templates/hackathon/create-event.html | 9 ++++++ .../hackathon/includes/hackathon_card.html | 9 +++--- hackathon/views.py | 4 ++- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/hackathon/forms.py b/hackathon/forms.py index 8603735e..56f5a0ee 100644 --- a/hackathon/forms.py +++ b/hackathon/forms.py @@ -1,6 +1,8 @@ from django import forms -from .models import Hackathon +from accounts.models import Organisation +from .models import Hackathon +from .lists import STATUS_TYPES_CHOICES, JUDGING_STATUS_CHOICES class HackathonForm(forms.ModelForm): """ A form to enable users to add hackathon events via the frontend site. @@ -25,8 +27,7 @@ class HackathonForm(forms.ModelForm): 'rows': 3, 'placeholder': 'Tell us more about this event...' } - ), - required=True + ) ) theme = forms.CharField( label='Theme', @@ -63,7 +64,27 @@ class HackathonForm(forms.ModelForm): } ), ) + status = forms.CharField( + label="Status", + required=True, + widget=forms.Select(choices=STATUS_TYPES_CHOICES), + ), + judging_status = forms.CharField( + label="Judging Status", + required=True, + widget=forms.Select(choices=JUDGING_STATUS_CHOICES), + ), + organisation = forms.ModelChoiceField( + label="Organisation", + queryset=Organisation.objects.order_by('display_name'), + ), class Meta: model = Hackathon - fields = ['display_name', 'description', 'theme', 'start_date', 'end_date'] + fields = ['display_name', 'description', 'theme', 'start_date', + 'end_date', 'status', 'judging_status', 'organisation', + ] + + def __init__(self, *args, **kwargs): + super(HackathonForm, self).__init__(*args, **kwargs) + self.fields['organisation'].empty_label = None diff --git a/hackathon/templates/hackathon/create-event.html b/hackathon/templates/hackathon/create-event.html index ff3bc822..e6a50881 100644 --- a/hackathon/templates/hackathon/create-event.html +++ b/hackathon/templates/hackathon/create-event.html @@ -34,6 +34,15 @@

Create Hackathon

{{ form.theme|as_crispy_field }}
+
+ {{ form.organisation|as_crispy_field }} +
+
+ {{ form.status|as_crispy_field }} +
+
+ {{ form.judging_status|as_crispy_field }} +
{{ form.start_date|as_crispy_field }}
diff --git a/hackathon/templates/hackathon/includes/hackathon_card.html b/hackathon/templates/hackathon/includes/hackathon_card.html index 50469980..c69bd28d 100644 --- a/hackathon/templates/hackathon/includes/hackathon_card.html +++ b/hackathon/templates/hackathon/includes/hackathon_card.html @@ -1,10 +1,11 @@
-
{{ hackathon.display_name }}
+
{{ hackathon.display_name }} {% if user.user_type != 'participant' %}{{hackathon.status}} {% endif %}

{{ hackathon.start_date }} - {{ hackathon.end_date }}

-

{{ hackathon.description }}

- {% if hackathon.organiser %} -

Organiser: {{ hackathon.organiser }}

+

Organised for {{ hackathon.organisation }}

+ {% if user.user_type != 'participant' %} +

+ Participants: {{ hackathon.participants.all|length }} / Teams: {{ hackathon.teams.all|length }}

{% endif %} Read More diff --git a/hackathon/views.py b/hackathon/views.py index 9b6e3246..c1e420a9 100644 --- a/hackathon/views.py +++ b/hackathon/views.py @@ -150,12 +150,13 @@ def create_hackathon(request): return redirect("hackathon:hackathon-list") template = "hackathon/create-event.html" - form = HackathonForm() + form = HackathonForm(initial={'organisation': 1}) return render(request, template, {"form": form}) else: form = HackathonForm(request.POST) + # Convert start and end date strings to datetime and validate start_date = datetime.strptime( request.POST.get('start_date'), '%d/%m/%Y %H:%M') @@ -178,6 +179,7 @@ def create_hackathon(request): # Submit form and save record if form.is_valid(): form.instance.created_by = request.user + form.instance.organiser = request.user form.save() messages.success( request, 'Thanks for submitting a new Hackathon event!') From 8ccb6550b899b216da2edf1344c3acddd5f8fa9f Mon Sep 17 00:00:00 2001 From: Stefan Dworschak Date: Tue, 5 Jan 2021 23:26:44 +0000 Subject: [PATCH 2/3] fixing some linting --- hackathon/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/hackathon/views.py b/hackathon/views.py index c1e420a9..9b9d9c24 100644 --- a/hackathon/views.py +++ b/hackathon/views.py @@ -156,7 +156,6 @@ def create_hackathon(request): else: form = HackathonForm(request.POST) - # Convert start and end date strings to datetime and validate start_date = datetime.strptime( request.POST.get('start_date'), '%d/%m/%Y %H:%M') From 1650c568d22d19b1efbf2794dbd1cd35d473117b Mon Sep 17 00:00:00 2001 From: Stefan Dworschak Date: Wed, 6 Jan 2021 21:34:24 +0000 Subject: [PATCH 3/3] Fixing home template --- home/templates/home/index.html | 52 ++++++++++++++++------------------ 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/home/templates/home/index.html b/home/templates/home/index.html index a62a0c8c..9840935f 100644 --- a/home/templates/home/index.html +++ b/home/templates/home/index.html @@ -5,39 +5,37 @@
+ {% if hackathons %}

Upcoming Hackathons

- {% if hackathons %} - {% for hackathon in hackathons %} - {% if hackathon.status == 'published' or user == hackathon.created_by %} - {% if hackathon.organisation.id == 1 or hackathon.organisation == user.organisation %} - {% if not hackathon.status == 'deleted' %} -
-
- -
{{ hackathon.display_name }}
-
-
-
-
- -
Start: {{ hackathon.start_date }} - End: {{ hackathon.end_date }}
-

{{ hackathon.description }}

- {% if hackathon.organiser %} -

Organiser: {{ hackathon.organiser }}

- {% endif %} - Read More -
-
+ {% for hackathon in hackathons %} + {% if hackathon.status == 'published' %} + {% if hackathon.organisation.id == 1 or hackathon.organisation == user.organisation %} + {% if not hackathon.status == 'deleted' %} +
+
+ +
{{ hackathon.display_name }}
+
+
+
+
+
Start: {{ hackathon.start_date }} - End: {{ hackathon.end_date }}
+

{{ hackathon.description }}

+ {% if hackathon.organiser %} +

Organiser: {{ hackathon.organiser }}

+ {% endif %} + Read More
- {% endif %} +
{% endif %} {% endif %} - {% endfor %} - {% else %} -

There aren't any Hackathons at the moment!

{% endif %} + {% endfor %} + {% else %} +

There aren't any Hackathons at the moment!

+ {% endif %}
    Project Portfolio @@ -48,7 +46,6 @@

    There aren't any Hackathons at the moment!

-
Code Institute Hackathon Logo
@@ -85,5 +82,4 @@

Submission Showcases

- {% endblock %}