-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attempt to implement collection modals
- Loading branch information
Showing
9 changed files
with
245 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# | ||
# Freesound is (c) MUSIC TECHNOLOGY GROUP, UNIVERSITAT POMPEU FABRA | ||
# | ||
# Freesound is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Freesound is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# Authors: | ||
# See AUTHORS file. | ||
# | ||
|
||
from django import forms | ||
from fscollections.models import Collection | ||
|
||
#this class was aimed to perform similarly to BookmarkSound, however, at first the method to add a sound to a collection | ||
#will be opening the search engine in a modal, looking for a sound in there and adding it to the actual collection page | ||
#this can be found in edit pack -> add sounds | ||
#class CollectSoundForm(forms.ModelForm): | ||
|
||
class CollectionSoundForm(forms.Form): | ||
#list of existing collections | ||
#add sound to collection from sound page | ||
collection = forms.ChoiceField( | ||
label=False, | ||
choices=[], | ||
required=True) | ||
|
||
new_collection_name = forms.ChoiceField( | ||
label = False, | ||
help_text=None, | ||
required = False) | ||
|
||
use_last_collection = forms.BooleanField(widget=forms.HiddenInput(), required=False, initial=False) | ||
user_collections = None | ||
|
||
NO_COLLECTION_CHOICE_VALUE = '-1' | ||
NEW_COLLECTION_CHOICE_VALUE = '0' | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.user_collections = kwargs.pop('user_collections', False) | ||
self.user_saving_sound = kwargs.pop('user_saving_sound', False) | ||
self.sound_id = kwargs.pop('sound_id', False) | ||
super().__init__(*args, **kwargs) | ||
self.fields['collection'].choices = [(self.NO_COLLECTION_CHOICE_VALUE, '--- No collection ---'),#in this case this goes to bookmarks collection (might have to be created) | ||
(self.NEW_COLLECTION_CHOICE_VALUE, 'Create a new collection...')] + \ | ||
([(collection.id, collection.name) for collection in self.user_collections] | ||
if self.user_collections else[]) | ||
|
||
self.fields['new_collection_name'].widget.attrs['placeholder'] = "Fill in the name for the new collection" | ||
self.fields['category'].widget.attrs = { | ||
'data-grey-items': f'{self.NO_CATEGORY_CHOICE_VALUE},{self.NEW_CATEGORY_CHOICE_VALUE}'} | ||
#i don't fully understand what this last line of code does | ||
|
||
def save(self, *args, **kwargs): | ||
collection_to_use = None | ||
|
||
if not self.cleaned_data['use_last_collection']: | ||
if self.cleaned_data['collection'] == self.NO_COLLECTION_CHOICE_VALUE: | ||
pass | ||
elif self.cleaned_data['collection'] == self.NEW_COLLECTION_CHOICE_VALUE: | ||
if self.cleaned_data['new_collection_name'] != "": | ||
collection = \ | ||
Collection(author=self.user_saving_bookmark, name=self.cleaned_data['new_collection_name']) | ||
collection.save() | ||
collection_to_use = collection | ||
else: | ||
collection_to_use = Collection.objects.get(id=self.cleaned_data['collection']) | ||
else: #en aquest cas - SÍ estem fent servir l'última coleccio, NO estem creant una nova coleccio, NO estem agafant una coleccio existent i | ||
# per tant ens trobem en un cas de NO COLLECTION CHOICE VALUE (no s'ha triat cap coleccio) | ||
# si no es tria cap coleccio: l'usuari té alguna colecció? NO -> creem BookmarksCollection pels seus sons privats | ||
# SI -> per defecte es posa a BookmarksCollection | ||
try: | ||
last_user_collection = \ | ||
Collection.objects.filter(user=self.user_saving_bookmark).order_by('-created')[0] | ||
# If user has a previous bookmark, use the same category (or use none if no category used in last | ||
# bookmark) | ||
collection_to_use = last_user_collection | ||
except IndexError: | ||
# This is first bookmark of the user | ||
pass | ||
|
||
# If collection already exists, don't save it and return the existing one | ||
collection, _ = Collection.objects.get_or_create( | ||
name = collection_to_use.name, author=self.user_saving_bookmark) | ||
return collection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{% extends "molecules/modal_base.html" %} | ||
{% load static %} | ||
{% load bw_templatetags %} | ||
|
||
{% block id %}collectSoundModal{% endblock %} | ||
{% block extra-class %}{% if request.user.is_authenticated %}modal-width-60{% endif %}{% endblock %} | ||
{% block aria-label %}Collect sound modal{% endblock %} | ||
|
||
<div class="col-12"> | ||
{% if not request.user.is_authenticated %} | ||
<div class="text-center"> | ||
<h4 class="v-spacing-5">Can't collect sound</h4> | ||
</div> | ||
<div class="v-spacing-4 text-center"> | ||
<div class="v-spacing-4">To collect sounds, you need to be logged in with your Freesound account.</div> | ||
<button class="btn-primary" data-dismiss="modal">Ok</button> | ||
</div> | ||
{% elif not sound_is_moderated_and_processed_ok %} | ||
<div class="text-center"> | ||
<h4 class="v-spacing-5">Can't collect sound</h4> | ||
</div> | ||
<div class="v-spacing-4 text-center"> | ||
<div class="v-spacing-4">This sound can't be collected because it has not yet been processed or moderated.</div> | ||
<button class="btn-primary" data-dismiss="modal">Ok</button> | ||
</div> | ||
{% else %} | ||
<div class="center"> | ||
<h4 class="v-spacing-5">Collect Sound</h4> | ||
</div> | ||
<div class="v-spacing-4"> | ||
{% if collections%} | ||
<div class="v-spacing-4"> | ||
{% bw_icon 'bookmark-filled' %}This sound is already in your collections under | ||
{% for col in collections_with_sound %} | ||
<span class="text-black">{{col.name}}</span>{% if not forloop.last%},{% endif %} | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
<form> | ||
{{ form }} | ||
<button class = "btn-primary v-spacing-top-2">Collect Sound</button> | ||
</form> | ||
</div> | ||
{% endif %} | ||
</div> | ||
{% endblock%} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters