Skip to content

Commit

Permalink
multiple photos working + code of conduct
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardo-devintage committed Jun 24, 2024
1 parent c09aedd commit d9a16e9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
22 changes: 18 additions & 4 deletions apps/core/forms/photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@ class MultipleFileInput(forms.ClearableFileInput):
allow_multiple_selected = True


class MultipleImageField(forms.ImageField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("widget", MultipleFileInput())
super().__init__(*args, **kwargs)

def clean(self, data, initial=None):
single_file_clean = super().clean
if isinstance(data, (list, tuple)):
result = [single_file_clean(d, initial) for d in data]
else:
result = [single_file_clean(data, initial)]
return result


class PhotoAlbumForm(forms.ModelForm):
photos = forms.ImageField(widget=MultipleFileInput(), required=False)
photos = MultipleImageField(widget=MultipleFileInput(), required=False)

class Meta:
model = PhotoAlbum
Expand Down Expand Up @@ -57,17 +71,17 @@ def __init__(self, *args, **kwargs):


class PhotoObjectForm(forms.ModelForm):
photo = forms.ImageField(widget=MultipleFileInput(), required=True)
photos = forms.ImageField(widget=MultipleFileInput(), required=True)

class Meta:
model = PhotoObject
fields = ["photo"]
fields = ["photos"]

def __init__(self, *args, **kwargs):
super(PhotoObjectForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(Field("photo"))
self.helper.layout = Layout(Field("photos"))


PHOTO_ALBUM_FUTURE_DATE = "future_photo_album"
Binary file not shown.
15 changes: 15 additions & 0 deletions apps/core/templates/resources.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "subpage.html" %}
{% block title %}Resources{% endblock title%}
{% block content %}
{% load static %}

<div class="container">
<div class="w-75 mx-auto">
Expand Down Expand Up @@ -68,6 +69,20 @@ <h2 class="text-center mt-5">Internal Documents</h2>
<a class="btn btn-cosmos-primary" href="{% url 'cosmos_core:gmm-list' %}">GMM Documents</a>
</div>

<h2 class="text-center mt-5">Code of Conduct</h2>
<p>
Everyone within Cosmos, in the Common Room, and at Cosmos events, including students,
staff, and guests, is entitled to fair treatment. The Code of Conduct details the rules that
we all have to follow, your rights, and who you can go to when you feel these rights
have been violated.
</p>
<p>
The Code of Conduct is available
<a href="{% static 'cosmos/pdf/CodeOfConduct1-0-0.pdf' %}">here</a>,
and applies to anyone at a Cosmos event, and to any Cosmos
member in the Common Room.
</p>

{% if user.is_authenticated %}
<h2 class="text-center mt-5">Members' Initiative</h2>
<p>Members' Initiative is a way for anyone to host events at Cosmos without the need to join an event organizing committee. Simply fill in the form, in which you outline your idea as well as the required budget, and we'll provide you with the means to make the event happen!</p>
Expand Down
2 changes: 1 addition & 1 deletion apps/core/views/photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def photo_album_add_photo(request, pk):

if request.method == "POST":
print(request.FILES)
for img in request.FILES.getlist("photo"):
for img in request.FILES.getlist("photos"):
PhotoObject.objects.create(album=album, photo=img)
return redirect(reverse("cosmos_core:photo_album-view", kwargs={"pk": album.id}))
else:
Expand Down

0 comments on commit d9a16e9

Please sign in to comment.