Skip to content

Commit

Permalink
#212 Log project edition
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylampada committed Dec 26, 2013
1 parent e41ade5 commit 6b50cdf
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 2 deletions.
42 changes: 41 additions & 1 deletion djangoproject/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ def get_image3x1(self):
def get_tags(self):
return Tag.objects.filter(objtype="Project", objid=self.id)

def to_json(self):
return json.dumps({
'id': self.id,
'name': self.name,
'homeURL': self.homeURL,
'trackerURL': self.trackerURL,
'image3x1': self.image3x1.url if self.image3x1 else None,
})

def __unicode__(self):
return self.name

Expand Down Expand Up @@ -993,7 +1002,38 @@ def log_edit_issue(cls, issue, old_json):

@classmethod
def log_edit_project(cls, project, user, old_json):
pass
new_json = project.to_json()
ActionLog(
creationDate=timezone.now(),
action='EDIT_PROJECT',
entity='PROJECT',
old_json=old_json,
new_json=new_json,
project=project,
user=user,
).save()

@classmethod
def log_project_tag_added(cls, user, project_id, tag_name):
ActionLog(
creationDate=timezone.now(),
action='PROJECT_ADD_TAG',
entity='PROJECT',
new_json=tag_name,
project=Project(id=project_id),
user=user,
).save()

@classmethod
def log_project_tag_removed(cls, user, project_id, tag_name):
ActionLog(
creationDate=timezone.now(),
action='PROJECT_REMOVE_TAG',
entity='PROJECT',
new_json=tag_name,
project=Project(id=project_id),
user=user,
).save()

@classmethod
def log_sponsor(cls, offer):
Expand Down
2 changes: 2 additions & 0 deletions djangoproject/core/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__author__ = 'tony'

import action_services
20 changes: 20 additions & 0 deletions djangoproject/core/services/action_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from core.models import ActionLog
from core.signals import project_edited, project_tag_added, project_tag_removed

__author__ = 'tony'
from django.dispatch import receiver


@receiver(project_edited)
def on_project_edited(sender, **kwargs):
ActionLog.log_edit_project(kwargs['project'], kwargs['user'], kwargs['old_json'])


@receiver(project_tag_added)
def on_project_tag_added(sender, **kwargs):
ActionLog.log_project_tag_added(kwargs['user'], kwargs['project_id'], kwargs['tag_name'])


@receiver(project_tag_removed)
def on_project_tag_removed(sender, **kwargs):
ActionLog.log_project_tag_removed(kwargs['user'], kwargs['project_id'], kwargs['tag_name'])
7 changes: 7 additions & 0 deletions djangoproject/core/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__author__ = 'tony'
from django.dispatch import Signal


project_edited = Signal(providing_args=["user", "project", "old_json"])
project_tag_added = Signal(providing_args=["user", "project_id", "tag_name"])
project_tag_removed = Signal(providing_args=["user", "project_id", "tag_name"])
11 changes: 11 additions & 0 deletions djangoproject/core/views/json_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Create your views here.
from django.views.decorators.csrf import csrf_exempt
from core.signals import project_tag_added, project_tag_removed

from core.models import *
from django.http import HttpResponse
Expand Down Expand Up @@ -77,6 +78,11 @@ def add_tag(request):
if not objtype in ['Project', 'Issue']:
raise BaseException('Wrong objtype: %s' % objtype)
tag_services.addTag(name, objtype, objid)
project_tag_added.send(
sender=None,
user=request.user,
project_id=objid,
tag_name=name)
return HttpResponse('')


Expand All @@ -87,6 +93,11 @@ def remove_tag(request):
objtype = request.POST.get('objtype')
objid = int(request.POST.get('objid'))
tag_services.removeTag(name, objtype, objid)
project_tag_removed.send(
sender=None,
user=request.user,
project_id=objid,
tag_name=name)
return HttpResponse('')


Expand Down
7 changes: 7 additions & 0 deletions djangoproject/core/views/project_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.template import RequestContext
from core.models import Project
from core.services import stats_services
from core.signals import project_edited
from core.views import template_folder

__author__ = 'tony'
Expand All @@ -28,10 +29,16 @@ def edit_form(request, project_id):
def edit(request):
project_id = int(request.POST.get('id'))
project = Project.objects.get(pk=project_id)
old_project_json = project.to_json()
if 'image3x1' in request.FILES and request.FILES['image3x1']:
project.image3x1 = request.FILES['image3x1']
project.description = request.POST.get('description')
project.save()
project_edited.send(
sender=None,
user=request.user,
project=project,
old_json=old_project_json)
return redirect('core.views.project_views.view', project_id=project.id)


Expand Down
2 changes: 1 addition & 1 deletion djangoproject/templates/core2/project_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
);

mod.controller("MyCtrl", function($scope){
$scope.description = '{{ project.description }}';
$scope.description = '{{ project.description|escapejs }}';
});
</script>
{% endblock %}
Expand Down

0 comments on commit 6b50cdf

Please sign in to comment.