Skip to content

Commit

Permalink
Put user member on Event object. Fixes #43.
Browse files Browse the repository at this point in the history
Also ensured that all events are being created properly, except
for those mentioned in #48 and #49.
  • Loading branch information
Colin Sullivan committed Apr 11, 2011
1 parent 5ba6104 commit 61c00fe
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 69 deletions.
2 changes: 1 addition & 1 deletion concertapp/audiosegments/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def create_nested_event(self, obj, nested_obj, request):
collection = obj.collection,
audio_segment = obj,
tag = nested_obj,
tagging_user = request.user
user = request.user
)
return

Expand Down
156 changes: 89 additions & 67 deletions concertapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.core.files import File
from django.core.files.base import ContentFile
from django.core.files.storage import FileSystemStorage
Expand Down Expand Up @@ -52,6 +53,8 @@ def concert_post_save_receiver(sender, **kwargs):
# theoretically work using django signals.
###
class Event(models.Model):
# Every event has a user associated with it, so lets just store it here
user = models.ForeignKey(User)
time = models.DateTimeField(auto_now_add = True)
collection = models.ForeignKey('Collection')
active = models.BooleanField(default=True)
Expand Down Expand Up @@ -85,101 +88,107 @@ def __unicode__(self):
return str(self.cast())


class TagCommentEvent(Event):
tag_comment = models.ForeignKey("TagComment", related_name = 'comment_event')

def __unicode__(self):
author = self.tag_comment.author
tag = self.tag_comment.tag.name

return str(author) + " commented on tag '" + str(tag) + "'."


class SegmentCommentEvent(Event):
segment_comment = models.ForeignKey("SegmentComment", related_name = "comment_event" )
###
# When a user comments on a tag.
###
#class TagCommentEvent(Event):
# tag_comment = models.ForeignKey("TagComment", related_name = 'comment_event')

# def __unicode__(self):
# author = self.user
# tag = self.tag_comment.tag.name

def __unicode__(self):
author = self.segment_comment.author
segment = self.segment_comment.segment.name
# return str(author) + " commented on tag '" + str(tag) + "'."

return str(author) + " commented on segment '" + str(segment) + "'."

###
# When a user comments on a segment
###
#class SegmentCommentEvent(Event):
# segment_comment = models.ForeignKey("SegmentComment", related_name = "comment_event" )

class TagCreatedEvent(Event):
tag = models.ForeignKey("Tag", related_name = "created_event")

def __unicode__(self):
creator = self.tag.creator
tag = self.tag.name

return str(creator) + " created tag '" + str(tag) + "'."
# def __unicode__(self):
# author = self.segment_comment.author
# segment = self.segment_comment.segment.name

# return str(author) + " commented on segment '" + str(segment) + "'."

###
# When an audio segment is created.
###
class AudioSegmentCreatedEvent(Event):
# The audio segment that was created.
audio_segment = models.ForeignKey("AudioSegment", related_name = "created_event")

def __unicode__(self):
creator = self.audio_segment.creator
creator = self.user
audio_segment = self.audio_segment.name

return str(creator) + " created segment '" + str(audio_segment) + "'."


###
# When an audio segment has been tagged.
###
class AudioSegmentTaggedEvent(Event):
# The audio segment that was tagged
audio_segment = models.ForeignKey("AudioSegment", related_name = "tagged_event")
# The tag
tag = models.ForeignKey("Tag", related_name = "tagged_event")
tagging_user = models.ForeignKey(User, related_name = "tagged_event")

def __unicode__(self):
return str(self.tagging_user) + " tagged '" + str(self.audio_segment.name) + "' with tag '" + self.tag.name + "'."

return str(self.user) + " tagged '" + str(self.audio_segment.name) + "' with tag '" + self.tag.name + "'."

###
# When an audio file was uploaded
###
class AudioFileUploadedEvent(Event):
# The audio file that was uploaded
audioFile = models.ForeignKey("AudioFile", related_name = "audio_uploaded_event")

def __unicode__(self):
return str(self.audioFile.uploader) + " uploaded file '" + self.audioFile.name + "'."


###
# When a user joins a collection
###
class JoinCollectionEvent(Event):
new_user = models.ForeignKey(User)

def __unicode__(self):
return str(self.new_user) + " joined " + str(self.collection)
return str(self.user) + " joined " + str(self.collection)

###
# When a user leaves a collection
###
class LeaveCollectionEvent(Event):
old_user = models.ForeignKey(User)

def __unicode__(self):
return str(self.new_user) + " left " + str(self.collection)
return str(self.user) + " left " + str(self.collection)

###
# An event that is created when a collection is created.
# When a collection is created.
###
class CreateCollectionEvent(Event):
admin = models.ForeignKey(User)

def __unicode__(self):
return str(self.admin) + " created " + str(self.collection)
return str(self.user) + " created " + str(self.collection)


###
# When a user requests to join a collection
###
class RequestJoinCollectionEvent(Event):
requesting_user = models.ForeignKey(User)

def __unicode__(self):
return str(self.requesting_user) + " requested to join " + str(self.collection)

class RequestDeniedEvent(Event):
requesting_user = models.ForeignKey(User)
return str(self.user) + " requested to join " + str(self.collection)

###
# When a user gets denied from a collection.
###
class RequestDeniedEvent(Event):
def __unicode__(self):
return str(self.requesting_user) + " was denied from " + str(self.collection)
return str(self.user) + " was denied from " + str(self.collection)

###
# When a user revokes her/his request to join a collection
###
class RequestRevokedEvent(Event):
requesting_user = models.ForeignKey(User)

def __unicode__(self):
return str(self.requesting_user) + " revoked join request from " + str(self.collection)
return str(self.user) + " revoked join request from " + str(self.collection)


class AudioSegment(models.Model):
Expand All @@ -200,23 +209,36 @@ def save(self, *args, **kwargs):
self.full_clean()

new = False
if not self.id or not AudioSegment.objects.filter(pk=self.id):
if not self.id:
new = True

super(AudioSegment, self).save(*args, **kwargs)

if new:
event = AudioSegmentCreatedEvent(audio_segment = self, collection = self.collection)
event.save()

AudioSegmentCreatedEvent.objects.create(
user = self.creator,
audio_segment = self,
collection = self.collection
)

# Make sure it has a unique name (relative to the other segments
# in the collection)
def clean(self):
# if the audio segment is new, make sure it has a unique name (relative to the other segments
# in the collection
if not AudioSegment.objects.filter(pk=self.id):
from django.core.exceptions import ValidationError
if AudioSegment.objects.filter(name = self.name, collection = self.collection):
try:
# If there is a segment in this collection with the same name
sameName = AudioSegment.objects.get(
name = self.name,
collection = self.collection
)
# And it is not the current segment
if sameName.id is not self.id:
raise ValidationError('Audio Segments must have unique names!')

except ObjectDoesNotExist:
# There is no segment with the same name in this collection. We're
# golden.
pass


def tag_list(self):
tags = self.tag_set.all()
Expand Down Expand Up @@ -258,7 +280,7 @@ def save(self, *args, **kwargs):
self.users.add(self.admin)

# Create event
CreateCollectionEvent.objects.create(admin=self.admin, collection=self)
CreateCollectionEvent.objects.create(user=self.admin, collection=self)
else:
super(Collection, self).save(*args, **kwargs)

Expand Down Expand Up @@ -294,7 +316,7 @@ def save(self, *args, **kwargs):
super(Request, self).save(*args, **kwargs)
# Create event
RequestJoinCollectionEvent.objects.create(
requesting_user=user,
user=user,
collection=collection
)
else:
Expand All @@ -314,7 +336,7 @@ def accept(self):
collection.users.add(user)

# Create event
event = JoinCollectionEvent(new_user = user, collection = collection)
event = JoinCollectionEvent(user = user, collection = collection)
event.save()

self.delete()
Expand All @@ -324,7 +346,7 @@ def accept(self):
###
def deny(self):
# Create proper event
event = RequestDeniedEvent(requesting_user = self.user, collection = self.collection)
event = RequestDeniedEvent(user = self.user, collection = self.collection)
event.save()

self.delete()
Expand All @@ -333,7 +355,7 @@ def deny(self):
# When request is revoked
###
def revoke(self):
event = RequestRevokedEvent(requesting_user = self.user, collection = self.collection)
event = RequestRevokedEvent(user = self.user, collection = self.collection)
event.save()

self.delete()
Expand Down Expand Up @@ -549,7 +571,7 @@ def save(self, f = None, *args, **kwargs):

super(AudioFile, self).save(*args, **kwargs)

event = AudioFileUploadedEvent(audioFile = self, collection = self.collection)
event = AudioFileUploadedEvent(user = self.uploader, audioFile = self, collection = self.collection)
event.save()


Expand Down
2 changes: 1 addition & 1 deletion concertapp/tags/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def create_nested_event(self, obj, nested_obj, request):
collection = obj.collection,
audio_segment = nested_obj,
tag = obj,
tagging_user = request.user
user = request.user
)
return

Expand Down

0 comments on commit 61c00fe

Please sign in to comment.