From 0d4aba4b4b3a9824fc41793cd27ce5ad51337ecc Mon Sep 17 00:00:00 2001 From: Sanjay B Date: Thu, 19 Sep 2013 06:16:16 +0530 Subject: [PATCH] add notes --- itf/app/models.py | 10 +++++++++- itf/events/models.py | 13 ++++++++++++- itf/itfprofiles/models.py | 13 ++++++++++++- itf/itfprofiles/views.py | 14 ++++++++++++++ .../modules/itfprofiles/theatregroup.html | 2 +- itf/urls.py | 1 + 6 files changed, 49 insertions(+), 4 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index 5961b2b..5c3b38c 100755 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -78,7 +78,14 @@ class ItfModel(models.Model): else: return False - + + def add_note(self, user, text): + if self.user_has_perms(user): + n = Note(user=user, text=text, content_object=self) + n.save() + return True + else: + return False #Should return the id for the object and the title to display in the left hand list def list_dict(self): @@ -106,6 +113,7 @@ class ItfModel(models.Model): # d['add_form'] = self.__class__.get_add_form() d['forms'] = self.__class__.get_forms() d['obj'] = self + d['content_type'] = ContentType.objects.filter(model=self.__class__._meta.module_name)[0] try: edit_url = self.get_edit_url() d['edit_url'] = edit_url diff --git a/itf/events/models.py b/itf/events/models.py index 94c7e4a..f316f95 100644 --- a/itf/events/models.py +++ b/itf/events/models.py @@ -6,7 +6,7 @@ from django.contrib.localflavor.in_.forms import INZipCodeField #from ox.django.fields import DictField from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic -from itfprofiles.models import City, Location, Production, TheatreGroup, Person, BuzzItem +from itfprofiles.models import City, Location, Production, TheatreGroup, Person, BuzzItem, Note from mediagallery.models import GalleryAlbum @@ -42,6 +42,7 @@ class Event(ItfModel): production = models.ForeignKey(Production, blank=True, null=True, help_text="If this is a showing of a production...") buzzitems = generic.GenericRelation(BuzzItem) galleries = generic.GenericRelation(GalleryAlbum) + notes = generic.GenericRelation(Note) people = models.ManyToManyField(Person, blank=True, null=True, through="PersonEvent") image = models.ImageField(upload_to='images/', blank=True, null=True) groups = models.ManyToManyField(TheatreGroup, blank=True, null=True, through="GroupEvent") @@ -49,6 +50,16 @@ class Event(ItfModel): #Entities and Connections - # connections = generic.GenericRelation("Connection") + def user_has_perms(self, user): + if ItfModel.user_has_perms(self, user): + return True + for pe in self.personevent_set.filter(typ='organiser'): + if pe.person == user: + return True + for ge in self.groupevent_set.filter(typ='venue'): + if ge.user_has_perms(user): + return True + return False def __unicode__(self): return "%s" % (self.title,) diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index 67d1c58..3f4fde2 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -195,6 +195,16 @@ class BuzzItem(ItfModel): def __unicode__(self): return self.title + +class Note(ItfModel): + user = models.ForeignKey(User) + text = models.TextField() + content_type = models.ForeignKey(ContentType) + object_id = models.PositiveIntegerField() + content_object = generic.GenericForeignKey('content_type', 'object_id') + + def __unicode__(self): + return self.text STATE_CHOICES= ( @@ -322,7 +332,7 @@ class TheatreGroup(ItfModel): awards = generic.GenericRelation("Award") buzzitems = generic.GenericRelation("BuzzItem") galleries = generic.GenericRelation(GalleryAlbum) - + notes = generic.GenericRelation("Note") website = models.URLField(blank=True, verify_exists=False) resources = generic.GenericRelation("Resource") locations = generic.GenericRelation("Location") @@ -427,6 +437,7 @@ class Production(ItfModel): awards = generic.GenericRelation("Award") debut_date = models.DateField(blank=True, null=True) reviews= generic.GenericRelation("BuzzItem") + notes = generic.GenericRelation("Note") galleries = generic.GenericRelation(GalleryAlbum) #FIXME: add no of shows diff --git a/itf/itfprofiles/views.py b/itf/itfprofiles/views.py index 85bc66c..018eea0 100644 --- a/itf/itfprofiles/views.py +++ b/itf/itfprofiles/views.py @@ -164,6 +164,8 @@ def contact_person(request): def contact_group(request): + if not request.user.is_authenticated(): + return HttpResponse("You need to be logged in to send messages") frm = request.user.email to_group = request.GET.get("to", None) try: @@ -182,3 +184,15 @@ def contact_group(request): return HttpResponse("Your message has been sent, thanks.") +def add_note(request, content_type, object_id): + model_class = ContentType.objects.get(pk=content_type).model_class() + obj = model_class.objects.get(pk=object_id) + if not obj.user_has_perms(request.user): + return render_to_json_response({'error': 'You do not have permissions to add a note'}) + note = request.POST.get("note", None) + if note: + obj.add_note(request.user, note) + return render_to_json_response({'success': 'Note added'}) + else: + return render_to_json_response({'error': 'Empty note'}) + diff --git a/itf/templates/modules/itfprofiles/theatregroup.html b/itf/templates/modules/itfprofiles/theatregroup.html index 3a6f25f..430c13f 100644 --- a/itf/templates/modules/itfprofiles/theatregroup.html +++ b/itf/templates/modules/itfprofiles/theatregroup.html @@ -302,7 +302,7 @@ {% endif %}
-

Kindly refer to notes tab in Script Archive

+ {% include 'includes/notes.html' %}
diff --git a/itf/urls.py b/itf/urls.py index f2c45e1..a54a612 100755 --- a/itf/urls.py +++ b/itf/urls.py @@ -63,6 +63,7 @@ urlpatterns = patterns('', (r'^invitation/accept/(?P\w+)/','itfprofiles.views.invitation_accept'), #(r'^invitation/add/$', 'itfprofiles.views.friend_add'), (r'^invitation/invite/$', 'itfprofiles.views.friend_invite'), + (r'^add_note/(?P[0-9]*?)/(?P[0-9]*?)$', 'itfprofiles.views.add_note'), (r'^contact/person/$', 'itfprofiles.views.contact_person'), (r'^contact/group/$', 'itfprofiles.views.contact_group'), (r'^contact/event/$', 'events.views.contact_person'),