VirtualMailManager/Domain.py
changeset 133 2d5c4745efec
parent 122 30abf0abf8f8
child 138 617f27715b01
equal deleted inserted replaced
132:fa22bd13b4d1 133:2d5c4745efec
    34         else:
    34         else:
    35             self._transport = transport
    35             self._transport = transport
    36         self._id = 0
    36         self._id = 0
    37         self._domaindir = None
    37         self._domaindir = None
    38         if not self._exists() and self._isAlias():
    38         if not self._exists() and self._isAlias():
    39             raise VMMDE(_(u"The domain »%s« is an alias domain.") %self._name,
    39             raise VMMDE(_(u"The domain “%s” is an alias domain.") %self._name,
    40                     ERR.DOMAIN_ALIAS_EXISTS)
    40                     ERR.DOMAIN_ALIAS_EXISTS)
    41 
    41 
    42     def _exists(self):
    42     def _exists(self):
    43         """Checks if the domain already exists.
    43         """Checks if the domain already exists.
    44 
    44 
   140             dbc.execute("INSERT INTO domain_name (domainname, gid, is_primary)\
   140             dbc.execute("INSERT INTO domain_name (domainname, gid, is_primary)\
   141  VALUES (%s, %s, %s)", self._name, self._id, True)
   141  VALUES (%s, %s, %s)", self._name, self._id, True)
   142             self._dbh.commit()
   142             self._dbh.commit()
   143             dbc.close()
   143             dbc.close()
   144         else:
   144         else:
   145             raise VMMDE(_(u'The domain »%s« already exists.') % self._name,
   145             raise VMMDE(_(u'The domain “%s” already exists.') % self._name,
   146                 ERR.DOMAIN_EXISTS)
   146                 ERR.DOMAIN_EXISTS)
   147 
   147 
   148     def delete(self, delUser=False, delAlias=False):
   148     def delete(self, delUser=False, delAlias=False):
   149         """Deletes the domain.
   149         """Deletes the domain.
   150 
   150 
   158             for t in ('alias','users','relocated','domain_name','domain_data'):
   158             for t in ('alias','users','relocated','domain_name','domain_data'):
   159                 dbc.execute("DELETE FROM %s WHERE gid = %d" % (t, self._id))
   159                 dbc.execute("DELETE FROM %s WHERE gid = %d" % (t, self._id))
   160             self._dbh.commit()
   160             self._dbh.commit()
   161             dbc.close()
   161             dbc.close()
   162         else:
   162         else:
   163             raise VMMDE(_(u"The domain »%s« doesn't exist yet.") % self._name,
   163             raise VMMDE(_(u"The domain “%s” doesn't exist yet.") % self._name,
   164                 ERR.NO_SUCH_DOMAIN)
   164                 ERR.NO_SUCH_DOMAIN)
   165 
   165 
   166     def updateTransport(self, transport, force=False):
   166     def updateTransport(self, transport, force=False):
   167         """Sets a new transport for the domain.
   167         """Sets a new transport for the domain.
   168 
   168 
   184                         trsp.getID(), self._id)
   184                         trsp.getID(), self._id)
   185                 if dbc.rowcount > 0:
   185                 if dbc.rowcount > 0:
   186                     self._dbh.commit()
   186                     self._dbh.commit()
   187             dbc.close()
   187             dbc.close()
   188         else:
   188         else:
   189             raise VMMDE(_(u"The domain »%s« doesn't exist yet.") % self._name,
   189             raise VMMDE(_(u"The domain “%s” doesn't exist yet.") % self._name,
   190                 ERR.NO_SUCH_DOMAIN)
   190                 ERR.NO_SUCH_DOMAIN)
   191 
   191 
   192     def getID(self):
   192     def getID(self):
   193         """Returns the ID of the domain."""
   193         """Returns the ID of the domain."""
   194         return self._id
   194         return self._id
   215         dbc = self._dbh.cursor()
   215         dbc = self._dbh.cursor()
   216         dbc.execute(sql)
   216         dbc.execute(sql)
   217         info = dbc.fetchone()
   217         info = dbc.fetchone()
   218         dbc.close()
   218         dbc.close()
   219         if info is None:
   219         if info is None:
   220             raise VMMDE(_(u"The domain »%s« doesn't exist yet.") % self._name,
   220             raise VMMDE(_(u"The domain “%s” doesn't exist yet.") % self._name,
   221                     ERR.NO_SUCH_DOMAIN)
   221                     ERR.NO_SUCH_DOMAIN)
   222         else:
   222         else:
   223             keys = ['gid', 'domainname', 'transport', 'domaindir',
   223             keys = ['gid', 'domainname', 'transport', 'domaindir',
   224                     'aliasdomains', 'accounts', 'aliases', 'relocated']
   224                     'aliasdomains', 'accounts', 'aliases', 'relocated']
   225             return dict(zip(keys, info))
   225             return dict(zip(keys, info))