Merge branch 'master' into nanterre-recette
This commit is contained in:
commit
9daf983e8b
|
@ -79,6 +79,11 @@ class ZooNanterreConfig(AppConfig):
|
|||
'view': '_apply_report',
|
||||
'name': '-show-apply-report',
|
||||
},
|
||||
{
|
||||
're': r'(?P<job_id>\d+)/delete/',
|
||||
'view': '_delete',
|
||||
'name': '-delete',
|
||||
},
|
||||
{
|
||||
're': r'(?P<job_id>\d+)/apply/',
|
||||
'view': '_apply',
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from .utils import PersonSearch, get_applications, get_application
|
||||
from . import synchronize_federations
|
||||
|
@ -58,6 +59,20 @@ class SynchronizeFederationsForm(forms.Form):
|
|||
csv_uploaded = forms.FileField(
|
||||
label=_('CSV file'))
|
||||
|
||||
def clean_csv_uploaded(self):
|
||||
csv_uploaded = self.cleaned_data['csv_uploaded']
|
||||
errors = []
|
||||
for i, line in enumerate(csv_uploaded):
|
||||
try:
|
||||
line.encode('ascii')
|
||||
# works with pyhton2 and 3
|
||||
except (UnicodeEncodeError, UnicodeDecodeError) as e:
|
||||
errors.append(_(u'non-ASCII character on line {0} and column {1}').format(
|
||||
i + 1, e.start + 1))
|
||||
if errors:
|
||||
raise ValidationError(errors)
|
||||
return csv_uploaded
|
||||
|
||||
def save(self):
|
||||
synchronize_federations.SynchronizeFederationsAction.synchronize(
|
||||
**self.cleaned_data)
|
||||
|
|
|
@ -68,3 +68,6 @@ msgstr "doublon"
|
|||
#: zoo_nanterre/models.py:77
|
||||
msgid "duplicates"
|
||||
msgstr "doublons"
|
||||
|
||||
msgid "non-ASCII character on line {0} and column {1}"
|
||||
msgstr "caractère non-ASCII à la ligne {0} et colonne {1}"
|
||||
|
|
|
@ -240,7 +240,10 @@ class SynchronizeFederationsAction(object):
|
|||
def report(self):
|
||||
if not self.report_csv_filepath:
|
||||
return None
|
||||
return default_storage.open(self.report_csv_filepath)
|
||||
try:
|
||||
return default_storage.open(self.report_csv_filepath)
|
||||
except IOError:
|
||||
return None
|
||||
|
||||
def make_url(self, action, prefix):
|
||||
stream = getattr(self, prefix)
|
||||
|
@ -253,6 +256,21 @@ class SynchronizeFederationsAction(object):
|
|||
'filename': filename,
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def __delete(self, path):
|
||||
if not path:
|
||||
return
|
||||
if default_storage.exists(path):
|
||||
try:
|
||||
default_storage.delete(path)
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
def delete(self):
|
||||
self.__delete(self.csv_filepath)
|
||||
self.__delete(self.report_csv_filepath)
|
||||
self.__delete(self.apply_report_csv_filepath)
|
||||
|
||||
@property
|
||||
def download_report_url(self):
|
||||
return self.make_url('download', 'report')
|
||||
|
@ -273,7 +291,10 @@ class SynchronizeFederationsAction(object):
|
|||
def apply_report(self):
|
||||
if not self.apply_report_csv_filepath:
|
||||
return None
|
||||
return default_storage.open(self.apply_report_csv_filepath)
|
||||
try:
|
||||
return default_storage.open(self.apply_report_csv_filepath)
|
||||
except IOError:
|
||||
return None
|
||||
|
||||
def set_apply(self, job):
|
||||
job.content['apply'] = True
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
<th>Nom du fichier</th>
|
||||
<th>Rapport d'import</th>
|
||||
<th>Synchroniser ?</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -55,7 +56,12 @@
|
|||
</form>
|
||||
{% endif %}
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<form action="{% url "admin:synchronize-federations-delete" job_id=job.id %}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="submit" value="{% trans "Delete" %}">
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -197,6 +197,16 @@ def synchronize_federations_apply(request, job_id, model_admin, **kwargs):
|
|||
return redirect('admin:synchronize-federations')
|
||||
|
||||
|
||||
@permission_required('zoo_data.action1_entity')
|
||||
def synchronize_federations_delete(request, job_id, model_admin, *args, **kwargs):
|
||||
if request.method == 'POST':
|
||||
jobs = SynchronizeFederationsAction.get_jobs()
|
||||
job = get_object_or_404(jobs, id=job_id)
|
||||
job.action.delete()
|
||||
job.delete()
|
||||
return redirect('admin:synchronize-federations')
|
||||
|
||||
|
||||
def fiches_inactives():
|
||||
inactivity = Inactivity(
|
||||
child_delay=getattr(settings, 'ZOO_NANTERRE_INACTIVITY_CHILD_DELAY', 365),
|
||||
|
|
Loading…
Reference in New Issue