0001-manager-translate-state-names-34234.patch
src/authentic2/manager/templates/authentic2/manager/user_import.html | ||
---|---|---|
56 | 56 |
<tbody> |
57 | 57 |
{% for report in reports %} |
58 | 58 |
<tr data-uuid="{{ report.uuid }}"> |
59 |
<td class="created">{% if report.state != 'running' %}<a href="{% url "a2-manager-users-import-report" import_uuid=user_import.uuid report_uuid=report.uuid %}">{{ report.created }}</a>{% else %}{{ report.created }}{% endif %}</td>
|
|
60 |
<td class="state"><span>{{ report.state }}</span> {% if report.state == 'error' %}"{{ report.exception }}"{% endif %} {% if not report.is_running %}!failed before finishing!{% endif %}</td>
|
|
59 |
<td class="created">{% if report.state != report.STATE_RUNNING %}<a href="{% url "a2-manager-users-import-report" import_uuid=user_import.uuid report_uuid=report.uuid %}">{{ report.created }}</a>{% else %}{{ report.created }}{% endif %}</td>
|
|
60 |
<td class="state"><span>{{ report.state_display }}</span> {% if report.state == report.STATE_ERROR %}"{{ report.exception }}"{% endif %} {% if not report.is_running %}!failed before finishing!{% endif %}</td>
|
|
61 | 61 |
<td class="applied">{% if not report.simulate %}<span class="icon-check"></span>{% endif %}</td> |
62 | 62 |
<td class="delete-action">{% if report.simulate %}<form method="post" id="delete-form-{{ report.uuid }}">{% csrf_token %}<button name="delete" value="{{ report.uuid }}">{% trans "Delete" %}</button></form>{% endif %}</td> |
63 | 63 |
</tr> |
src/authentic2/manager/user_import.py | ||
---|---|---|
34 | 34 |
from django.utils import six |
35 | 35 |
from django.utils.functional import cached_property |
36 | 36 |
from django.utils.timezone import utc |
37 |
from django.utils.translation import ugettext_lazy as _ |
|
37 | 38 | |
38 | 39 |
from authentic2.utils import gettid |
39 | 40 | |
... | ... | |
123 | 124 | |
124 | 125 | |
125 | 126 |
class Report(object): |
127 |
STATE_WAITING = 'waiting' |
|
128 |
STATE_RUNNING = 'running' |
|
129 |
STATE_FINISHED = 'finished' |
|
130 |
STATE_ERROR = 'error' |
|
131 |
STATES = { |
|
132 |
STATE_WAITING: _('Waiting'), |
|
133 |
STATE_RUNNING: _('Running'), |
|
134 |
STATE_FINISHED: _('Finished'), |
|
135 |
STATE_ERROR: _('Error'), |
|
136 |
} |
|
137 | ||
126 | 138 |
def __init__(self, user_import, uuid): |
127 | 139 |
self.user_import = user_import |
128 | 140 |
self.uuid = uuid |
... | ... | |
140 | 152 |
data = pickle.load(fd) |
141 | 153 |
return data |
142 | 154 | |
155 |
@property |
|
156 |
def state_display(self): |
|
157 |
state = self.data['state'] |
|
158 |
return self.STATES.get(state, state) |
|
159 | ||
143 | 160 |
@property |
144 | 161 |
@contextlib.contextmanager |
145 | 162 |
def data_update(self): |
... | ... | |
155 | 172 |
with report.data_update as data: |
156 | 173 |
data['encoding'] = user_import.meta['encoding'] |
157 | 174 |
data['ou'] = user_import.meta.get('ou') |
158 |
data['state'] = 'waiting'
|
|
175 |
data['state'] = cls.STATE_WAITING
|
|
159 | 176 |
return report |
160 | 177 | |
161 | 178 |
def run(self, start=True, simulate=False): |
162 |
assert self.data.get('state') == 'waiting'
|
|
179 |
assert self.data.get('state') == self.STATE_WAITING
|
|
163 | 180 | |
164 | 181 |
with self.data_update as data: |
165 | 182 |
data['simulate'] = simulate |
... | ... | |
171 | 188 |
importer = UserCsvImporter() |
172 | 189 |
start = datetime.datetime.now() |
173 | 190 |
with self.data_update as data: |
174 |
data['state'] = 'running'
|
|
191 |
data['state'] = self.STATE_RUNNING
|
|
175 | 192 |
data['pid'] = os.getpid() |
176 | 193 |
data['tid'] = gettid() |
177 | 194 |
try: |
... | ... | |
181 | 198 |
simulate=simulate) |
182 | 199 |
except Exception as e: |
183 | 200 |
logger.exception('error during report %s:%s run', self.user_import.uuid, self.uuid) |
184 |
state = 'error'
|
|
201 |
state = self.STATE_ERROR
|
|
185 | 202 |
try: |
186 | 203 |
exception = six.text_type(e) |
187 | 204 |
except Exception: |
188 | 205 |
exception = repr(repr(e)) |
189 | 206 |
else: |
190 | 207 |
exception = None |
191 |
state = 'finished'
|
|
208 |
state = self.STATE_FINISHED
|
|
192 | 209 |
finally: |
193 | 210 |
duration = datetime.datetime.now() - start |
194 | 211 |
try: |
tests/test_user_manager.py | ||
---|---|---|
271 | 271 | |
272 | 272 |
def wait_finished(): |
273 | 273 |
new_resp = response.click('Users Import') |
274 |
if new_resp.pyquery('tr[data-uuid="%s"] td.state span' % uuid).text() == 'finished':
|
|
274 |
if new_resp.pyquery('tr[data-uuid="%s"] td.state span' % uuid).text() == 'Finished':
|
|
275 | 275 |
return new_resp |
276 | 276 | |
277 | 277 |
simulate = reports[0] |
278 |
- |