diff options
Diffstat (limited to 'ishtar/ishtar_base')
| -rw-r--r-- | ishtar/ishtar_base/management/__init__.py | 0 | ||||
| -rw-r--r-- | ishtar/ishtar_base/management/commands/__init__.py | 0 | ||||
| -rw-r--r-- | ishtar/ishtar_base/management/commands/generate_rights.py | 65 | ||||
| -rw-r--r-- | ishtar/ishtar_base/models.py | 22 | ||||
| -rw-r--r-- | ishtar/ishtar_base/views.py | 4 |
5 files changed, 87 insertions, 4 deletions
diff --git a/ishtar/ishtar_base/management/__init__.py b/ishtar/ishtar_base/management/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ishtar/ishtar_base/management/__init__.py diff --git a/ishtar/ishtar_base/management/commands/__init__.py b/ishtar/ishtar_base/management/commands/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/ishtar/ishtar_base/management/commands/__init__.py diff --git a/ishtar/ishtar_base/management/commands/generate_rights.py b/ishtar/ishtar_base/management/commands/generate_rights.py new file mode 100644 index 000000000..9bf2776a8 --- /dev/null +++ b/ishtar/ishtar_base/management/commands/generate_rights.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2011 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# See the file COPYING for details. + +from django.core.management.base import BaseCommand, CommandError +from django.core.exceptions import ObjectDoesNotExist + +import ishtar_base.forms_main as ishtar_forms +import ishtar_base.models as models + +class Command(BaseCommand): + args = '' + help = 'Regenerate rights for current forms' + + def handle(self, *args, **options): + wizards = [] + wizard_steps = {} + for attr in dir(ishtar_forms): + if not attr.endswith('_wizard'): + continue + wizard = getattr(ishtar_forms, attr) + url_name = wizard.url_name + try: + wizard_obj = models.Wizard.objects.get(url_name=url_name) + except ObjectDoesNotExist: + wizard_obj = models.Wizard.objects.create(url_name=url_name) + wizard_obj.save() + self.stdout.write('* Wizard "%s" added\n' % url_name) + wizard_steps[url_name] = [] + for idx, step_url_name in enumerate(wizard.form_list.keys()): + form = wizard.form_list[step_url_name] + if issubclass(form, ishtar_forms.FinalForm): + break # don't reference the final form + step_values = {'name':unicode(form.form_label), + 'order':idx} + try: + step_obj = models.WizardStep.objects.get(wizard=wizard_obj, + url_name=step_url_name) + for k in step_values: + setattr(step_obj, k, step_values[k]) + step_obj.save() + except ObjectDoesNotExist: + step_values.update({'wizard':wizard_obj, + 'url_name':step_url_name}) + step_obj = models.WizardStep.objects.create(**step_values) + step_obj.save() + self.stdout.write('* Wizard step "%s" added\n' \ + % unicode(form.form_label)) + wizard_steps[url_name].append(step_url_name) + self.stdout.write('Successfully regeneration of wizard rights\n') diff --git a/ishtar/ishtar_base/models.py b/ishtar/ishtar_base/models.py index caa67a513..41979129b 100644 --- a/ishtar/ishtar_base/models.py +++ b/ishtar/ishtar_base/models.py @@ -356,6 +356,27 @@ class LightHistorizedItem(BaseHistorizedItem): super(LightHistorizedItem, self).save(*args, **kwargs) return True +class Wizard(models.Model): + url_name = models.CharField(_(u"URL name"), max_length=128, unique=True) + class Meta: + verbose_name = _(u"Wizard") + ordering = ['url_name'] + + def __unicode__(self): + return unicode(self.url_name) + +class WizardStep(models.Model): + order = models.IntegerField(_(u"Order")) + wizard = models.ForeignKey(Wizard, verbose_name=_(u"Wizard")) + url_name = models.CharField(_(u"URL name"), max_length=128) + name = models.CharField(_(u"Label"), max_length=128) + class Meta: + verbose_name = _(u"Wizard step") + ordering = ['wizard', 'order'] + + def __unicode__(self): + return u"%s » %s" % (unicode(self.wizard), unicode(self.name)) + class UserDashboard: def __init__(self): types = IshtarUser.objects.values('person__person_type', @@ -1071,6 +1092,7 @@ class Organization(Address, OwnPerms): return self.name class PersonType(GeneralType): + rights = models.ManyToManyField(WizardStep, verbose_name=_(u"Rights")) class Meta: verbose_name = _(u"Person type") verbose_name_plural = _(u"Person types") diff --git a/ishtar/ishtar_base/views.py b/ishtar/ishtar_base/views.py index 68f26f5ae..c00dd8bc9 100644 --- a/ishtar/ishtar_base/views.py +++ b/ishtar/ishtar_base/views.py @@ -17,10 +17,6 @@ # See the file COPYING for details. -""" -Furnitures views -""" - import tidy import re import csv |
