Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Madison Scott-Clary committed Oct 30, 2016
1 parent cd34bb0 commit 95d6194
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cleanmigrations: venv/bin/django-admin
@echo "In case @makyo does not delete this before first alpha, do not"
@echo "run this target. Migrations are hecka important for dev after"
@echo "that point!"
@exit 1 # We really shouldn't do this, but may need to in the future
exit 1 # We really shouldn't do this, but may need to in the future
@echo
@echo "Psst, @makyo, don't forget to delete this target!"
@sleep 5
Expand Down
6 changes: 5 additions & 1 deletion activitystream/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ class Activity(models.Model):

# Promotions
('PROMOTION:CREATE', 'Promotion: created'),
('PROMOTION:RETIRED', 'Promotion: retired'),
('PROMOTION:RETIRE', 'Promotion: retired'),
('AD:CREATE', 'Ad: created,'),
('AD:UPDATE', 'Ad: update'),
('AD:GOLIVE', 'Ad: went live'),
('AD:RETIRE', 'Ad: retired'),

# Publisher pages
('PUBLISHER:CREATE', 'Publisher: created'),
Expand Down
3 changes: 3 additions & 0 deletions activitystream/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
urlpatterns = [
url('^$', views.sitewide_data, name='sitewide_data'),
url('^stream/$', views.get_stream, name='get_stream'),
url('^stream/(?P<models>[\w_:]+)/$', views.get_stream, name='get_stream'),
url('^stream/(?P<models>[\w_:]+)/(?P<object_id>\d+)',
views.get_stream, name='get_stream'),
]
27 changes: 11 additions & 16 deletions activitystream/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
)
from django.contrib.contenttypes.models import ContentType
from django.http import (HttpResponse)
from django.shortcuts import get_object_or_404
from django.views.decorators.cache import cache_page
from taggit.models import (
Tag,
Expand All @@ -33,37 +32,33 @@
from usermgmt.group_models import FriendGroup


def generate_stream_entry(activity, ctype, instance):
def generate_stream_entry(activity):
entry = {
'time': activity.activity_time.strftime('%Y-%m-%dT%H:%M:%S'),
'type': activity.activity_type,
}
if instance is not None:
entry['instance'] = "{}: {}".format(ctype.name, str(instance))
elif activity.content_type:
if activity.content_type:
entry['instance'] = "{}: {}".format(
activity.content_type.name, str(activity.object_model))
return entry


@cache_page(60 * 5)
def get_stream(request, app_label=None, model=None, object_id=None):
ctype = None
instance = None
@cache_page(60 * 15)
def get_stream(request, models=None, object_id=None):
stream = Activity.objects.select_related('content_type')
if app_label and model:
ctype = get_object_or_404(ContentType,
app_label=app_label, model=model)
stream = stream.filter(content_type=ctype)
if models:
expanded = [model.split(':') for model in models.split(',')]
ctypes = ContentType.objects.filter(
app_label__in=[i[0] for i in expanded],
model__in=[i[1] for i in expanded])
stream = stream.filter(content_type__in=ctypes)
if object_id:
stream = stream.filter(object_id=object_id)
instance = ctype.get_object_for_this_type(pk=object_id)
if request.GET.get('type') is not None:
stream = stream.filter(activity_type=request.GET['type'])
data = []
for activity in stream:
print(ctype)
data.append(generate_stream_entry(activity, ctype, instance))
data.append(generate_stream_entry(activity))
return HttpResponse(
json.dumps(data, separators=[',', ':']),
content_type='application/json')
Expand Down

0 comments on commit 95d6194

Please sign in to comment.