2008-06-06 21:20:18 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-07-02 11:14:47 +02:00
|
|
|
#
|
2009-07-19 01:03:23 +02:00
|
|
|
# Copyright (C) 2007, 2008, 2009 by Jan Dittberner.
|
2007-07-02 11:14:47 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 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
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
# USA.
|
|
|
|
#
|
|
|
|
# Version: $Id$
|
2008-06-07 23:25:35 +02:00
|
|
|
"""This module defines the ClientEntity class."""
|
2007-07-02 11:14:47 +02:00
|
|
|
|
2009-07-19 01:03:23 +02:00
|
|
|
from gnuviechadmin.backend.settings import get_template, get_template_string
|
2008-06-07 23:25:35 +02:00
|
|
|
from gnuviechadmin.exceptions import CannotDeleteError
|
|
|
|
from gnuviechadmin.backend.BackendTo import Client
|
|
|
|
from gnuviechadmin.backend.BackendEntity import BackendEntity
|
|
|
|
from gnuviechadmin.backend.BackendEntityHandler import BackendEntityHandler
|
2007-07-02 11:14:47 +02:00
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
|
2007-07-09 08:46:36 +02:00
|
|
|
class ClientEntity(BackendEntity):
|
2007-07-02 11:14:47 +02:00
|
|
|
"""Entity class for clients."""
|
|
|
|
|
2009-07-19 01:03:23 +02:00
|
|
|
def __init__(self, config, delegate, verbose = False, **kwargs):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Initializes the client entity instance."""
|
2009-07-19 01:03:23 +02:00
|
|
|
BackendEntity.__init__(self, config, delegate, verbose)
|
2007-07-05 11:00:34 +02:00
|
|
|
for (key, value) in kwargs.items():
|
|
|
|
self.__setattr__(key, value)
|
2007-07-09 08:46:36 +02:00
|
|
|
if not self.delegateto.country:
|
|
|
|
self.delegateto.country = self._get_default_country()
|
2007-07-02 11:14:47 +02:00
|
|
|
self.validate()
|
|
|
|
|
2007-07-09 08:46:36 +02:00
|
|
|
def _client_mail(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Mails a summary about the creation of the client."""
|
2009-07-19 01:03:23 +02:00
|
|
|
text = get_template(self.config['mailtemplates'],
|
|
|
|
self.config['client.create.mail']).substitute({
|
2008-06-06 21:20:18 +02:00
|
|
|
'firstname': self.delegateto.firstname,
|
|
|
|
'lastname': self.delegateto.lastname,
|
|
|
|
'email': self.delegateto.email,
|
|
|
|
'address1': self.delegateto.address1,
|
|
|
|
'zipcode': self.delegateto.zip,
|
|
|
|
'city': self.delegateto.city,
|
|
|
|
'phone': self.delegateto.phone})
|
2007-07-09 08:46:36 +02:00
|
|
|
subject = get_template_string(
|
2009-07-19 01:03:23 +02:00
|
|
|
self.config['client.create_subject']).substitute({
|
2008-06-06 21:20:18 +02:00
|
|
|
'firstname': self.delegateto.firstname,
|
|
|
|
'lastname': self.delegateto.lastname})
|
|
|
|
self.send_mail(subject, text)
|
2009-07-19 01:03:23 +02:00
|
|
|
|
2007-07-09 08:46:36 +02:00
|
|
|
def create_hook(self, session):
|
|
|
|
"""Actions to perform when a client is created."""
|
|
|
|
self._client_mail()
|
2007-07-02 11:14:47 +02:00
|
|
|
|
2007-07-09 08:46:36 +02:00
|
|
|
def delete_hook(self, session):
|
|
|
|
"""Actions to perform when a client is deleted."""
|
|
|
|
if self.delegateto.sysusers:
|
|
|
|
raise CannotDeleteError(
|
|
|
|
self.delegateto,
|
|
|
|
"it still has the following system users assigned: %s" % (
|
|
|
|
", ".join([sysuser.username for sysuser in \
|
|
|
|
self.delegateto.sysusers])))
|
2007-07-02 11:14:47 +02:00
|
|
|
|
2007-07-09 08:46:36 +02:00
|
|
|
def _get_default_country(self):
|
|
|
|
"""Gets the default country."""
|
2009-07-19 01:03:23 +02:00
|
|
|
return self.config['client.defaultcountry']
|
2007-07-02 11:14:47 +02:00
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
|
2007-07-02 11:14:47 +02:00
|
|
|
class ClientHandler(BackendEntityHandler):
|
|
|
|
"""BackendEntityHandler for Client entities."""
|
|
|
|
|
2009-07-19 01:03:23 +02:00
|
|
|
def __init__(self, config, verbose = False):
|
|
|
|
BackendEntityHandler.__init__(self, ClientEntity, Client, config,
|
|
|
|
verbose)
|