Skip to content

Commit

Permalink
[#1079] Add admin log entry when approving an employment in MyRSR
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Apr 1, 2015
1 parent a4ccab4 commit 551d101
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion akvo/rest/views/employment.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def approve_employment(request, pk=None):
if not user.has_perm('rsr.change_employment', employment):
raise PermissionDenied

employment.approve()
employment.approve(user)

return Response({'status': 'employment approved'})

Expand Down
22 changes: 20 additions & 2 deletions akvo/rsr/models/employment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.


from django.contrib.admin.models import LogEntry, CHANGE
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models.query import QuerySet
from django.forms.models import model_to_dict
from django.utils.encoding import force_unicode
from django.utils.translation import ugettext_lazy as _


from .models_utils import QuerySetManager

from ..fields import ValidXMLCharField
Expand Down Expand Up @@ -59,11 +62,26 @@ class Meta:
def __unicode__(self):
return u"{0} {1}: {2}".format(self.user.first_name, self.user.last_name, self.organisation.name)

def approve(self):
def approve(self, approved_by):
"""
Approve an Employment. Will also be logged in the Employment admin history.
:param approved_by: User that approves the Employment
"""
if not self.is_approved:
self.is_approved = True
self.save()

# Log in Employment admin history
LogEntry.objects.log_action(
user_id=approved_by.pk,
content_type_id=ContentType.objects.get_for_model(self).pk,
object_id=self.pk,
object_repr=force_unicode(self),
action_flag=CHANGE,
change_message=u'Changed is_approved, outside of admin.'
)

def to_dict(self, org_list):
country = '' if not self.country else model_to_dict(self.country)
# Set groups in right order
Expand Down

0 comments on commit 551d101

Please sign in to comment.