diff options
Diffstat (limited to 'coip/apps/name')
-rw-r--r-- | coip/apps/name/forms.py | 36 | ||||
-rw-r--r-- | coip/apps/name/views.py | 11 |
2 files changed, 36 insertions, 11 deletions
diff --git a/coip/apps/name/forms.py b/coip/apps/name/forms.py index a2a659e..759579c 100644 --- a/coip/apps/name/forms.py +++ b/coip/apps/name/forms.py @@ -7,6 +7,7 @@ from django import forms from coip.apps.name.models import Name, Attribute, NameLink from django.forms import fields from django.forms.widgets import HiddenInput, CheckboxSelectMultiple +from form_utils.forms import BetterModelForm, BetterForm class NameForm(forms.ModelForm): class Meta: @@ -16,21 +17,42 @@ class AttributeForm(forms.ModelForm): class Meta: model = Attribute -class NameEditForm(forms.ModelForm): - description = forms.CharField(widget=forms.Textarea(attrs={'cols': 60, 'rows': 6})) - +class NameEditForm(BetterModelForm): + description = forms.CharField(widget=forms.Textarea(attrs={'cols': 60, 'rows': 6})) class Meta: model = Name fields = ['short','description'] - -class NewNameForm(forms.ModelForm): + fieldsets = [('step1', {'fields': ['short', 'description'], + 'legend': 'Describe your group', + 'classes': ['step submit_step'], + 'description': 'Provide a short and (optionally) longer description of your group..'})] + +class NewNameForm(BetterModelForm): description = forms.CharField(widget=forms.Textarea(attrs={'cols': 60, 'rows': 6})) + value = forms.CharField(label="Name") class Meta: model = Name - fields = ['type','value','short','description'] + fields = ['value','short','description','type'] + fieldsets = [('step1', {'fields': ['value'], + 'legend': 'Step 1: Name your group', + 'classes': ['step'], + 'description': 'Provide a short identifier for your groups. Spaces are not allowed here.'}), + ('step2', {'fields': ['short', 'description'], + 'legend': 'Step 2: Describe your group', + 'classes': ['step'], + 'description': 'Provide a short and (optionally) longer description of your group..'}), + ('step3', {'fields': ['type'], + 'legend': 'Step 3 (optional): Advanced options', + 'classes': ['step','submit_step'], + 'description': 'Only set the type if you know what you are doing. You almost certainly do not need this.'})] -class NameDeleteForm(forms.Form): +class NameDeleteForm(BetterForm): recursive = fields.BooleanField(label="Also delete everything below this name?",required=False) + class Meta: + fieldsets = [('step1', {'fields': ['recursive'], + 'legend': 'Confirm deletion of your group', + 'classes': ['step'], + 'description': 'This is a destructive operation - there is no way to recover your group once it has been deleted!'})] class NameLinkForm(forms.ModelForm): class Meta: diff --git a/coip/apps/name/views.py b/coip/apps/name/views.py index df669e7..c6d0621 100644 --- a/coip/apps/name/views.py +++ b/coip/apps/name/views.py @@ -45,7 +45,7 @@ def delete(request,id): else: form = NameDeleteForm() - return respond_to(request,{'text/html': 'apps/name/edit.html'},{'form': form,'name': name,'formtitle': 'Remove %s' % (name.short) ,'submitname': 'Delete'}) + return respond_to(request,{'text/html': 'apps/name/delete.html'},{'form': form,'name': name,'formtitle': 'Remove %s' % (name.short) ,'submitname': 'Delete'}) @login_required def add(request,id): @@ -68,7 +68,7 @@ def add(request,id): else: form = NewNameForm() - return respond_to(request,{'text/html': 'apps/name/edit.html'},{'form': form,'name': parent,'formtitle': 'Add group','submitname': 'Create'}) + return respond_to(request,{'text/html': 'apps/name/add.html'},{'form': form,'name': parent,'formtitle': 'Add group','submitname': 'Create'}) @login_required def edit(request,id): @@ -85,7 +85,7 @@ def edit(request,id): else: form = NameEditForm(instance=name) - return respond_to(request,{'text/html': 'apps/name/edit.html'},{'form': form,'name': name,'formtitle': 'Change name','submitname': 'Update'}) + return respond_to(request,{'text/html': 'apps/name/edit.html'},{'form': form,'name': name,'formtitle': 'Modify %s' % name.short,'submitname': 'Update'}) @login_required @@ -182,7 +182,10 @@ def show_by_id(request,id=None): return HttpResponseNotFound() def _tree_node(name,depth): - state = 'closed' + if depth > 2: + state = "closed" + else: + state = 'open' return {'data': { 'title': name.relative_name(), 'attr': {'href': name.url() } }, 'state': state, 'attr': {'id': name.id}} |