summaryrefslogtreecommitdiff
path: root/app/utils
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2017-11-09 11:32:36 -0800
committerluxagraf <sng@luxagraf.net>2017-11-09 11:32:36 -0800
commitff0316afe40fa8572e787bdc2c5c69fd9c7ace65 (patch)
treedac03bdcc20b7349d8bfac916ae31377f07b9b5b /app/utils
parente392dc34c836dc529a72b603c5ee5c9b917c2f37 (diff)
fixed bird admin. maybe.
Diffstat (limited to 'app/utils')
-rw-r--r--app/utils/views.py1
-rw-r--r--app/utils/widgets.py32
2 files changed, 33 insertions, 0 deletions
diff --git a/app/utils/views.py b/app/utils/views.py
index 26253ff..108293e 100644
--- a/app/utils/views.py
+++ b/app/utils/views.py
@@ -1,6 +1,7 @@
from itertools import chain
from django.views.generic import ListView
from photos.models import LuxImage, LuxVideo
+from django.shortcuts import render_to_response
from django.shortcuts import render
from django.template import RequestContext
diff --git a/app/utils/widgets.py b/app/utils/widgets.py
index 240820a..eac4631 100644
--- a/app/utils/widgets.py
+++ b/app/utils/widgets.py
@@ -25,6 +25,38 @@ def markdown_to_html(txt):
return md.convert(txt)
+class CustomSelectMultiple(SelectMultiple):
+ def render_options(self, choices, selected_choices):
+ if not selected_choices:
+ # there is CreatView and we have no selected choices - render all selected
+ render_option = self.render_option
+ else:
+ # there is UpdateView and we have selected choices - render as default
+ render_option = super(CustomSelectMultiple, self).render_option
+
+ selected_choices = set(force_text(v) for v in selected_choices)
+ output = []
+ for option_value, option_label in chain(self.choices, choices):
+ if isinstance(option_label, (list, tuple)):
+ output.append(format_html('<optgroup label="{0}">', force_text(option_value)))
+ for option in option_label:
+ output.append(render_option(selected_choices, *option))
+ output.append('</optgroup>')
+ else:
+
+ output.append(render_option(selected_choices, option_value, option_label))
+ return '\n'.join(output)
+
+ def render_option(self, selected_choices, option_value, option_label):
+ option_value = force_text(option_value)
+ selected_html = mark_safe(' selected="selected"')
+
+ return format_html('<option value="{0}"{1}>{2}</option>',
+ option_value,
+ selected_html,
+ force_text(option_label))
+
+
class TagListFilter(admin.SimpleListFilter):
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.