summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-07-12 18:54:30 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-07-12 18:54:30 +0200
commitbb5ca32767ce6a25b72e03a4ebebd0648bc0cd42 (patch)
treeeb3d8b5c2cbbfcc454a4e2c94929d11056fac61c
parent7185d81691ede9520cecdd2a2e8dcac372aaac6c (diff)
downloadIshtar-bb5ca32767ce6a25b72e03a4ebebd0648bc0cd42.tar.bz2
Ishtar-bb5ca32767ce6a25b72e03a4ebebd0648bc0cd42.zip
Basket: manage slug and public (for admin only)
-rw-r--r--archaeological_finds/forms.py37
-rw-r--r--archaeological_finds/migrations/0068_auto_20190712_1814.py25
-rw-r--r--archaeological_finds/templates/ishtar/sheet_findbasket.html2
-rw-r--r--archaeological_finds/wizards.py9
-rw-r--r--ishtar_common/models.py2
5 files changed, 74 insertions, 1 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index 129a1446e..390d36c36 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -1514,6 +1514,8 @@ class FindBasketForm(IshtarForm):
label = forms.CharField(
label=_(u"Label"),
validators=[validators.MaxLengthValidator(1000)])
+ slug = forms.SlugField(label=_("Slug"), required=False)
+ public = forms.BooleanField(label=_("Is public"), required=False)
comment = forms.CharField(label=_(u"Comment"),
widget=forms.Textarea, required=False)
shared_with = widgets.Select2MultipleField(
@@ -1527,6 +1529,27 @@ class FindBasketForm(IshtarForm):
required=False, long_widget=True
)
+ def __init__(self, *args, **kwargs):
+ self.basket_pk = None
+ if "basket_pk" in kwargs:
+ self.basket_pk = kwargs.pop("basket_pk")
+ self.is_admin = None
+ if "user" in kwargs:
+ user = kwargs.pop("user")
+ self.is_admin = getattr(user, "is_superuser", None)
+ super(FindBasketForm, self).__init__(*args, **kwargs)
+ if not self.is_admin:
+ self.fields.pop("slug")
+ self.fields.pop("public")
+
+ def clean(self):
+ slug = self.cleaned_data.get('slug', None)
+ if slug and slug.strip() and models.FindBasket.objects.filter(
+ slug=slug.strip()).exclude(pk=self.basket_pk).count():
+ raise forms.ValidationError(_("A basket with this slug already "
+ "exists."))
+ return self.cleaned_data
+
class NewFindBasketForm(forms.ModelForm, IshtarForm):
shared_with = widgets.Select2MultipleField(
@@ -1542,11 +1565,18 @@ class NewFindBasketForm(forms.ModelForm, IshtarForm):
class Meta:
model = models.FindBasket
- fields = ('label', 'comment', 'shared_with', 'shared_write_with')
+ fields = ('label', 'slug', 'public', 'comment', 'shared_with',
+ 'shared_write_with')
def __init__(self, *args, **kwargs):
self.user = kwargs.pop('user')
+ self.is_admin = False
+ if getattr(self.user, "user_ptr", None):
+ self.is_admin = getattr(self.user.user_ptr, "is_superuser", None)
super(NewFindBasketForm, self).__init__(*args, **kwargs)
+ if not self.is_admin:
+ self.fields.pop("slug")
+ self.fields.pop("public")
def clean(self):
q = models.FindBasket.objects.filter(user=self.user,
@@ -1554,6 +1584,11 @@ class NewFindBasketForm(forms.ModelForm, IshtarForm):
if q.count():
raise forms.ValidationError(_(u"Another basket already exists with "
u"this name."))
+ slug = self.cleaned_data.get('slug', None)
+ if slug and slug.strip() and models.FindBasket.objects.filter(
+ slug=slug.strip()).count():
+ raise forms.ValidationError(_("A basket with this slug already "
+ "exists."))
return self.cleaned_data
def save(self, commit=True):
diff --git a/archaeological_finds/migrations/0068_auto_20190712_1814.py b/archaeological_finds/migrations/0068_auto_20190712_1814.py
new file mode 100644
index 000000000..8f7b3b36e
--- /dev/null
+++ b/archaeological_finds/migrations/0068_auto_20190712_1814.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-07-12 18:14
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('archaeological_finds', '0067_auto_20190628_1257'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='findbasket',
+ name='public',
+ field=models.BooleanField(default=False, verbose_name='Public'),
+ ),
+ migrations.AddField(
+ model_name='findbasket',
+ name='slug',
+ field=models.SlugField(blank=True, null=True, verbose_name='Identifiant texte'),
+ ),
+ ]
diff --git a/archaeological_finds/templates/ishtar/sheet_findbasket.html b/archaeological_finds/templates/ishtar/sheet_findbasket.html
index 52b53df2a..af5baea5d 100644
--- a/archaeological_finds/templates/ishtar/sheet_findbasket.html
+++ b/archaeological_finds/templates/ishtar/sheet_findbasket.html
@@ -12,6 +12,8 @@
<div class='row'>
{% field_flex "Label" item.label %}
{% field_flex_detail "Owned by" item.user.person %}
+ {% field_flex "Slug" item.slug %}
+ {% field_flex "Is public" item.public %}
{% field_flex "Comment" item.comment %}
{% field_flex_multiple_full "Shared (read) with" item.shared_with %}
{% field_flex_multiple_full "Shared (read/edit) with" item.shared_write_with %}
diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py
index e1c6814d6..42f5f47c6 100644
--- a/archaeological_finds/wizards.py
+++ b/archaeological_finds/wizards.py
@@ -502,6 +502,15 @@ class FindBasketEditWizard(FindBasketWizard):
edit = True
alt_is_own_method = 'get_write_query_owns'
+ def get_form_kwargs(self, step, **kwargs):
+ kwargs = super(FindBasketEditWizard, self).get_form_kwargs(
+ step, **kwargs)
+ if step != 'basket-find_basket_modification':
+ return kwargs
+ kwargs['basket_pk'] = self.get_current_object().pk
+ kwargs['user'] = self.request.user
+ return kwargs
+
class FindBasketDeletionWizard(DeletionWizard):
model = models.FindBasket
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index dc7c219ac..bcde57ea3 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -4574,6 +4574,8 @@ class Basket(FullSearch, OwnPerms):
IS_BASKET = True
label = models.CharField(_("Label"), max_length=1000)
comment = models.TextField(_("Comment"), blank=True, null=True)
+ slug = models.SlugField(_("Slug"), blank=True, null=True)
+ public = models.BooleanField(_("Public"), default=False)
user = models.ForeignKey(
IshtarUser, blank=True, null=True, related_name='%(class)ss',
on_delete=models.SET_NULL,