VirtualMailManager/Domain.py
changeset 56 9ae1b1b2ee5c
parent 53 5b50eb306d37
child 58 1692da96ec17
equal deleted inserted replaced
55:15c873f94ba6 56:9ae1b1b2ee5c
    39             self._transport = Transport(self._dbh, transport=transport)
    39             self._transport = Transport(self._dbh, transport=transport)
    40         else:
    40         else:
    41             self._transport = transport
    41             self._transport = transport
    42         self._id = 0
    42         self._id = 0
    43         self._domaindir = None
    43         self._domaindir = None
    44         self._exists()
    44         if not self._exists() and self._isAlias():
       
    45             raise VMMDE(_(u"The domain »%s« is an alias domain.") %self._name,
       
    46                     ERR.DOMAIN_ALIAS_EXISTS)
    45 
    47 
    46     def _exists(self):
    48     def _exists(self):
    47         """Checks if the domain already exists.
    49         """Checks if the domain already exists.
    48 
    50 
    49         If the domain exists _id will be set and returns True, otherwise False
    51         If the domain exists _id will be set and returns True, otherwise False
    50         will be returned.
    52         will be returned.
    51         """
    53         """
    52         dbc = self._dbh.cursor()
    54         dbc = self._dbh.cursor()
    53         dbc.execute("SELECT gid, tid, domaindir FROM domain_data WHERE gid =\
    55         dbc.execute("SELECT gid, tid, domaindir FROM domain_data WHERE gid =\
    54  (SELECT gid FROM domain_name WHERE domainname = %s AND is_primary)",
    56  (SELECT gid FROM domain_name WHERE domainname = %s AND is_primary)",
    55             self._name)
    57                 self._name)
    56         result = dbc.fetchone()
    58         result = dbc.fetchone()
    57         dbc.close()
    59         dbc.close()
    58         if result is not None:
    60         if result is not None:
    59             self._id, self._domaindir = result[0], result[2]
    61             self._id, self._domaindir = result[0], result[2]
    60             self._transport = Transport(self._dbh, tid=result[1])
    62             self._transport = Transport(self._dbh, tid=result[1])
       
    63             return True
       
    64         else:
       
    65             return False
       
    66 
       
    67     def _isAlias(self):
       
    68         """Checks if self._name is known for an alias domain."""
       
    69         dbc = self._dbh.cursor()
       
    70         dbc.execute('SELECT is_primary FROM domain_name WHERE domainname = %s',
       
    71                 self._name)
       
    72         result = dbc.fetchone()
       
    73         dbc.close()
       
    74         if result is not None and not result[0]:
    61             return True
    75             return True
    62         else:
    76         else:
    63             return False
    77             return False
    64 
    78 
    65     def _setID(self):
    79     def _setID(self):
   241 
   255 
   242     def getAliaseNames(self):
   256     def getAliaseNames(self):
   243         """Returns a list with all alias names from the domain."""
   257         """Returns a list with all alias names from the domain."""
   244         dbc = self._dbh.cursor()
   258         dbc = self._dbh.cursor()
   245         dbc.execute("SELECT domainname FROM domain_name WHERE gid = %s\
   259         dbc.execute("SELECT domainname FROM domain_name WHERE gid = %s\
   246  AND NOT is_primary", self._id)
   260  AND NOT is_primary ORDER BY domainname", self._id)
   247         anames = dbc.fetchall()
   261         anames = dbc.fetchall()
   248         dbc.close()
   262         dbc.close()
   249         aliasdomains = []
   263         aliasdomains = []
   250         if len(anames) > 0:
   264         if len(anames) > 0:
   251             for aname in anames:
   265             for aname in anames: