Skip to content

Commit

Permalink
bug 595886, Activity Feed page
Browse files Browse the repository at this point in the history
  • Loading branch information
davedash committed Nov 8, 2010
1 parent 719dd82 commit 16396b7
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 77 deletions.
27 changes: 13 additions & 14 deletions apps/amo/log.py
Expand Up @@ -10,30 +10,30 @@

class CREATE_ADDON:
id = 1
format = _(u'{user.name} created addon {addon.name}')
format = _(u'{addon} was created.')
keep = True


class EDIT_PROPERTIES:
""" Expects: addon """
id = 2
format = _(u'{user.name} edited addon {addon.name} properties')
format = _(u'{user.name} edited addon {addon} properties')


class EDIT_DESCRIPTIONS:
id = 3
format = _(u'{user.name} edited addon {addon.name} description')
format = _(u'{user.name} edited addon {addon} description')


class EDIT_CATEGORIES:
id = 4
format = _(u'{user.name} edited categories for {addon.name}')
format = _(u'{user.name} edited categories for {addon}')


class ADD_USER_WITH_ROLE:
id = 5
format = _(u'{user.name} added {0.name} to '
'addon {addon.name} with role {1}')
'addon {addon} with role {1}')
keep = True


Expand All @@ -46,18 +46,18 @@ class REMOVE_USER_WITH_ROLE:

class EDIT_CONTRIBUTIONS:
id = 7
format = _(u'{user.name} edited contributions for {addon.name}')
format = _(u'{user.name} edited contributions for {addon}')


class SET_INACTIVE:
id = 8
format = _(u'{user.name} set addon {addon.name} inactive')
format = _(u'{addon} set inactive')
keep = True


class UNSET_INACTIVE:
id = 9
format = _(u'{user.name} activated addon {addon.name}')
format = _(u'{user.name} activated addon {addon}')
keep = True


Expand Down Expand Up @@ -97,7 +97,7 @@ class DELETE_PREVIEW:

class ADD_VERSION:
id = 16
format = _(u'{user.name} added version {0.version} to {addon}')
format = _(u'{version} added to {addon}.')
keep = True


Expand Down Expand Up @@ -125,8 +125,7 @@ class DELETE_FILE_FROM_VERSION:
should be strings and not the object.
"""
id = 20
format = _(u'{user.name} deleted file {0} '
'from {addon} version {1}')
format = _(u'File {0} deleted from {version} of {addon}')


class APPROVE_VERSION:
Expand Down Expand Up @@ -170,17 +169,17 @@ class REMOVE_TAG:

class ADD_TO_COLLECTION:
id = 27
format = _(u'{user.name} added addon {addon} to a collection {0.name}')
format = _(u'{addon} added to {collection}.')


class REMOVE_FROM_COLLECTION:
id = 28
forma = _(u'{user.name} removed addon {addon} from a collection {0.name}')
forma = _(u'{addon} removed from {collection}')


class ADD_REVIEW:
id = 29
format = _(u'{user.name} wrote a review about {addon}')
format = _(u'{review} for {addon} written.')


class ADD_RECOMMENDED_CATEGORY:
Expand Down
61 changes: 49 additions & 12 deletions apps/devhub/models.py
@@ -1,16 +1,20 @@
from copy import copy
from datetime import datetime
import json

from django.db import models

import commonware.log
from tower import ugettext_lazy as _

import amo
import amo.models
from addons.models import Addon
from users.models import UserProfile
from bandwagon.models import Collection
from reviews.models import Review
from translations.fields import TranslatedField

from users.models import UserProfile
from versions.models import Version

log = commonware.log.getLogger('devhub')

Expand Down Expand Up @@ -79,13 +83,20 @@ class Meta:


class ActivityLogManager(amo.models.ManagerBase):
def for_addon(self, addon, limit=20, offset=0):
vals = (AddonLog.objects.filter(addon=addon)[offset:limit]
def for_addons(self, addons):
if isinstance(addons, Addon):
addons = (addons,)

vals = (AddonLog.objects.filter(addon__in=addons)
.values_list('activity_log', flat=True))
return self.filter(pk__in=list(vals))

def for_user(self, user, limit=20, offset=0):
vals = (UserLog.objects.filter(user=user)[offset:limit]
if vals:
return self.filter(pk__in=list(vals))
else:
return self.none()

def for_user(self, user):
vals = (UserLog.objects.filter(user=user)
.values_list('activity_log', flat=True))
return self.filter(pk__in=list(vals))

Expand Down Expand Up @@ -169,22 +180,48 @@ def log(cls, request, action, arguments=None):
# TODO(davedash): Support other types.
def to_string(self, type='default'):
log_type = amo.LOG_BY_ID[self.action]
arguments = self.arguments

# We need to copy arguments so we can remove elements from it
# while we loop over self.arguments.
arguments = copy(self.arguments)
addon = None
for arg in arguments:
review = None
version = None
collection = None
for arg in self.arguments:
if isinstance(arg, Addon) and not addon:
addon = arg
break
addon = u'<a href="%s">%s</a>' % (arg.get_url_path(), arg.name)
arguments.remove(arg)
if isinstance(arg, Review) and not review:
review = u'<a href="%s">%s</a>' % (arg.get_url_path(),
_('Review'))
arguments.remove(arg)
if isinstance(arg, Version) and not version:
text = _('Version %s') % arg.version
version = u'<a href="%s">%s</a>' % (arg.get_url_path(), text)
arguments.remove(arg)
if isinstance(arg, Collection) and not collection:
collection = u'<a href="%s">%s</a>' % (arg.get_url_path(),
arg.name)
arguments.remove(arg)

return log_type.format.format(*arguments, user=self.user, addon=addon)
try:
data = dict(user=self.user, addon=addon, review=review,
version=version, collection=collection)
return log_type.format.format(*arguments, **data)
except (AttributeError, KeyError, IndexError):
log.warning('%d contains garbage data' % self.id)
return 'Something magical happened.'

def __unicode__(self):
return self.to_string()

class Meta:
db_table = 'log_activity'
ordering = ('-created',)


# TODO(davedash): Remove after we finish the import.
class LegacyAddonLog(models.Model):
TYPES = [(value, key) for key, value in amo.LOG.items()]

Expand Down
54 changes: 24 additions & 30 deletions apps/devhub/templates/devhub/addons/activity.html
Expand Up @@ -5,7 +5,7 @@
{% endblock %}

{% block rss_feed %}
{# TODO: Add ``<link>`` to 'Recent Activity' RSS feed. #}
{# TODO(davedash): Add ``<link>`` to 'Recent Activity' RSS feed. #}
{% endblock %}

{% block content %}
Expand All @@ -17,14 +17,25 @@ <h2>{{ _('Recent Activity for My Add-ons') }}</h2>
<section class="primary" role="main">
<div class="listing results">
<div class="results-inner">
{% if pager.object_list %}
{% for item in pager.object_list %}
<div class="item">
<p>{{ item|safe }}</p>
<p>
{% trans user=item.user|user_link, ago=item.created|timesince %}
{{ ago }} by {{ user }}
{% endtrans %}
</p>

{# TODO(cvan): Add item for each activity update. #}
<div class="item">
<p><a href="#">Version 1.3</a> of <a href="#">Test Pilot</a> added.</p>
<p>30 min ago by <a href="#">Mozilla Labs</a></p>
</div>

</div>
{% endfor %}
{% else %}
<p class="no-results">{{ _('No results found.') }}</p>
{% endif %}
</div>
{% if pager.has_other_pages() %}
<div class="listing-footer">{{ pager|paginator }}</div>
{% endif %}
</div>
</section>

Expand All @@ -37,36 +48,19 @@ <h3>{{ _('Refine Activity') }}</h3>
<h5>{{ _('Add-on') }}</h5>

<ul class="refinements">
{# TODO(cvan): Add list items for each refinement item. #}
<li class="selected">
<a href="#">{{ _('All My Add-ons') }}</a>
</li>
<li><a href="#">{{ _('Firefox Sync') }}</a></li>
<li><a href="#">{{ _('Personas Plus') }}</a></li>
<li><a href="#">{{ _('Test Pilot') }}</a></li>

{# for item in addons #}
{# include 'devhub/includes/refinement.html' #}
{# endfor #}
{% for item in addons %}
{% include 'includes/refinement.html' %}
{% endfor %}
</ul>
</div>

<div id="refine-activity">
<h5>{{ _('Activity') }}</h5>

<ul class="refinements">
{# TODO(cvan): Add list items for each refinement item. #}
<li class="selected">
<a href="#">{{ _('All Activity') }}</a>
</li>
<li><a href="#">{{ _('Add-on Updates') }}</a></li>
<li><a href="#">{{ _('Add-on Status') }}</a></li>
<li><a href="#">{{ _('User Collections') }}</a></li>
<li><a href="#">{{ _('User Reviews') }}</a></li>

{# for item in activities #}
{# include 'devhub/includes/refinement.html' #}
{# endfor #}
{% for item in activities %}
{% include 'includes/refinement.html' %}
{% endfor %}
</ul>
</div>

Expand Down
Binary file modified apps/devhub/tests/locale/zz/LC_MESSAGES/django.mo
Binary file not shown.
4 changes: 2 additions & 2 deletions apps/devhub/tests/locale/zz/LC_MESSAGES/django.po
Expand Up @@ -17,5 +17,5 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "{user.name} added {0.name} to addon {addon.name} with role {1}"
msgstr "(ZZ) {user.name} added {0.name} to addon {addon.name} with role {1}"
msgid "{user.name} added {0.name} to addon {addon} with role {1}"
msgstr "(ZZ) {user.name} added {0.name} to addon {addon} with role {1}"
6 changes: 3 additions & 3 deletions apps/devhub/tests/test_models.py
Expand Up @@ -26,11 +26,11 @@ def test_basic(self):
request = self.request
a = Addon.objects.get()
ActivityLog.log(request, amo.LOG['CREATE_ADDON'], a)
entries = ActivityLog.objects.for_addon(a)
entries = ActivityLog.objects.for_addons(a)
eq_(len(entries), 1)
eq_(entries[0].arguments[0], a)
eq_(unicode(entries[0]),
'Joe CamelCase created addon Delicious Bookmarks')
for x in ('Delicious Bookmarks', 'was created.'):
assert x in unicode(entries[0])

def test_json_failboat(self):
request = self.request
Expand Down

0 comments on commit 16396b7

Please sign in to comment.