This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
First pass at activitystreams #28
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cd34bb0
First pass at activitystreams
95d6194
Cleanup
88601d1
revno work
64c49f9
Tests
9b38a4e
Trivial, forgot a few things
1948f92
Trivial, lint
8350ed8
Fix json.loads across versions
14a1d88
Tests, implement activity creation
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Release Process | ||
|
||
* Ensure that the project is clean across versions by running `make check` | ||
* Tag your release | ||
* ensure master is up to date: `git pull upstream master` | ||
* update the revno file: `TAG=<new tag> make update-revno` | ||
* relying on semver as an outline, make an empty commit specifying the release: `git commit -am "Releasing <new tag>"` | ||
* tag and sign the release: `git tag -s <new tag>` | ||
* Push the new tag | ||
* push the changes: `git push upstream master` | ||
* push the tags: `git push --tags upstream` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default_app_config = 'activitystream.apps.ActivitystreamConfig' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from __future__ import unicode_literals | ||
|
||
from django.apps import AppConfig | ||
|
||
|
||
class ActivitystreamConfig(AppConfig): | ||
name = 'activitystream' | ||
|
||
def ready(self): | ||
import activitystream.signals # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.2 on 2016-10-30 04:16 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('contenttypes', '0002_remove_content_type_name'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Activity', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('activity_time', models.DateTimeField(auto_now_add=True)), | ||
('activity_type', models.CharField(choices=[('USER:REG', 'User: registered'), ('USER:LOGIN', 'User: logged in'), ('USER:PWCHANGE', 'User: password changed'), ('USER:PWRESET', 'User: password reset'), ('USER:UPDATE', 'User: profile updated'), ('USER:VIEW', 'User: profile viewed'), ('GROUP:CREATE', 'Group: created'), ('GROUP:UPDATE', 'Group: updated'), ('GROUP:DELETE', 'Group: deleted'), ('GROUP:VIEW', 'Group: viewed'), ('SOCIAL:WATCH', 'Social: watch user'), ('SOCIAL:UNWATCH', 'Social: unwatch user'), ('SOCIAL:BLOCK', 'Social: block user'), ('SOCIAL:UNBLOCK', 'Social: unblock user'), ('SOCIAL:FAVORITE', 'Social: favorite submission'), ('SOCIAL:UNFAVORITE', 'Social: unfavorite submission'), ('SOCIAL:RATE', 'Social: rate submission'), ('SOCIAL:ENJOY', 'Social: enjoy submission'), ('SOCIAL:COMMENT', 'Social: object received comment'), ('SUBMISSION:CREATE', 'Submission: created'), ('SUBMISSION:UPDATE', 'Submission: updated'), ('SUBMISSION:DELETE', 'Submission: deleted'), ('SUBMISSION:VIEW', 'Submission: viewed'), ('FOLDER:CREATE', 'Folder: created'), ('FOLDER:UPDATE', 'Folder: updated'), ('FOLDER:DELETE', 'Folder: deleted'), ('FOLDER:VIEW', 'Folder: viewed'), ('FOLDER:SORT', 'Folder: sorted')], max_length=3)), | ||
('object_id', models.PositiveIntegerField()), | ||
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), | ||
], | ||
options={ | ||
'ordering': ['-activity_type'], | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.2 on 2016-10-30 07:19 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('activitystream', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='activity', | ||
options={'ordering': ['-activity_time']}, | ||
), | ||
migrations.AlterField( | ||
model_name='activity', | ||
name='activity_type', | ||
field=models.CharField(choices=[('USER:REG', 'User: registered'), ('USER:LOGIN', 'User: logged in'), ('USER:LOGOUT', 'User: logged out'), ('USER:PWCHANGE', 'User: password changed'), ('USER:PWRESET', 'User: password reset'), ('PROFILE:UPDATE', 'User: profile updated'), ('PROFILE:VIEW', 'User: profile viewed'), ('ADMINFLAG:CREATE', 'Administration flag: created'), ('ADMINFLAG:UPDATE', 'Administration flag: updated'), ('ADMINFLAG:DELETE', 'Administration flag: deleted'), ('ADMINFLAG:VIEW', 'Administration flag: viewed'), ('GROUP:CREATE', 'Group: created'), ('GROUP:UPDATE', 'Group: updated'), ('GROUP:DELETE', 'Group: deleted'), ('GROUP:VIEW', 'Group: viewed'), ('SOCIAL:WATCH', 'Social: watch user'), ('SOCIAL:UNWATCH', 'Social: unwatch user'), ('SOCIAL:BLOCK', 'Social: block user'), ('SOCIAL:UNBLOCK', 'Social: unblock user'), ('SOCIAL:FAVORITE', 'Social: favorite submission'), ('SOCIAL:UNFAVORITE', 'Social: unfavorite submission'), ('SOCIAL:RATE', 'Social: rate submission'), ('SOCIAL:ENJOY', 'Social: enjoy submission'), ('SUBMISSION:CREATE', 'Submission: created'), ('SUBMISSION:UPDATE', 'Submission: updated'), ('SUBMISSION:DELETE', 'Submission: deleted'), ('SUBMISSION:VIEW', 'Submission: viewed'), ('FOLDER:CREATE', 'Folder: created'), ('FOLDER:UPDATE', 'Folder: updated'), ('FOLDER:DELETE', 'Folder: deleted'), ('FOLDER:VIEW', 'Folder: viewed'), ('FOLDER:SORT', 'Folder: sorted'), ('TAG:CREATE', 'Tag: tag created'), ('TAG:TAG', 'Tag: tagged item created'), ('COMMENT:CREATE', 'Comment: created'), ('COMMENT:UPDATE', 'Comment: updated'), ('COMMENT:DELETE', 'Comment: deleted'), ('PROMOTION:CREATE', 'Promotion: created'), ('PROMOTION:RETIRED', 'Promotion: retired'), ('PUBLISHER:CREATE', 'Publisher: created'), ('PUBLISHER:UPDATE', 'Publisher: updated'), ('PUBLISHER:DELETE', 'Publisher: deleted'), ('PUBLISHER:VIEW', 'Publisher: viewed'), ('PUBLISHER:CLAIMED', 'Publisher: claimed'), ('SEARCH:SEARCH', 'Search: run')], max_length=50), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.2 on 2016-10-30 07:23 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('activitystream', '0002_auto_20161030_0719'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='activity', | ||
name='object_id', | ||
field=models.PositiveIntegerField(blank=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.2 on 2016-10-30 07:23 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('activitystream', '0003_auto_20161030_0723'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='activity', | ||
name='content_type', | ||
field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.2 on 2016-10-30 07:24 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('activitystream', '0004_auto_20161030_0723'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='activity', | ||
name='content_type', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType'), | ||
), | ||
migrations.AlterField( | ||
model_name='activity', | ||
name='object_id', | ||
field=models.PositiveIntegerField(blank=True, null=True), | ||
), | ||
] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models | ||
from django.contrib.contenttypes.fields import GenericForeignKey | ||
from django.contrib.contenttypes.models import ContentType | ||
|
||
|
||
class Activity(models.Model): | ||
ACTIVITY_TYPES = ( | ||
# Users and profiles | ||
('user:reg', 'user: registered'), | ||
('user:login', 'user: logged in'), | ||
('user:logout', 'user: logged out'), | ||
('user:pwchange', 'user: password changed'), # TODO | ||
('user:pwreset', 'user: password reset'), # TODO | ||
('profile:update', 'user: profile updated'), | ||
('profile:view', 'user: profile viewed'), | ||
|
||
# Administration flags | ||
('adminflag:create', 'administration flag: created'), | ||
('adminflag:update', 'administration flag: updated'), | ||
('adminflag:delete', 'administration flag: deleted'), | ||
('adminflag:view', 'administration flag: viewed'), | ||
|
||
# User groups | ||
('group:create', 'group: created'), | ||
('group:update', 'group: updated'), | ||
('group:delete', 'group: deleted'), | ||
|
||
# Social interactions | ||
('social:watch', 'social: watch user'), | ||
('social:unwatch', 'social: unwatch user'), | ||
('social:block', 'social: block user'), | ||
('social:unblock', 'social: unblock user'), | ||
('social:message', 'social: message user'), | ||
('social:favorite', 'social: favorite submission'), | ||
('social:unfavorite', 'social: unfavorite submission'), | ||
('social:rate', 'social: rate submission'), | ||
('social:enjoy', 'social: enjoy submission'), | ||
|
||
# Submissions | ||
('submission:create', 'submission: created'), | ||
('submission:update', 'submission: updated'), | ||
('submission:delete', 'submission: deleted'), | ||
('submission:view', 'submission: viewed'), | ||
|
||
# Submission folders | ||
('folder:create', 'folder: created'), | ||
('folder:update', 'folder: updated'), | ||
('folder:delete', 'folder: deleted'), | ||
('folder:view', 'folder: viewed'), | ||
('folder:sort', 'folder: sorted'), | ||
|
||
# Tags | ||
('tag:create', 'tag: tag created'), | ||
('tag:tag', 'tag: tagged item created'), | ||
|
||
# Comments | ||
('comment:create', 'comment: created'), | ||
('comment:update', 'comment: updated'), | ||
('comment:delete', 'comment: deleted'), | ||
|
||
# Promotions | ||
('promotion:create', 'promotion: created'), | ||
('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'), | ||
('publisher:update', 'publisher: updated'), | ||
('publisher:delete', 'publisher: deleted'), | ||
('publisher:view', 'publisher: viewed'), | ||
('publisher:claimed', 'publisher: claimed'), | ||
|
||
# Search | ||
('search:basic_search', 'search: basic search run'), | ||
) | ||
|
||
activity_time = models.DateTimeField(auto_now_add=True) | ||
activity_type = models.CharField(max_length=50, choices=ACTIVITY_TYPES) | ||
content_type = models.ForeignKey(ContentType, blank=True, null=True) | ||
object_id = models.PositiveIntegerField(blank=True, null=True) | ||
object_model = GenericForeignKey('content_type', 'object_id') | ||
|
||
@classmethod | ||
def create(cls, app, action, object_model): | ||
item_type = "{}:{}".format(app.lower(), action.lower()) | ||
if item_type not in dict(Activity.ACTIVITY_TYPES): | ||
return None # XXX should we fail silently? | ||
activity = cls(activity_type=item_type) | ||
activity.object_model = object_model | ||
activity.save() | ||
return activity | ||
|
||
class Meta: | ||
ordering = ['-activity_time'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from django.contrib.auth.signals import ( | ||
user_logged_in, | ||
user_logged_out, | ||
) | ||
from django.db.models.signals import ( | ||
post_delete, | ||
post_save, | ||
) | ||
from django.dispatch import receiver | ||
from taggit.models import TaggedItem | ||
|
||
from .models import Activity | ||
from usermgmt.models import Profile | ||
|
||
|
||
@receiver(post_save, sender=Profile) | ||
def log_user_register(sender, **kwargs): | ||
if kwargs['created']: | ||
Activity.create('user', 'reg', kwargs['instance'].user) | ||
|
||
|
||
@receiver(user_logged_in) | ||
def log_login(sender, **kwargs): | ||
Activity.create('user', 'login', kwargs['user']) | ||
|
||
|
||
@receiver(user_logged_out) | ||
def log_logout(sender, **kwargs): | ||
Activity.create('user', 'logout', kwargs['user']) | ||
|
||
|
||
@receiver(post_save) | ||
def log_base_create_or_update(sender, **kwargs): | ||
try: | ||
name = { | ||
'Flag': 'flag', | ||
'Folder': 'folder', | ||
'FriendGroup': 'group', | ||
'Profile': 'profile', | ||
'PublisherPage': 'publisher', | ||
'Submission': 'submission', | ||
'Tag': 'tag', | ||
}[sender.__name__] | ||
except: | ||
return | ||
if name == 'profile' and kwargs['created']: | ||
return | ||
Activity.create( | ||
name, | ||
'create' if kwargs['created'] else 'update', | ||
kwargs['instance']) | ||
|
||
|
||
@receiver(post_delete) | ||
def log_base_delete(sender, **kwargs): | ||
try: | ||
name = { | ||
'Flag': 'flag', | ||
'Folder': 'folder', | ||
'FriendGroup': 'group', | ||
'Submission': 'submission', | ||
'PublisherPage': 'publisher', | ||
}[sender.__name__] | ||
except: | ||
return | ||
Activity.create(name, 'delete', kwargs['instance']) | ||
|
||
|
||
@receiver(post_save, sender=TaggedItem) | ||
def log_tagged_item(sender, **kwargs): | ||
Activity.create( | ||
'tag', | ||
'tag' if kwargs['created'] else 'update', | ||
kwargs['instance']) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an ActivityAggregateDay that boils down a day of activity of a certain type for a certain object; add a command that generates these once a day from activities so that graphs can query in a more lightweight fashion; activity rotate will leave these so we have graphable data going back forever
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue #29