From ccd858622c1ef161b355f020055682c6e424ad98 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 17 Dec 2013 13:40:51 +0100 Subject: Organizations management (refs #1568) * select, create, modify forms * create, modify, wizard * sheet templates * associated actions, urls --- ishtar_common/forms_common.py | 20 ++++++++ ishtar_common/ishtar_menu.py | 16 ++++++- ishtar_common/menus.py | 2 +- ishtar_common/models.py | 8 ++++ .../templates/ishtar/sheet_organization.html | 41 ++++++++++++++++ .../templates/ishtar/sheet_organization_pdf.html | 18 ++++++++ .../ishtar/sheet_organization_window.html | 3 ++ ishtar_common/urls.py | 9 ++++ ishtar_common/views.py | 54 ++++++++++++++-------- ishtar_common/wizards.py | 6 +++ 10 files changed, 156 insertions(+), 21 deletions(-) create mode 100644 ishtar_common/templates/ishtar/sheet_organization.html create mode 100644 ishtar_common/templates/ishtar/sheet_organization_pdf.html create mode 100644 ishtar_common/templates/ishtar/sheet_organization_window.html diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index b6cab8b6a..ec3ccfb8b 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -67,6 +67,8 @@ def get_person_field(label=_(u"Person"), required=True, person_types=[]): validators=[models.valid_id(models.Person)]) class OrganizationForm(forms.Form): + form_label = _(u"Organization") + associated_models = {'organization_type':models.OrganizationType} name = forms.CharField(label=_(u"Name"), max_length=40, validators=[name_validator]) organization_type = forms.ChoiceField(label=_(u"Organization type"), @@ -100,6 +102,24 @@ class OrganizationForm(forms.Form): new_item.save() return new_item +class OrganizationSelect(TableSelect): + name = forms.CharField(label=_(u"Name"), max_length=30) + organization_type = forms.ChoiceField(label=_(u"Type"), choices=[]) + + def __init__(self, *args, **kwargs): + super(OrganizationSelect, self).__init__(*args, **kwargs) + self.fields['organization_type'].choices = \ + models.OrganizationType.get_types() + +class OrganizationFormSelection(forms.Form): + form_label = _(u"Organization search") + associated_models = {'pk':models.Organization} + currents = {'pk':models.Organization} + pk = forms.IntegerField(label="", + widget=widgets.JQueryJqGrid(reverse_lazy('get-organization'), + OrganizationSelect, models.Organization), + validators=[models.valid_id(models.Organization)]) + class PersonSelect(TableSelect): name = forms.CharField(label=_(u"Name"), max_length=30) surname = forms.CharField(label=_(u"Surname"), max_length=20) diff --git a/ishtar_common/ishtar_menu.py b/ishtar_common/ishtar_menu.py index 1c198ad91..76961aea9 100644 --- a/ishtar_common/ishtar_menu.py +++ b/ishtar_common/ishtar_menu.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2010-2012 Étienne Loks +# Copyright (C) 2010-2013 Étienne Loks # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -26,7 +26,8 @@ import models MENU_SECTIONS = [ (10, SectionItem('administration', _(u"Administration"), - childs=[SectionItem('person', _(u"Person"), + childs=[ + SectionItem('person', _(u"Person"), childs=[ MenuItem('person_creation', _(u"Creation"), model=models.Person, @@ -35,6 +36,17 @@ MENU_SECTIONS = [ model=models.Person, access_controls=['change_person', 'change_own_person']), ]), + SectionItem('organization', _(u"Organization"), + childs=[ + MenuItem('organization_creation', _(u"Creation"), + model=models.Organization, + access_controls=['add_organization', + 'add_own_organization']), + MenuItem('organization_modification', _(u"Modification"), + model=models.Organization, + access_controls=['change_organization', + 'change_own_organization']), + ]), MenuItem('account_management', _(u"Account management"), model=models.IshtarUser, access_controls=['add_ishtaruser',]), diff --git a/ishtar_common/menus.py b/ishtar_common/menus.py index 77dcabcd3..465692ec6 100644 --- a/ishtar_common/menus.py +++ b/ishtar_common/menus.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2010-2012 Étienne Loks +# Copyright (C) 2010-2013 Étienne Loks # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 77a7d6562..473d634fa 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -701,6 +701,7 @@ class OrganizationType(GeneralType): ordering = ('label',) class Organization(Address, OwnPerms, ValueGetter): + TABLE_COLS = ('name', 'organization_type',) name = models.CharField(_(u"Name"), max_length=100) organization_type = models.ForeignKey(OrganizationType, verbose_name=_(u"Type")) @@ -719,6 +720,13 @@ class Organization(Address, OwnPerms, ValueGetter): def __unicode__(self): return self.name + @property + def associated_filename(self): + values = [unicode(getattr(self, attr)) + for attr in ('organization_type', 'name') + if getattr(self, attr)] + return slugify(u"-".join(values)) + class PersonType(GeneralType): #rights = models.ManyToManyField(WizardStep, verbose_name=_(u"Rights")) groups = models.ManyToManyField(Group, verbose_name=_(u"Groups"), diff --git a/ishtar_common/templates/ishtar/sheet_organization.html b/ishtar_common/templates/ishtar/sheet_organization.html new file mode 100644 index 000000000..64f8fe5c7 --- /dev/null +++ b/ishtar_common/templates/ishtar/sheet_organization.html @@ -0,0 +1,41 @@ +{% extends "ishtar/sheet.html" %} +{% load i18n %} + +{% block head_sheet %} +{{block.super}} +

{% trans "Organization"%}

+{% endblock %} + +{% block content %} + + +

{{item.name}}

+{% if item.address %}

{{item.address}}

{% endif %} +{% if item.address_complement %}

{{item.address_complement}}

{% endif %} +{% if item.postal_code %}

{{item.postal_code}}

{% endif %} +{% if item.town %}

{{item.town}}

{% endif %} +{% if item.phone %}

{{item.phone}}

{% endif %} +{% if item.mobile_phone %}

{{item.mobile_phone}}

{% endif %} + + + + + + + + + + + {% for person in item.members.all %} + + + + + + + {% empty %} + + {% endfor %} +
{%trans "Person in the organization"%}
{% trans "Name" %}{% trans "Surname" %}{% trans "Type" %} 
{{person.name|default:""}}{{person.surname|default:""}}{% for type in person.person_types.all %}{% if forloop.counter0 %}, {% endif %}{{type.label}}{% endfor %}
{% trans "No person in this organization" %}
+ +{% endblock %} diff --git a/ishtar_common/templates/ishtar/sheet_organization_pdf.html b/ishtar_common/templates/ishtar/sheet_organization_pdf.html new file mode 100644 index 000000000..79e89ef0b --- /dev/null +++ b/ishtar_common/templates/ishtar/sheet_organization_pdf.html @@ -0,0 +1,18 @@ +{% extends "ishtar/sheet_organization.html" %} +{% block header %} + +{% endblock %} +{% block main_head %} +{{ block.super }} +
+Ishtar – {{APP_NAME}} – {{item}} +
+{% endblock %} +{%block head_sheet%}{%endblock%} +{%block main_foot%} +
+– – +
+ + +{%endblock%} diff --git a/ishtar_common/templates/ishtar/sheet_organization_window.html b/ishtar_common/templates/ishtar/sheet_organization_window.html new file mode 100644 index 000000000..a0e5d9b77 --- /dev/null +++ b/ishtar_common/templates/ishtar/sheet_organization_window.html @@ -0,0 +1,3 @@ +{% extends "ishtar/sheet_organization.html" %} +{% block main_head %}{%endblock%} +{% block main_foot %}{%endblock%} diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py index 35354409e..565db57d5 100644 --- a/ishtar_common/urls.py +++ b/ishtar_common/urls.py @@ -35,6 +35,11 @@ urlpatterns = patterns('', views.person_creation_wizard, name='person_creation'), url(r'person_modification/(?P.+)?$', views.person_modification_wizard, name='person_modification'), + url(r'organization_creation/(?P.+)?$', + views.organization_creation_wizard, name='organization_creation'), + url(r'organization_modification/(?P.+)?$', + views.organization_modification_wizard, + name='organization_modification'), url(r'account_management/(?P.+)?$', views.account_management_wizard, name='account_management'), ) @@ -70,6 +75,10 @@ urlpatterns += patterns('ishtar_common.views', name='autocomplete-author'), url(r'new-organization/(?P.+)?/$', 'new_organization', name='new-organization'), + url(r'get-organization/(?P.+)?$', 'get_organization', + name='get-organization'), + url(r'show-organization/(?P.+)?/(?P.+)?$', + 'show_organization', name='show-organization'), url(r'autocomplete-organization/([0-9_]+)?$', 'autocomplete_organization', name='autocomplete-organization'), url(r'(?P' + actions + r')/$', 'action', diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 5e49ddc13..c03870935 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -51,10 +51,8 @@ if settings.XHTML2ODT_PATH: from menus import menu from ishtar_common.forms import FinalForm -from ishtar_common.forms_common import PersonForm, PersonTypeForm, \ - PersonFormSelection, AccountForm, FinalAccountForm, OrganizationForm, \ - AuthorForm, SimplePersonForm -from ishtar_common.wizards import PersonWizard, PersonModifWizard, AccountWizard +from ishtar_common import forms_common as forms +from ishtar_common import wizards import models CSV_OPTIONS = {'delimiter':';', 'quotechar':'"', 'quoting':csv.QUOTE_ALL} @@ -74,25 +72,38 @@ def index(request): return render_to_response('index.html', dct, context_instance=RequestContext(request)) -person_creation_wizard = PersonWizard.as_view([ - ('identity-person_creation', SimplePersonForm), - ('person_type-person_creation', PersonTypeForm), +person_creation_wizard = wizards.PersonWizard.as_view([ + ('identity-person_creation', forms.SimplePersonForm), + ('person_type-person_creation', forms.PersonTypeForm), ('final-person_creation', FinalForm)], label=_(u"New person"), url_name='person_creation') -person_modification_wizard = PersonModifWizard.as_view([ - ('selec-person_modification', PersonFormSelection), - ('identity-person_modification', SimplePersonForm), - ('person_type-person_creation', PersonTypeForm), +person_modification_wizard = wizards.PersonModifWizard.as_view([ + ('selec-person_modification', forms.PersonFormSelection), + ('identity-person_modification', forms.SimplePersonForm), + ('person_type-person_creation', forms.PersonTypeForm), ('final-person_modification', FinalForm)], label=_(u"Person modification"), url_name='person_modification') -account_management_wizard = AccountWizard.as_view([ - ('selec-account_management', PersonFormSelection), - ('account-account_management', AccountForm), - ('final-account_management', FinalAccountForm)], +organization_creation_wizard = wizards.OrganizationWizard.as_view([ + ('identity-organization_creation', forms.OrganizationForm), + ('final-organization_creation', FinalForm)], + label=_(u"New organization"), + url_name='organization_creation') + +organization_modification_wizard = wizards.OrganizationModifWizard.as_view([ + ('selec-organization_modification', forms.OrganizationFormSelection), + ('identity-organization_modification', forms.OrganizationForm), + ('final-organization_modification', FinalForm)], + label=_(u"Organization modification"), + url_name='organization_modification') + +account_management_wizard = wizards.AccountWizard.as_view([ + ('selec-account_management', forms.PersonFormSelection), + ('account-account_management', forms.AccountForm), + ('final-account_management', forms.FinalAccountForm)], label=_(u"Account management"), url_name='account_management',) @@ -584,9 +595,16 @@ def new_item(model, frm): context_instance=RequestContext(request)) return func -new_person = new_item(models.Person, PersonForm) -new_organization = new_item(models.Organization, OrganizationForm) -new_author = new_item(models.Author, AuthorForm) +new_person = new_item(models.Person, forms.PersonForm) +new_organization = new_item(models.Organization, forms.OrganizationForm) +show_organization = show_item(models.Organization, 'organization') +get_organization = get_item(models.Organization, + 'get_organization', 'organization', + extra_request_keys={ + 'name':'name__icontains', + 'organization_type':'organization_type__pk__in', + },) +new_author = new_item(models.Author, forms.AuthorForm) show_person = show_item(models.Person, 'person') get_person = get_item(models.Person, 'get_person', 'person', diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index ec684650f..55c9d0d9d 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -839,6 +839,12 @@ class PersonWizard(Wizard): class PersonModifWizard(PersonWizard): modification = True +class OrganizationWizard(Wizard): + model = models.Organization + +class OrganizationModifWizard(OrganizationWizard): + modification = True + class AccountWizard(Wizard): model = models.Person def get_formated_datas(self, forms): -- cgit v1.2.3