VirtualMailManager/Domain.py
changeset 56 9ae1b1b2ee5c
parent 53 5b50eb306d37
child 58 1692da96ec17
--- a/VirtualMailManager/Domain.py	Fri Aug 22 20:00:50 2008 +0000
+++ b/VirtualMailManager/Domain.py	Fri Aug 22 22:39:03 2008 +0000
@@ -41,7 +41,9 @@
             self._transport = transport
         self._id = 0
         self._domaindir = None
-        self._exists()
+        if not self._exists() and self._isAlias():
+            raise VMMDE(_(u"The domain »%s« is an alias domain.") %self._name,
+                    ERR.DOMAIN_ALIAS_EXISTS)
 
     def _exists(self):
         """Checks if the domain already exists.
@@ -52,7 +54,7 @@
         dbc = self._dbh.cursor()
         dbc.execute("SELECT gid, tid, domaindir FROM domain_data WHERE gid =\
  (SELECT gid FROM domain_name WHERE domainname = %s AND is_primary)",
-            self._name)
+                self._name)
         result = dbc.fetchone()
         dbc.close()
         if result is not None:
@@ -62,6 +64,18 @@
         else:
             return False
 
+    def _isAlias(self):
+        """Checks if self._name is known for an alias domain."""
+        dbc = self._dbh.cursor()
+        dbc.execute('SELECT is_primary FROM domain_name WHERE domainname = %s',
+                self._name)
+        result = dbc.fetchone()
+        dbc.close()
+        if result is not None and not result[0]:
+            return True
+        else:
+            return False
+
     def _setID(self):
         """Sets the ID of the domain."""
         dbc = self._dbh.cursor()
@@ -243,7 +257,7 @@
         """Returns a list with all alias names from the domain."""
         dbc = self._dbh.cursor()
         dbc.execute("SELECT domainname FROM domain_name WHERE gid = %s\
- AND NOT is_primary", self._id)
+ AND NOT is_primary ORDER BY domainname", self._id)
         anames = dbc.fetchall()
         dbc.close()
         aliasdomains = []