Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tabbycat/options/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ def get_pref(name, section=section):


def tournament_preference_form_builder(instance, preferences=[], **kwargs):
if kwargs.get('section') in [str(s) for s in global_preferences_registry.sections()]:
if kwargs.get('section') == 'all_sections':

return preference_form_builder(TournamentPreferenceForm, preferences=[], model={'instance': instance})

elif kwargs.get('section') in [str(s) for s in global_preferences_registry.sections()]:
# Check for global preferences
return preference_form_builder(GlobalPreferenceForm, preferences, **kwargs)

Expand Down
20 changes: 20 additions & 0 deletions tabbycat/options/preferences.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from decimal import Decimal

from django import forms
from django.core.validators import EmailValidator, MinValueValidator, validate_slug
from django.forms import SelectMultiple
from django.utils.translation import gettext_lazy as _
Expand All @@ -17,6 +18,25 @@
from .types import MultiValueChoicePreference
from .utils import validate_metric_duplicates


# ==============================================================================
all_sections = Section('all_sections', verbose_name=_("All Preferances"))
Comment thread
JWPCode marked this conversation as resolved.
Outdated
# ==============================================================================


@tournament_preferences_registry.register
class DummyAllSectionsPreference(StringPreference):
section = all_sections
name = 'dummy_all_sections'
default = ''
verbose_name = 'All Sections Placeholder'

def get_field_kwargs(self):
kwargs = super().get_field_kwargs()
kwargs['widget'] = forms.HiddenInput
return kwargs
Comment on lines +27 to +37
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a dummy preference?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its been a while since I did it sorry, but Its because of how the preferences are handled and how they have been put into sections. The default when there is no argument passed doesn't work with this set up, So we needed a new section to pass, that could then have the other sections added to, however it needs an initial preference to be returned or it throws an error



# ==============================================================================
scoring = Section('scoring', verbose_name=_("Score Rules"))
# ==============================================================================
Expand Down
6 changes: 6 additions & 0 deletions tabbycat/options/templates/preferences_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
{% trans "Settings which can affect all tournaments on the site" as description %}
{% include "components/item-action.html" with type="primary" emoji="🌏" text=title extra=description %}

{% tournamenturl 'options-tournament-section' section='all_sections' as url %}
{% trans "Preferance List" as title %}
Comment thread
JWPCode marked this conversation as resolved.
Outdated
{% trans "All preferance options in one place" as description %}
Comment thread
JWPCode marked this conversation as resolved.
Outdated
{% include "components/item-action.html" with type="primary" emoji="📋" text=title extra=description %}


</ul>
</div>

Expand Down
Loading