mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
* Return accounts before aliases (see #116)
* Continue on error for existing objects (see #317)
This commit is contained in:
@@ -323,6 +323,10 @@ class ForwardForm(GenericAliasForm):
|
||||
class ImportDataForm(forms.Form):
|
||||
sourcefile = forms.FileField(label=ugettext_lazy("Select a file"))
|
||||
sepchar = forms.CharField(label=ugettext_lazy("Separator"), max_length=1, required=False)
|
||||
continue_if_exists = forms.BooleanField(
|
||||
label=ugettext_lazy("Continue on error"), required=False,
|
||||
help_text=ugettext_lazy("Don't treat duplicated objects as error")
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ImportDataForm, self).__init__(*args, **kwargs)
|
||||
@@ -335,7 +339,7 @@ class ImportDataForm(forms.Form):
|
||||
|
||||
class ImportIdentitiesForm(ImportDataForm):
|
||||
crypt_password = forms.BooleanField(
|
||||
label=ugettext_lazy("Crypt passwords"),
|
||||
label=ugettext_lazy("Crypt passwords"), required=False,
|
||||
help_text=ugettext_lazy("Check this option if passwords contained in your file are not crypted")
|
||||
)
|
||||
|
||||
|
||||
@@ -224,7 +224,29 @@ class User(DUser):
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_accounts(self):
|
||||
"""Return all accounts owned by this user
|
||||
|
||||
:return: a queryset
|
||||
"""
|
||||
from modoboa.lib.permissions import get_content_type
|
||||
|
||||
return self.objectaccess_set.filter(content_type=get_content_type(self))
|
||||
|
||||
def get_aliases(self):
|
||||
"""Return all aliases owned by this user
|
||||
|
||||
:return: a queryset
|
||||
"""
|
||||
from modoboa.lib.permissions import get_content_type
|
||||
|
||||
return self.objectaccess_set.filter(content_type=get_content_type(Alias))
|
||||
|
||||
def get_identities(self):
|
||||
"""Return all identities owned by this user
|
||||
|
||||
:return: a queryset
|
||||
"""
|
||||
from modoboa.lib.permissions import get_content_type
|
||||
|
||||
userct = get_content_type(self)
|
||||
|
||||
+11
-5
@@ -607,8 +607,6 @@ def importdata(request, formclass=ImportDataForm):
|
||||
error = None
|
||||
form = formclass(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
import csv
|
||||
|
||||
try:
|
||||
reader = csv.reader(request.FILES['sourcefile'],
|
||||
delimiter=form.cleaned_data['sepchar'])
|
||||
@@ -623,13 +621,18 @@ def importdata(request, formclass=ImportDataForm):
|
||||
fct = globals()["import_%s" % row[0].strip()]
|
||||
except KeyError:
|
||||
continue
|
||||
fct(request.user, row, form.cleaned_data)
|
||||
try:
|
||||
fct(request.user, row, form.cleaned_data)
|
||||
except IntegrityError, e:
|
||||
if form.cleaned_data["continue_if_exists"]:
|
||||
continue
|
||||
raise ModoboaException(_("Object already exists: %s" % row))
|
||||
cpt += 1
|
||||
msg = _("%d objects imported successfully" % cpt)
|
||||
return render(request, "admin/import_done.html", {
|
||||
"status" : "ok", "msg" : msg
|
||||
})
|
||||
except (IntegrityError, ModoboaException), e:
|
||||
except (ModoboaException), e:
|
||||
error = str(e)
|
||||
|
||||
return render(request, "admin/import_done.html", {
|
||||
@@ -685,9 +688,12 @@ def _export(content, filename):
|
||||
def export_identities(request):
|
||||
fp = cStringIO.StringIO()
|
||||
csvwriter = csv.writer(fp, delimiter=';')
|
||||
for oa in request.user.get_identities():
|
||||
for oa in request.user.get_accounts():
|
||||
if oa.content_object:
|
||||
oa.content_object.to_csv(csvwriter)
|
||||
for oa in request.user.get_aliases():
|
||||
if oa.content_object:
|
||||
oa.content_object.to_csv(csvwriter)
|
||||
|
||||
content = fp.getvalue()
|
||||
fp.close()
|
||||
|
||||
Reference in New Issue
Block a user