Revision bfe23b13 snf-astakos-app/astakos/im/api/backends/lib/django/__init__.py
b/snf-astakos-app/astakos/im/api/backends/lib/django/__init__.py | ||
---|---|---|
319 | 319 |
g.policies = policies |
320 | 320 |
# g.members = members |
321 | 321 |
g.owners = owners |
322 |
return self._details(g) |
|
323 |
|
|
324 |
|
|
325 |
@safe |
|
326 |
def submit_application(self, **kwargs): |
|
327 |
app = self._create_object(ProjectApplication, **kwargs) |
|
328 |
notification = build_notification( |
|
329 |
settings.SERVER_EMAIL, |
|
330 |
[settings.ADMINS], |
|
331 |
_(GROUP_CREATION_SUBJECT) % {'group':app.definition.name}, |
|
332 |
_('An new project application identified by %(serial)s has been submitted.') % app.serial |
|
333 |
) |
|
334 |
notification.send() |
|
335 |
|
|
336 |
@safe |
|
337 |
def list_applications(self): |
|
338 |
return self._list(ProjectAppication) |
|
339 |
|
|
340 |
@safe |
|
341 |
def approve_application(self, serial): |
|
342 |
app = self._lookup_object(ProjectAppication, serial=serial) |
|
343 |
notify = False |
|
344 |
if not app.precursor_application: |
|
345 |
kwargs = { |
|
346 |
'application':app, |
|
347 |
'creation_date':datetime.now(), |
|
348 |
'last_approval_date':datetime.now(), |
|
349 |
} |
|
350 |
project = self._create_object(Project, **kwargs) |
|
351 |
else: |
|
352 |
project = app.precursor_application.project |
|
353 |
last_approval_date = project.last_approval_date |
|
354 |
if project.is_valid: |
|
355 |
project.application = app |
|
356 |
project.last_approval_date = datetime.now() |
|
357 |
project.save() |
|
358 |
else: |
|
359 |
raise Exception(_(astakos_messages.INVALID_PROJECT) % project.__dict__) |
|
360 |
|
|
361 |
r = _synchonize_project(project.serial) |
|
362 |
if not r.is_success: |
|
363 |
# revert to precursor |
|
364 |
project.appication = app.precursor_application |
|
365 |
if project.application: |
|
366 |
project.last_approval_date = last_approval_date |
|
367 |
project.save() |
|
368 |
r = synchonize_project(project.serial) |
|
369 |
if not r.is_success: |
|
370 |
raise Exception(_(astakos_messages.QH_SYNC_ERROR)) |
|
371 |
else: |
|
372 |
project.last_application_synced = app |
|
373 |
project.save() |
|
374 |
sender, recipients, subject, message |
|
375 |
notification = build_notification( |
|
376 |
settings.SERVER_EMAIL, |
|
377 |
[project.owner.email], |
|
378 |
_('Project application has been approved on %s alpha2 testing' % SITENAME), |
|
379 |
_('Your application request %(serial)s has been apporved.') |
|
380 |
) |
|
381 |
notification.send() |
|
382 |
|
|
383 |
|
|
384 |
@safe |
|
385 |
def list_projects(self, filter_property=None): |
|
386 |
if filter_property: |
|
387 |
q = filter_queryset_by_property( |
|
388 |
Project.objects.all(), |
|
389 |
filter_property |
|
390 |
) |
|
391 |
return map(lambda o: self._details(o), q) |
|
392 |
return self._list(Project) |
|
393 |
|
|
394 |
|
|
395 |
|
|
396 |
@safe |
|
397 |
def add_project_member(self, serial, user_id, request_user): |
|
398 |
project = self._lookup_object(Project, serial=serial) |
|
399 |
user = self.lookup_user(user_id) |
|
400 |
if not project.owner == request_user: |
|
401 |
raise Exception(_(astakos_messages.NOT_PROJECT_OWNER)) |
|
402 |
|
|
403 |
if not project.is_alive: |
|
404 |
raise Exception(_(astakos_messages.NOT_ALIVE_PROJECT) % project.__dict__) |
|
405 |
if len(project.members) + 1 > project.limit_on_members_number: |
|
406 |
raise Exception(_(astakos_messages.MEMBER_NUMBER_LIMIT_REACHED)) |
|
407 |
m = self._lookup_object(ProjectMembership, person=user, project=project) |
|
408 |
if m.is_accepted: |
|
409 |
return |
|
410 |
m.is_accepted = True |
|
411 |
m.decision_date = datetime.now() |
|
412 |
m.save() |
|
413 |
notification = build_notification( |
|
414 |
settings.SERVER_EMAIL, |
|
415 |
[user.email], |
|
416 |
_('Your membership on project %(name)s has been accepted.') % project.definition.__dict__, |
|
417 |
_('Your membership on project %(name)s has been accepted.') % project.definition.__dict__, |
|
418 |
) |
|
419 |
notification.send() |
|
420 |
|
|
421 |
@safe |
|
422 |
def remove_project_member(self, serial, user_id, request_user): |
|
423 |
project = self._lookup_object(Project, serial=serial) |
|
424 |
if not project.is_alive: |
|
425 |
raise Exception(_(astakos_messages.NOT_ALIVE_PROJECT) % project.__dict__) |
|
426 |
if not project.owner == request_user: |
|
427 |
raise Exception(_(astakos_messages.NOT_PROJECT_OWNER)) |
|
428 |
user = self.lookup_user(user_id) |
|
429 |
m = self._lookup_object(ProjectMembership, person=user, project=project) |
|
430 |
if not m.is_accepted: |
|
431 |
return |
|
432 |
m.is_accepted = False |
|
433 |
m.decision_date = datetime.now() |
|
434 |
m.save() |
|
435 |
notification = build_notification( |
|
436 |
settings.SERVER_EMAIL, |
|
437 |
[user.email], |
|
438 |
_('Your membership on project %(name)s has been removed.') % project.definition.__dict__, |
|
439 |
_('Your membership on project %(name)s has been removed.') % project.definition.__dict__, |
|
440 |
) |
|
441 |
notification.send() |
|
442 |
|
|
443 |
@safe |
|
444 |
def suspend_project(self, serial): |
|
445 |
project = self._lookup_object(Project, serial=serial) |
|
446 |
project.suspend() |
|
447 |
notification = build_notification( |
|
448 |
settings.SERVER_EMAIL, |
|
449 |
[project.owner.email], |
|
450 |
_('Project %(name)s has been suspended on %s alpha2 testing' % SITENAME), |
|
451 |
_('Project %(name)s has been suspended on %s alpha2 testing' % SITENAME) |
|
452 |
) |
|
453 |
notification.send() |
|
454 |
|
|
455 |
@safe |
|
456 |
def terminate_project(self, serial): |
|
457 |
project = self._lookup_object(Project, serial=serial) |
|
458 |
project.termination() |
|
459 |
notification = build_notification( |
|
460 |
settings.SERVER_EMAIL, |
|
461 |
[project.owner.email], |
|
462 |
_('Project %(name)s has been terminated on %s alpha2 testing' % SITENAME), |
|
463 |
_('Project %(name)s has been terminated on %s alpha2 testing' % SITENAME) |
|
464 |
) |
|
465 |
notification.send() |
|
466 |
|
|
467 |
@safe |
|
468 |
def synchonize_project(self, serial): |
|
469 |
project = self._lookup_object(Project, serial=serial) |
|
470 |
project.sync() |
|
322 |
return self._details(g) |
Also available in: Unified diff