Permalink
Browse files

Add simple activity log object. #636. #637.

  • Loading branch information...
1 parent caa111b commit 69b54cd4cfd480ec91e5fd7c59875b2702f2f138 @onyxfish onyxfish committed Apr 18, 2012
@@ -1,5 +1,6 @@
#!/usr/bin/env python
+from panda.api.activity_log import ActivityLogResource
from panda.api.category import CategoryResource
from panda.api.data import DataResource
from panda.api.datasets import DatasetResource
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+
+from tastypie import fields
+from tastypie.authorization import DjangoAuthorization
+
+from panda.api.utils import PandaApiKeyAuthentication, PandaModelResource, PandaSerializer
+from panda.models import ActivityLog
+
+class ActivityLogResource(PandaModelResource):
+ """
+ API resource for DataUploads.
+ """
+ from panda.api.users import UserResource
+
+ creator = fields.ForeignKey(UserResource, 'user', full=True)
+
+ class Meta:
+ queryset = ActivityLog.objects.all()
+ resource_name = 'activity_log'
+ allowed_methods = ['get', 'post']
+
+ authentication = PandaApiKeyAuthentication()
+ authorization = DjangoAuthorization()
+ serializer = PandaSerializer()
+
@@ -0,0 +1,159 @@
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'ActivityLog'
+ db.create_table('panda_activitylog', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
+ ('when', self.gf('django.db.models.fields.DateTimeField')()),
+ ))
+ db.send_create_signal('panda', ['ActivityLog'])
+
+ def backwards(self, orm):
+ # Deleting model 'ActivityLog'
+ db.delete_table('panda_activitylog')
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'panda.activitylog': {
+ 'Meta': {'object_name': 'ActivityLog'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
+ 'when': ('django.db.models.fields.DateTimeField', [], {})
+ },
+ 'panda.category': {
+ 'Meta': {'object_name': 'Category'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '256'})
+ },
+ 'panda.dataset': {
+ 'Meta': {'ordering': "['-creation_date']", 'object_name': 'Dataset'},
+ 'categories': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'datasets'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['panda.Category']"}),
+ 'column_schema': ('panda.fields.JSONField', [], {'default': 'None', 'null': 'True'}),
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'creator': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'datasets'", 'to': "orm['auth.User']"}),
+ 'current_task': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['panda.TaskStatus']", 'null': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'initial_upload': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'initial_upload_for'", 'null': 'True', 'to': "orm['panda.DataUpload']"}),
+ 'last_modification': ('django.db.models.fields.TextField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
+ 'last_modified': ('django.db.models.fields.DateTimeField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
+ 'last_modified_by': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
+ 'locked': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'locked_at': ('django.db.models.fields.DateTimeField', [], {'default': 'None', 'null': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+ 'row_count': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'sample_data': ('panda.fields.JSONField', [], {'default': 'None', 'null': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '256'})
+ },
+ 'panda.dataupload': {
+ 'Meta': {'ordering': "['creation_date']", 'object_name': 'DataUpload'},
+ 'columns': ('panda.fields.JSONField', [], {'null': 'True'}),
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {}),
+ 'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
+ 'data_type': ('django.db.models.fields.CharField', [], {'max_length': '4', 'null': 'True', 'blank': 'True'}),
+ 'dataset': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'data_uploads'", 'null': 'True', 'to': "orm['panda.Dataset']"}),
+ 'dialect': ('panda.fields.JSONField', [], {'null': 'True'}),
+ 'encoding': ('django.db.models.fields.CharField', [], {'default': "'utf-8'", 'max_length': '32'}),
+ 'filename': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+ 'guessed_types': ('panda.fields.JSONField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'imported': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'original_filename': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+ 'sample_data': ('panda.fields.JSONField', [], {'null': 'True'}),
+ 'size': ('django.db.models.fields.IntegerField', [], {})
+ },
+ 'panda.export': {
+ 'Meta': {'ordering': "['creation_date']", 'object_name': 'Export'},
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {}),
+ 'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
+ 'dataset': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'exports'", 'to': "orm['panda.Dataset']"}),
+ 'filename': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'original_filename': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+ 'size': ('django.db.models.fields.IntegerField', [], {})
+ },
+ 'panda.notification': {
+ 'Meta': {'ordering': "['-sent_at']", 'object_name': 'Notification'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'message': ('django.db.models.fields.TextField', [], {}),
+ 'read_at': ('django.db.models.fields.DateTimeField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
+ 'recipient': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'notifications'", 'to': "orm['auth.User']"}),
+ 'related_dataset': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['panda.Dataset']", 'null': 'True'}),
+ 'related_task': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['panda.TaskStatus']", 'null': 'True'}),
+ 'sent_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+ 'type': ('django.db.models.fields.CharField', [], {'default': "'Info'", 'max_length': '16'})
+ },
+ 'panda.relatedupload': {
+ 'Meta': {'ordering': "['creation_date']", 'object_name': 'RelatedUpload'},
+ 'creation_date': ('django.db.models.fields.DateTimeField', [], {}),
+ 'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
+ 'dataset': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'related_uploads'", 'to': "orm['panda.Dataset']"}),
+ 'filename': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'original_filename': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
+ 'size': ('django.db.models.fields.IntegerField', [], {})
+ },
+ 'panda.taskstatus': {
+ 'Meta': {'object_name': 'TaskStatus'},
+ 'creator': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'tasks'", 'null': 'True', 'to': "orm['auth.User']"}),
+ 'end': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'message': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+ 'start': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
+ 'status': ('django.db.models.fields.CharField', [], {'default': "'PENDING'", 'max_length': '50'}),
+ 'task_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'traceback': ('django.db.models.fields.TextField', [], {'default': 'None', 'null': 'True', 'blank': 'True'})
+ },
+ 'panda.userprofile': {
+ 'Meta': {'object_name': 'UserProfile'},
+ 'activation_key': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
+ }
+ }
+
+ complete_apps = ['panda']
@@ -10,6 +10,7 @@
from tastypie.models import ApiKey
from panda import config # Needed for autodiscovery
+from panda.models.activity_log import ActivityLog
from panda.models.category import Category
from panda.models.dataset import Dataset
from panda.models.data_upload import DataUpload
@@ -20,7 +21,7 @@
from panda.models.user_profile import UserProfile
from panda.utils.mail import send_mail
-__all__ = ['Category', 'Dataset', 'DataUpload', 'Export', 'Notification', 'RelatedUpload', 'TaskStatus', 'UserProfile']
+__all__ = ['ActivityLog', 'Category', 'Dataset', 'DataUpload', 'Export', 'Notification', 'RelatedUpload', 'TaskStatus', 'UserProfile']
@receiver(models.signals.post_save, sender=User)
def on_user_post_save(sender, instance, created, **kwargs):
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+from django.contrib.auth.models import User
+from django.db import models
+from django.utils.timezone import now
+
+ACTIVITY_CHOICES = [
+ ('ON_SITE', 'ON_SITE'),
+]
+
+class ActivityLog(models.Model):
+ """
+ A log of some activity taken by a user.
+ """
+ user = models.ForeignKey(User,
+ help_text='The user who was active.')
+ activity = models.CharField(max_length=64, default='ON_SITE', choices=ACTIVITY_CHOICES,
+ help_text='The activity being recorded'),
+ when = models.DateTimeField(
+ help_text='The date and time this activity was recorded.')
+
+ class Meta:
+ app_label = 'panda'
+ verbose_name_plural = 'ActivityLogs'
+
+ def __unicode__(self):
+ return '%s was %s at %s' % (self.user, self.activity, self.when)
+
+ def save(self, *args, **kwargs):
+ if not self.when:
+ self.when = now()
+
+ super(ActivityLog, self).save(*args, **kwargs)
+
View
@@ -4,10 +4,11 @@
from tastypie.api import Api
from tastypie.utils.urls import trailing_slash
-from panda.api import CategoryResource, DatasetResource, DataUploadResource, ExportResource, NotificationResource, RelatedUploadResource, TaskResource, UserResource
+from panda.api import ActivityLogResource, CategoryResource, DatasetResource, DataUploadResource, ExportResource, NotificationResource, RelatedUploadResource, TaskResource, UserResource
from panda import views
api_1_0 = Api(api_name='1.0')
+api_1_0.register(ActivityLogResource())
api_1_0.register(CategoryResource())
api_1_0.register(DatasetResource())
api_1_0.register(DataUploadResource())

0 comments on commit 69b54cd

Please sign in to comment.