Possibility to import domain aliases.

see #317
This commit is contained in:
Antoine Nguyen
2013-01-12 18:51:40 +01:00
parent c7d147654b
commit a7b7eef367
2 changed files with 34 additions and 3 deletions
+23
View File
@@ -513,7 +513,30 @@ class DomainAlias(DatesAware):
ungrant_access_to_object(self)
super(DomainAlias, self).delete()
def from_csv(self, user, row):
"""Create a domain alias from a CSV row
Expected format: ["domainalias", domain alias name, targeted domain]
:param user: a ``User`` object
:param row: a list containing the alias definition
"""
if len(row) < 3:
raise AdminError(_("Invalid line"))
self.name = row[1].strip()
domname = row[2].strip()
try:
self.target = Domain.objects.get(name=domname)
except Domain.DoesNotExist:
raise AdminError(_("Unknown domain %s" % domname))
self.enabled = True
self.save()
def to_csv(self, csvwriter):
"""Export a domain alias using CSV format
:param csvwriter: a ``csv.writer`` object
"""
csvwriter.writerow(["domainalias", self.name, self.target.name])
class Mailbox(DatesAware):
+11 -3
View File
@@ -560,6 +560,13 @@ def import_domain(user, row):
grant_access_to_object(user, dom, is_owner=True)
events.raiseEvent("CreateDomain", user, dom)
def import_domainalias(user, row):
"""Specific code for domain aliases import"""
domalias = DomainAlias()
domalias.from_csv(user, row)
grant_access_to_object(user, domalias, is_owner=True)
events.raiseEvent("DomainAliasCreated", user, domalias)
def import_account(user, row):
"""Specific code for accounts import"""
mb = Mailbox()
@@ -634,7 +641,7 @@ def import_identities(request):
if request.method == "POST":
return importdata(request)
helptext = _("""Provide a CSV file where lines respect one of the following format:
helptext = _("""Provide a CSV file where lines respect one of the following formats:
<ul>
<li><em>account; loginname; password; first name; last name; address</em></li>
<li><em>alias; address; internal recipient</em></li>
@@ -691,11 +698,12 @@ def import_domains(request):
if request.method == "POST":
return importdata(request)
helptext = _("""Provide a CSV file where lines respect the following format:
helptext = _("""Provide a CSV file where lines respect one of the following formats:
<ul>
<li><em>domain; name; quota</em></li>
<li><em>domainalias; name; targeted domain</em></li>
</ul>
<p>The <em>domain</em> keyword must be present for each line.</p>
<p>The first element of each line is mandatory and must be equal to one of the previous values.</p>
<p>You can use a different character as separator.</p>
""")