Skip to content
Browse files

Fixed up user starred show set saves

  • Loading branch information...
1 parent f5f2162 commit ccde0c066b8e932957a85ce4688d37219a4500e0 @hensom committed Jun 3, 2011
Showing with 17 additions and 6 deletions.
  1. +9 −0 fancyashow/db/models.py
  2. +7 −5 fancyashow/ui/fancy_api/resources.py
  3. +1 −1 fancyashow/ui/fancy_main/views.py
View
9 fancyashow/db/models.py
@@ -465,6 +465,15 @@ def add_shows(self, shows):
if s.id not in id_map:
id_map[s.id] = True
self.show_ids.append(s.id)
+
+ def remove_shows(self, shows):
+ id_map = dict((show_id, True) for show_id in self.show_ids)
+
+ for s in shows:
+ if s.id in id_map:
+ del id_map[s.id]
+
+ self.show_ids = id_map.keys()
class Festival(Document, AuditMixin):
merge_key = StringField()
View
12 fancyashow/ui/fancy_api/resources.py
@@ -98,15 +98,17 @@ def post_saved_shows(self, request, **kwargs):
add, remove = form.cleaned_data['add'], form.cleaned_data['remove']
LOG.debug('Request by user: %s to add: %s, remove: %s' % (user, add, remove))
+
+ show_set = user.starred_show_set
- if add and add.id not in user.saved_shows:
- user.saved_shows.append(add.id)
+ if add and add.id:
+ show_set.add_shows([add])
- if remove and remove.id in user.saved_shows:
- user.saved_shows.remove(remove.id)
+ if remove and remove.id:
+ show_set.remove_shows([remove])
if add or remove:
- user.save()
+ show_set.save()
else:
desired_format = self.determine_format(request)
serialized = self.serialize(request, form.errors, desired_format)
View
2 fancyashow/ui/fancy_main/views.py
@@ -259,7 +259,7 @@ def festivals(request):
saved_shows = { }
if request.user.is_authenticated():
- saved_shows = user.starred_show_set.get_id_dict()
+ saved_shows = request.user.starred_show_set.get_id_dict()
context = {
'festivals': festivals,

0 comments on commit ccde0c0

Please sign in to comment.
Something went wrong with that request. Please try again.