Example #1
0
 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'))
Example #2
0
    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)
Example #3
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         lazy_parent('index'),
         _('Surveys'),
         lazy_reverse('evaluation-index'),
     )
Example #4
0
 def breadcrumb(self, request, context, id):
     return Breadcrumb(
         self.conf.local_name,
         lazy_parent('poll-index'),
         context['poll']['text'],
         lazy_reverse('poll-detail'),
     )
Example #5
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         lazy_parent('index'),
         'Polls',
         lazy_reverse('poll-index'),
     )
Example #6
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         lazy_parent('index'),
         _('User information'),
         lazy_reverse('direct-index'),
     )
Example #7
0
 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]),
     )
Example #8
0
 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]),
     )
Example #9
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         lazy_parent('index'),
         _('Sign-ups'),
         lazy_reverse('signup-index'),
     )
Example #10
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         static_parent(context['return_url'], 'Back'),
         _('Clear session'),
         lazy_reverse('auth:clear-session'),
     )
Example #11
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         None,
         _('Popular Devices'),
         lazy_reverse('popular-devices'),
     )
Example #12
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         None,
         _('Slow Pages'),
         lazy_reverse('slow-pages'),
     )
Example #13
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         None,
         _('Stats'),
         lazy_reverse('index'),
     )
Example #14
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         None,
         'Popular Devices',
         lazy_reverse('popular-devices'),
     )
Example #15
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         None,
         _('Stats'),
         lazy_reverse('index'),
     )
Example #16
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         None,
         _('Slow Pages'),
         lazy_reverse('slow-pages'),
     )
Example #17
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         None,
         'Favourites',
         lazy_reverse('index'),
     )
Example #18
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         None,
         _('Authentication preferences'),
         lazy_reverse('auth:index'),
     )
Example #19
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         lazy_parent('index'),
         'Polls',
         lazy_reverse('poll-index'),
     )
Example #20
0
 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]),
     )
Example #21
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         lazy_parent('index'),
         _('Surveys'),
         lazy_reverse('evaluation-index'),
     )
Example #22
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         None,
         _('Popular 404s'),
         lazy_reverse('popular-404s'),
     )
Example #23
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         None,
         _('Authentication preferences'),
         lazy_reverse('auth:index'),
     )
Example #24
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         lazy_parent('index'),
         _('User information'),
         lazy_reverse('direct-index'),
     )
Example #25
0
 def breadcrumb(self, request, context, id):
     return Breadcrumb(
         self.conf.local_name,
         lazy_parent('poll-index'),
         context['poll']['text'],
         lazy_reverse('poll-detail'),
     )
Example #26
0
 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]),
     )
Example #27
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         None,
         'Favourites',
         lazy_reverse('index'),
     )
Example #28
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         lazy_parent('index'),
         _('Sign-ups'),
         lazy_reverse('signup-index'),
     )
Example #29
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name,
         static_parent(context['return_url'], 'Back'),
         _('Clear session'),
         lazy_reverse('auth:clear-session'),
         
     )
Example #30
0
 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'),
     )
Example #31
0
 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'),
     )
Example #32
0
    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]),
        )
Example #33
0
    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]),
        )
Example #34
0
    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]),
        )
Example #35
0
    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]),
        )
Example #36
0
    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'))
Example #37
0
    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"))
Example #38
0
 def breadcrumb(cls, request, context):
     return Breadcrumb(
         cls.conf.local_name, None, 'Feedback',
         lazy_reverse('index'))
Example #39
0
 def breadcrumb(cls, request, context):
     return Breadcrumb(cls.conf.local_name, None, "Feedback", lazy_reverse("index"))
Example #40
0
    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)
Example #41
0
 def breadcrumb(self, request, context):
     return Breadcrumb(
         self.conf.local_name, None, 'Feedback',
         lazy_reverse('index'))
Example #42
0
 def breadcrumb(self, request, context):
     return Breadcrumb(self.conf.local_name, None, "Stats", lazy_reverse("index"))
Example #43
0
 def breadcrumb(self, request, context):
     return Breadcrumb(self.conf.local_name, None, "Slow Pages", lazy_reverse("slow-pages"))
Example #44
0
 def breadcrumb(self, request, context):
     return Breadcrumb(self.conf.local_name, None, _("Favourites"), lazy_reverse("index"))
Example #45
0
 def breadcrumb(self, request, context):
     return Breadcrumb(self.conf.local_name, None, "Popular Devices", lazy_reverse("popular-devices"))