summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-05-14 21:32:22 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-06-12 08:44:34 +0200
commit0adadd4d3f40ee313e392886fab1080e1bee4f92 (patch)
tree65aeca30bd4c57b7eb7431d5f7586bd8b985ca86 /ishtar_common
parent083985d6f383157b84e528701ba4be7cbd898fe3 (diff)
downloadIshtar-0adadd4d3f40ee313e392886fab1080e1bee4f92.tar.bz2
Ishtar-0adadd4d3f40ee313e392886fab1080e1bee4f92.zip
Add new to authors field for m2m images
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/forms_common.py2
-rw-r--r--ishtar_common/models.py4
-rw-r--r--ishtar_common/widgets.py23
3 files changed, 23 insertions, 6 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 22cd81e7b..061ae49b0 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -1101,7 +1101,7 @@ class BaseImageForm(ManageOldType):
name = forms.CharField(label=_(u"Name"), max_length=250, required=False)
authors = widgets.Select2MultipleField(
model=models.Author, remote=True, label=_(u"Authors"),
- required=False, long_widget=True
+ required=False, long_widget=True, new=True
)
description = forms.CharField(label=_(u"Description"), required=False,
widget=forms.Textarea)
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 53f4e1c11..ab70faaa0 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2904,10 +2904,12 @@ post_delete.connect(post_save_cache, sender=AuthorType)
class Author(FullSearch):
+ PARENT_SEARCH_VECTORS = ['person']
+ SLUG = "author"
+
person = models.ForeignKey(Person, verbose_name=_(u"Person"),
related_name='author')
author_type = models.ForeignKey(AuthorType, verbose_name=_(u"Author type"))
- PARENT_SEARCH_VECTORS = ['person']
class Meta:
verbose_name = _(u"Author")
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index e33669e19..442f12b9a 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -103,11 +103,12 @@ class SelectReadonlyField(forms.ChoiceField):
class Select2Multiple(forms.SelectMultiple):
def __init__(self, attrs=None, choices=(), remote=None, model=None,
- available=None):
+ new=None, available=None):
super(Select2Multiple, self).__init__(attrs, choices)
self.remote = remote
self.available = available
self.model = model
+ self.new = new
@property
def media(self):
@@ -152,7 +153,7 @@ class Select2Multiple(forms.SelectMultiple):
attrs['class'] = klass
if 'style' not in attrs:
if attrs.get('full-width', None):
- attrs['style'] = "width: 100%"
+ attrs['style'] = "width: calc(100% - 60px)"
else:
attrs['style'] = "width: 370px"
@@ -195,7 +196,18 @@ class Select2Multiple(forms.SelectMultiple):
options = "{"
options += " containerCssClass: 'full-width'}"
self.choices = choices
- html = super(Select2Multiple, self).render(name, value, attrs)
+
+ new, html = "", ""
+ if self.new:
+ html = u"<div class='input-group'>"
+ url_new = 'new-' + self.model.SLUG
+ url_new = reverse(url_new)
+ new = u'<span class="input-group-append">' \
+ u'<a href="#" class="add-button input-group-text" ' \
+ u'onclick="open_window(\'%s\');">+</a></span></div>' % url_new
+
+ html += super(Select2Multiple, self).render(name, value, attrs)
+ html += new
html += """<script type="text/javascript">
$(document).ready(function() {{
$("#id_{}").select2({});
@@ -220,6 +232,9 @@ class CheckboxSelectMultiple(CheckboxSelectMultipleBase):
class Select2MultipleField(forms.MultipleChoiceField):
def __init__(self, *args, **kwargs):
+ new = None
+ if 'new' in kwargs:
+ new = kwargs.pop('new')
remote = None
if 'remote' in kwargs:
remote = kwargs.pop('remote')
@@ -241,7 +256,7 @@ class Select2MultipleField(forms.MultipleChoiceField):
attrs['full-width'] = True
kwargs['widget'] = Select2Multiple(
model=self.model, available=self.available, remote=self.remote,
- attrs=attrs
+ new=new, attrs=attrs
)
super(Select2MultipleField, self).__init__(*args, **kwargs)