Skip to content

Commit

Permalink
#212 Presentation of ActionLogs
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylampada committed Jan 2, 2014
1 parent 28bd75f commit dfefc6c
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 14 deletions.
39 changes: 28 additions & 11 deletions djangoproject/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,18 @@ def get_image3x1(self):
def get_tags(self):
return Tag.objects.filter(objtype="Project", objid=self.id)

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

def to_json(self):
return json.dumps(self.to_dict_json())

def __unicode__(self):
return self.name
Expand Down Expand Up @@ -385,12 +388,16 @@ def changeIssue(self, issuedict):
self.title = issuedict.get('title')
self.touch()

def to_json(self):
return json.dumps({
def to_dict_json(self):
return {
'id': self.id,
'title': self.title,
'description': self.description
})
'description': self.description,
'link': self.get_view_link(),
}

def to_json(self):
return json.dumps(self.to_dict_json())

def getTotalOffersPriceUSD(self):
return self.getTotalOffersPrice_by_currency('USD')
Expand Down Expand Up @@ -567,16 +574,19 @@ class Offer(models.Model):
REVOKED = "REVOKED"
PAID = "PAID"

def to_json(self):
return json.dumps({
def to_dict_json(self):
return {
'id': self.id,
'price': float(str(self.price)),
'currency': self.currency,
'acceptanceCriteria': self.acceptanceCriteria,
'no_forking': self.no_forking,
'require_release': self.require_release,
'status': self.status,
})
}

def to_json(self):
return json.dumps(self.to_dict_json())

@classmethod
def newOffer(cls, issue, sponsor, price, currency, acceptanceCriteria, no_forking, require_release, expiration_days):
Expand Down Expand Up @@ -915,11 +925,13 @@ class PaymentPart(models.Model):
solution = models.ForeignKey(Solution)
paypalEmail = models.EmailField(max_length=256, null=True)
price = models.DecimalField(max_digits=16, decimal_places=8)
money_sent = models.ForeignKey(MoneySent, null = True)
money_sent = models.ForeignKey(MoneySent, null=True)

def to_dict_json(self):
return {
'programmer_id': self.programmer.id,
'programmer_image': self.programmer.gravatar_url_small(),
'programmer_screenname': self.programmer.getUserInfo().screenname,
'solution_id': self.solution.id,
'price': float(str(self.price)) if self.price else None,
}
Expand Down Expand Up @@ -970,10 +982,15 @@ def to_dict_json(self):
'action': self.action,
'entity': self.entity,
# 'creationDate': self.id,
'user_image': self.user.gravatar_url_medium(),
'user_screenname': self.user.getUserInfo().screenName,
'user_id': self.user.id,
'project_id': self.project.id if self.project else None,
'project': self.project.to_dict_json() if self.project else None,
'issue_id': self.issue.id if self.issue else None,
'issue': self.issue.to_dict_json() if self.issue else None,
'offer_id': self.offer.id if self.offer else None,
'offer': self.offer.to_dict_json() if self.offer else None,
'solution_id': self.solution.id if self.solution else None,
'issue_comment_id': self.issue_comment.id if self.issue_comment else None,
'old_json': self.old_json,
Expand Down
3 changes: 2 additions & 1 deletion djangoproject/core/services/activity_services.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from core.models import ActionLog
from django.db.models import Q

__author__ = 'tony'


def get_latest_activity(project_id):
query = ActionLog.objects.all()
if project_id:
query = query.filter(project__id=project_id)
query = query.filter(Q(project__id=project_id) & (~Q(action__in=['ADD_ISSUE_COMMENT', 'EDIT_ISSUE_COMMENT'])))
query = query.order_by('-creationDate')
return query[0:10]
75 changes: 73 additions & 2 deletions djangoproject/statfiles/static/js/activitylist/activitylist.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,76 @@
<div>
<div ng-repeat="activity in activities">
{[{describe(activity)}]}
<div ng-repeat="activity in activities" style="border: solid 1px; margin-bottom: 20px">
<div ng-switch on="activity.action">
<div ng-switch-when="EDIT_PROJECT">
{[{ activity.when }]}<br>
<img ng-src="{[{activity.user_image}]}"> {[{ activity.user_screenname }]}
has edited project details. <a href="#">More...</a>
</div>
<div ng-switch-when="PROJECT_ADD_TAG">
{[{ activity.when }]}<br>
<img ng-src="{[{activity.user_image}]}"> {[{ activity.user_screenname }]}
added tag <strong>{[{ activity.new_json }]}</strong> to project.
</div>
<div ng-switch-when="PROJECT_REMOVE_TAG">
{[{ activity.when }]}<br>
<img ng-src="{[{activity.user_image}]}"> {[{ activity.user_screenname }]}
removed tag <strong>{[{ activity.new_json }]}</strong> from project.
</div>
<div ng-switch-when="SPONSOR">
{[{ activity.when }]}<br>
<img ng-src="{[{activity.user_image}]}"> {[{ activity.user_screenname }]}
sponsored issue <a href="{[{ activity.issue.link }]}">{[{ activity.issue.title }]}</a>,
with a {[{ activity.new_dic.currency }]} {[{ activity.new_dic.price }]} offer.
</div>
<div ng-switch-when="CHANGE_OFFER">
{[{ activity.when }]}<br>
has changed his offer on issue <a href="{[{ activity.issue.link }]}">{[{ activity.issue.title }]} </a>
<a href="#">More...</a>
</div>
<div ng-switch-when="REVOKE">
{[{ activity.when }]}<br>
<img ng-src="{[{activity.user_image}]}"> {[{ activity.user_screenname }]}
revoked his {[{ activity.new_dic.currency }]} {[{ activity.new_dic.price }]} offer
on issue <a href="{[{ activity.issue.link }]}">{[{ activity.issue.title }]} </a>
<a href="#">More...</a>
</div>
<div ng-switch-when="PROPOSE">
{[{ activity.when }]}<br>
<img ng-src="{[{activity.user_image}]}"> {[{ activity.user_screenname }]}
proposed issue <a href="{[{ activity.issue.link }]}">{[{ activity.issue.title }]} </a>
</div>
<div ng-switch-when="WORK">
{[{ activity.when }]}<br>
<img ng-src="{[{activity.user_image}]}"> {[{ activity.user_screenname }]}
started working on issue <a href="{[{ activity.issue.link }]}">{[{ activity.issue.title }]} </a>
<a href="#">More...</a>
</div>
<div ng-switch-when="ABORT">
{[{ activity.when }]}<br>
<img ng-src="{[{activity.user_image}]}"> {[{ activity.user_screenname }]}
stopped working on issue <a href="{[{ activity.issue.link }]}">{[{ activity.issue.title }]} </a>
<a href="#">More...</a>
</div>
<div ng-switch-when="RESOLVE">
{[{ activity.when }]}<br>
<img ng-src="{[{activity.user_image}]}"> {[{ activity.user_screenname }]}
resolved issue <a href="{[{ activity.issue.link }]}">{[{ activity.issue.title }]} </a>
</div>
<div ng-switch-when="PAY">
{[{ activity.when }]}<br>
<img ng-src="{[{activity.user_image}]}"> {[{ activity.user_screenname }]}
made a {[{ activity.new_dic.currency }]} {[{ activity.new_dic.total }]} payment
for issue <a href="{[{ activity.issue.link }]}">{[{ activity.issue.title }]} </a><br>
Receivers:<br>
<ul>
<li ng-repeat="part in activity.new_dic.parts">
<img ng-src="{[{part.programmer_image}]}"> {[{ part.programmer_screenname }]}: {[{ activity.new_dic.currency }]} {[{ part.price }]}
</li>
</ul>
</div>
<div ng-switch-default>
Unknown activity: {[{activity.action }]}
</div>
</div>
</div>
</div>
13 changes: 13 additions & 0 deletions djangoproject/statfiles/static/js/activitylist/activitylist.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,21 @@ mod.directive('activitylist', function() {
},
templateUrl: '/static/js/activitylist/activitylist.html',
controller: function ($scope, FSApi) {

var instrument = function(activity){
try{
activity.new_dic = JSON.parse(activity.new_json);
activity.old_dic = JSON.parse(activity.old_json);
} catch(err){
//that's ok
}
};

FSApi.get_latest_activity($scope.projectId).onResult(function(result){
$scope.activities=result;
for(var i=0; i < $scope.activities.length; i++){
instrument($scope.activities[i])
}
$scope.$digest();
});

Expand Down

0 comments on commit dfefc6c

Please sign in to comment.