def handle_POST(self, request, context): """ Add and remove favourites. Favourites are stored as URLs (the part of them Django is interested in anyway) in the database. This has the downside of breaking favourites if URLs change. """ # Alter favourites list if 'URL' in request.POST: if 'favourite' in request.POST: # Add try: resolve(request.POST['URL']) except Http404: # This means that they tried to save a URL that doesn't exist # or isn't on our site return HttpResponseRedirect(lazy_reverse('favourites:index')) else: Favourite(user=request.user, url=request.POST['URL']).save() elif 'unfavourite' in request.POST: Favourite.objects.filter(user=request.user, url=request.POST['URL']).delete() # If the source was the favourites page, redirect back there if 'return_to_favourites' in request.POST: return self.handle_GET(request, context) # else the source else: return HttpResponseRedirect(request.POST['URL']) else: # Missing POST data, probably a bad request return HttpResponseRedirect(lazy_reverse('favourites:index'))
def handle_POST(self, request, context): """ Add and remove favourites. Favourites are stored as URLs (the part of them Django is interested in anyway) in the database, if the user is logged in - otherwise, it is stored in the session, and then migrated to the database when the user logs in. This has the downside of breaking favourites if URLs change. """ # Alter favourites list if "URL" in request.POST: print request.POST if "favourite" in request.POST: # Add try: resolve(request.POST["URL"]) except Http404: # This means that they tried to save a URL that doesn't exist # or isn't on our site logger.debug("Attempted to favourite a non-existant URL") return self.redirect(lazy_reverse("favourites:index"), request) else: if request.user.is_anonymous(): logger.debug("User is anonymous, storing favourites in session") if "favourites" not in request.session: request.session["favourites"] = set() request.session["favourites"].add(request.POST["URL"]) request.session.modified = True else: logger.debug("User is logged in, storing favourites in database") Favourite(user=request.user, url=request.POST["URL"]).save() elif "unfavourite" in request.POST: if not request.user.is_anonymous(): try: favourite = Favourite.objects.get(user=request.user, url=request.POST["URL"]) except Favourite.DoesNotExist: pass else: favourite.delete() else: if request.POST["URL"] in request.session.get("favourites", set()): request.session["favourites"].remove(request.POST["URL"]) request.session.modified = True # If the source was the favourites page, redirect back there if "return_to_favourites" in request.POST: return self.redirect(lazy_reverse("favourites:index"), request) # else the source else: return self.redirect(request.POST["URL"], request) else: # Missing POST data, probably a bad request return self.redirect(lazy_reverse("favourites:index"), request)
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, lazy_parent('index'), _('Surveys'), lazy_reverse('evaluation-index'), )
def breadcrumb(self, request, context, id): return Breadcrumb( self.conf.local_name, lazy_parent('poll-index'), context['poll']['text'], lazy_reverse('poll-detail'), )
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, lazy_parent('index'), 'Polls', lazy_reverse('poll-index'), )
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, lazy_parent('index'), _('User information'), lazy_reverse('direct-index'), )
def breadcrumb(self, request, context, site, event_id): return Breadcrumb( self.conf.local_name, lazy_parent('signup-site', site), context['event']['title'] if 'event' in context else 'Sign-ups', lazy_reverse('signup-detail', args=[site, event_id]), )
def breadcrumb(self, request, context, site): return Breadcrumb( self.conf.local_name, lazy_parent('signup-index'), context.get('title', 'Sign-ups'), lazy_reverse('signup-site', args=[site]), )
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, lazy_parent('index'), _('Sign-ups'), lazy_reverse('signup-index'), )
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, static_parent(context['return_url'], 'Back'), _('Clear session'), lazy_reverse('auth:clear-session'), )
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, None, _('Popular Devices'), lazy_reverse('popular-devices'), )
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, None, _('Slow Pages'), lazy_reverse('slow-pages'), )
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, None, _('Stats'), lazy_reverse('index'), )
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, None, 'Popular Devices', lazy_reverse('popular-devices'), )
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, None, 'Favourites', lazy_reverse('index'), )
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, None, _('Authentication preferences'), lazy_reverse('auth:index'), )
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, None, _('Popular 404s'), lazy_reverse('popular-404s'), )
def breadcrumb(self, request, context): # TODO Remove 'WebLearn' as the standard name for Sakai return Breadcrumb( self.conf.local_name, None, _('WebLearn'), lazy_reverse('index'), )
def breadcrumb(self, request, context, id): if not 'announcement' in context: context = self.initial_context(request, id) return Breadcrumb( self.conf.local_name, lazy_parent('index'), context['announcement']['title'], lazy_reverse('announcement', args=[id]), )
def breadcrumb(self, request, context, id): if not 'evaluation' in context: context = self.initial_context(request, id) return Breadcrumb( self.conf.local_name, lazy_parent('evaluation-index'), context.get('title', 'Survey'), lazy_reverse('evaluation-detail', args=[id]), )
def handle_POST(self, request, context): """ Add and remove favourites. Favourites are stored as URLs (the part of them Django is interested in anyway) in the database. This has the downside of breaking favourites if URLs change. """ # Alter favourites list if 'URL' in request.POST: if 'favourites' not in request.session: request.session['favourites'] = set() if 'favourite' in request.POST: # Add try: resolve(request.POST['URL']) request.session['favourites'].add(request.POST['URL']) request.session.modified = True except Http404: # This means that they tried to save a URL that doesn't exist # or isn't on our site return HttpResponseRedirect( lazy_reverse('favourites:index')) elif 'unfavourite' in request.POST and 'favourites' in request.session: # Remove if request.POST['URL'] in request.session['favourites']: request.session['favourites'].remove(request.POST['URL']) request.session.modified = True # If the source was the favourites page, redirect back there if 'return_to_favourites' in request.POST: return self.handle_GET(request, context) # else the source else: return HttpResponseRedirect(request.POST['URL']) else: # Missing POST data, probably a bad request return HttpResponseRedirect(lazy_reverse('favourites:index'))
def handle_POST(self, request, context): """ Add and remove favourites. Favourites are stored as URLs (the part of them Django is interested in anyway) in the database. This has the downside of breaking favourites if URLs change. """ # Alter favourites list if "URL" in request.POST: if "favourites" not in request.session: request.session["favourites"] = set() if "favourite" in request.POST: # Add try: resolve(request.POST["URL"]) request.session["favourites"].add(request.POST["URL"]) request.session.modified = True except Http404: # This means that they tried to save a URL that doesn't exist # or isn't on our site return HttpResponseRedirect(lazy_reverse("favourites:index")) elif "unfavourite" in request.POST and "favourites" in request.session: # Remove if request.POST["URL"] in request.session["favourites"]: request.session["favourites"].remove(request.POST["URL"]) request.session.modified = True # If the source was the favourites page, redirect back there if "return_to_favourites" in request.POST: return self.handle_GET(request, context) # else the source else: return HttpResponseRedirect(request.POST["URL"]) else: # Missing POST data, probably a bad request return HttpResponseRedirect(lazy_reverse("favourites:index"))
def breadcrumb(cls, request, context): return Breadcrumb( cls.conf.local_name, None, 'Feedback', lazy_reverse('index'))
def breadcrumb(cls, request, context): return Breadcrumb(cls.conf.local_name, None, "Feedback", lazy_reverse("index"))
def handle_POST(self, request, context): """ Add and remove favourites. Favourites are stored as URLs (the part of them Django is interested in anyway) in the database, if the user is logged in - otherwise, it is stored in the session, and then migrated to the database when the user logs in. This has the downside of breaking favourites if URLs change. """ # Alter favourites list if 'URL' in request.POST: if 'favourite' in request.POST: # Add try: resolve(request.POST['URL']) except Http404: # This means that they tried to save a URL that doesn't exist # or isn't on our site logger.debug('Attempted to favourite a non-existant URL') return self.redirect(lazy_reverse('favourites:index'), request) else: if request.user.is_anonymous(): logger.debug( 'User is anonymous, storing favourites in session') if 'favourites' not in request.session: request.session['favourites'] = set() request.session['favourites'].add(request.POST['URL']) request.session.modified = True else: logger.debug( 'User is logged in, storing favourites in database' ) Favourite(user=request.user, url=request.POST['URL']).save() elif 'unfavourite' in request.POST: if not request.user.is_anonymous(): try: favourite = Favourite.objects.get( user=request.user, url=request.POST['URL']) except Favourite.DoesNotExist: pass else: favourite.delete() else: if request.POST['URL'] in request.session.get( 'favourites', set()): request.session['favourites'].remove( request.POST['URL']) request.session.modified = True # If the source was the favourites page, redirect back there if 'return_to_favourites' in request.POST: return self.redirect(reverse('favourites:index'), request) # else the source else: return self.redirect(request.POST['URL'], request) else: # Missing POST data, probably a bad request return self.redirect(reverse('favourites:index'), request)
def breadcrumb(self, request, context): return Breadcrumb( self.conf.local_name, None, 'Feedback', lazy_reverse('index'))
def breadcrumb(self, request, context): return Breadcrumb(self.conf.local_name, None, "Stats", lazy_reverse("index"))
def breadcrumb(self, request, context): return Breadcrumb(self.conf.local_name, None, "Slow Pages", lazy_reverse("slow-pages"))
def breadcrumb(self, request, context): return Breadcrumb(self.conf.local_name, None, _("Favourites"), lazy_reverse("index"))
def breadcrumb(self, request, context): return Breadcrumb(self.conf.local_name, None, "Popular Devices", lazy_reverse("popular-devices"))