Commit 75de51da authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Project update and suspend functions

parent 87e3bf3f
......@@ -165,14 +165,6 @@ def send_account_creation_notification(template_name, dictionary=None):
return _send_admin_notification(template_name, dictionary, subject=subject)
def send_group_creation_notification(template_name, dictionary=None):
group = dictionary.get('group')
if not group:
return
subject = _(GROUP_CREATION_SUBJECT) % {'group':group.get('name', '')}
return _send_admin_notification(template_name, dictionary, subject=subject)
def send_helpdesk_notification(user, template_name='im/helpdesk_notification.txt'):
"""
Send email to DEFAULT_CONTACT_EMAIL to notify for a new user activation.
......@@ -425,6 +417,13 @@ def get_project_by_application_id(project_application_id):
raise IOError(
_(astakos_messages.UNKNOWN_PROJECT_APPLICATION_ID) % project_application_id)
def get_project_by_id(project_id):
try:
return Project.objects.get(id=project_id)
except Project.DoesNotExist:
raise IOError(
_(astakos_messages.UNKNOWN_PROJECT_ID) % project_id)
def get_user_by_id(user_id):
try:
return AstakosUser.objects.get(id=user_id)
......@@ -623,3 +622,37 @@ def approve_application(application):
notification.send()
except NotificationError, e:
logger.error(e.message)
def terminate(project_id):
project = get_project_by_id(project_id)
project.set_termination_start_date()
trigger_sync()
project.set_termination_date()
try:
notification = build_notification(
settings.SERVER_EMAIL,
[project.application.owner.email],
_(PROJECT_TERMINATION_SUBJECT) % project.__dict__,
template='im/projects/project_termination_notification.txt',
dictionary={'object':project.application}
).send()
except NotificationError, e:
logger.error(e.message)
def suspend(project_id):
project = get_project_by_id(project_id)
project.last_approval_date = None
project.save()
trigger_sync()
try:
notification = build_notification(
settings.SERVER_EMAIL,
[project.application.owner.email],
_(PROJECT_SUSPENSION_SUBJECT) % project.__dict__,
template='im/projects/project_suspension_notification.txt',
dictionary={'object':project.application}
).send()
except NotificationError, e:
logger.error(e.message)
......@@ -41,7 +41,9 @@ from django.http import Http404
from astakos.im.models import (
ProjectApplication, Project)
@transaction.commit_on_success
from astakos.im.functions import terminate, suspend
@transaction.commit_manually
class Command(BaseCommand):
args = "<project id>"
help = "Update project state"
......@@ -69,15 +71,12 @@ class Command(BaseCommand):
raise CommandError('Invalid id')
else:
try:
# Is it a project id?
p = lookup_object(Project, id, None, None)
except Http404:
raise CommandError('Invalid id')
if options['terminate']:
terminate(id)
elif options['suspend']:
suspend(id)
except BaseException, e:
transaction.rollback()
raise CommandError(e)
else:
try:
if options['terminate']:
p.terminate()
elif options['suspend']:
p.suspend()
except BaseException, e:
raise CommandError(e)
transaction.commit()
......@@ -173,6 +173,7 @@ ADD_PROJECT_MEMBERS_Q_HELP = 'Add a comma separated list of user
MISSING_IDENTIFIER = 'Missing identifier.'
UNKNOWN_USER_ID = 'There is no user identified by %s.'
UNKNOWN_PROJECT_APPLICATION_ID = 'There is no project application identified by %s.'
UNKNOWN_PROJECT_ID = 'There is no project identified by %s.'
UNKNOWN_IDENTIFIER = 'Unknown identifier.'
PENDING_MEMBERSHIP_LEAVE = 'Your request is pending moderation by the Project owner.'
USER_JOINED_PROJECT = '%(realname)s has joined the Project.'
......
......@@ -1644,43 +1644,15 @@ class Project(models.Model):
m = ProjectMembership.objects.get(person=user, project=self)
m.remove()
def terminate(self):
def set_termination_start_date(self):
self.termination_start_date = datetime.now()
self.terminaton_date = None
self.save()
rejected = self.sync()
if not rejected:
self.termination_start_date = None
self.termination_date = datetime.now()
self.save()
# try:
# notification = build_notification(
# settings.SERVER_EMAIL,
# [self.application.owner.email],
# _(PROJECT_TERMINATION_SUBJECT) % self.__dict__,
# template='im/projects/project_termination_notification.txt',
# dictionary={'object':self.application}
# ).send()
# except NotificationError, e:
# logger.error(e.message)
def suspend(self):
self.last_approval_date = None
def set_termination_date(self):
self.termination_start_date = None
self.termination_date = datetime.now()
self.save()
self.sync()
# try:
# notification = build_notification(
# settings.SERVER_EMAIL,
# [self.application.owner.email],
# _(PROJECT_SUSPENSION_SUBJECT) % self.__dict__,
# template='im/projects/project_suspension_notification.txt',
# dictionary={'object':self.application}
# ).send()
# except NotificationError, e:
# logger.error(e.message)
class ProjectMembership(models.Model):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment