Beispiel #1
0
def endpoint(request):
    openid_request = get_server().decodeRequest(dict(request.REQUEST.items()))
    if openid_request is None:
        return HttpResponse("This was not valid OpenID request")

    if openid_request.mode not in ("checkid_immediate", "checkid_setup"):
        return convertToHttpResponse(
            get_server().handleRequest(openid_request))

    djangoid = get_djangoid_user_from_identity()
    if not request.user.is_authenticated():
        if openid_request.claimed_id is None:
            openid_request.claimed_id = openid_request.identity
        return redirect_to_login(urllib.quote(
            openid_request.encodeToURL(request.build_absolute_uri())),
                                 login_url=reverse('login'))
    if request.user != djangoid.user:
        raise Exception("Logged in as %s while expecting %s" %
                        (request.user, djangoid.user))

    # Is the user authenticated, and does he trust this trust_root?
    # user logged in (using openid_request.identity and openid_request.trust_root)
    if djangoid.authenticate(openid_request.trust_root):
        response = openid_request.answer(True)
    elif openid_request.immediate:
        response = openid_request.answer(False, request.META["HTTP_HOST"])
    else:
        if openid_request.claimed_id is None:
            openid_request.claimed_id = openid_request.identity
        redirect = openid_request.encodeToURL(reverse('openid_accept'))
        return HttpResponseRedirect(redirect)
    return convertToHttpResponse(response)
Beispiel #2
0
def endpoint(request):
    openid_request = get_server().decodeRequest(dict(request.REQUEST.items()))
    if openid_request is None:
        return HttpResponse("This was not valid OpenID request")

    if openid_request.mode not in ("checkid_immediate", "checkid_setup"):
        return convertToHttpResponse(get_server().handleRequest(openid_request))

    djangoid = get_djangoid_user_from_identity()
    if not request.user.is_authenticated():
        if openid_request.claimed_id is None:
            openid_request.claimed_id = openid_request.identity
        return redirect_to_login(
            urllib.quote(openid_request.encodeToURL(request.build_absolute_uri())),
            login_url=reverse('login'))
    if request.user != djangoid.user:
        raise Exception("Logged in as %s while expecting %s" % (request.user, djangoid.user))

    # Is the user authenticated, and does he trust this trust_root?
    # user logged in (using openid_request.identity and openid_request.trust_root)
    if djangoid.authenticate(openid_request.trust_root):
        response = openid_request.answer(True)
    elif openid_request.immediate:
        response = openid_request.answer(False, request.META["HTTP_HOST"])
    else:
        if openid_request.claimed_id is None:
            openid_request.claimed_id = openid_request.identity
        redirect = openid_request.encodeToURL(reverse('openid_accept'))
        return HttpResponseRedirect(redirect)
    return convertToHttpResponse(response)
Beispiel #3
0
def revcanonical(obj):
    url = reverse('revcanonical', encode(obj))
    site = getattr(settings, 'REVCANONICAL_SITE', None)
    if not site:
        site = Site.objects.get_current().domain
    return mark_safe(u'<link rev="canonical" href="http://%s%s" />' %
                     (site, url))
Beispiel #4
0
 def feed_links(self):
     return ({
         'rel': u'alternate',
         'href': self.feed_id()
     }, {
         'rel': u'self',
         'href': link(reverse(get_feed_type(type), 'blog'))
     })
Beispiel #5
0
 def feed_id(self, bits):
     try:
         tags, union = bits
     except TypeError:
         raise Http404
     if not tags:
         raise Http404
     return link(reverse('post_by_tag', tag=get_tags_bit(tags, union)))
Beispiel #6
0
 def feed_id(self, bits):
     try:
         tags, union = bits
     except TypeError:
         raise Http404
     if not tags:
         raise Http404
     return link(reverse('post_by_tag', tag=get_tags_bit(tags, union)))
Beispiel #7
0
def datelinks(value, prefix=''):
    """
    This filter formats date as "day.month.year" and sets links to
    day/month/year-based archives.

    For correct work there must be defined urls with names:
        - day_archive
        - month_archive
        - year_archive
    """
    ctx = {'year': reverse(prefix+'year_archive', year=value.year),
           'month': reverse(prefix+'month_archive', year=value.year,
                            month=value.strftime('%m')),
           'day': reverse(prefix+'day_archive', year=value.year,
                          month=value.strftime('%m'),
                          day=value.strftime('%d')),
           'date': value}
    return mark_safe(loader.render_to_string('templatetags/datelinks.html', ctx))
Beispiel #8
0
def friends_fetch_feeds(request):
    """
    Manually fetch feeds
    (if don't want to use crontab)
    """
    if not request.user.is_superuser:
        return HttpResponseForbidden("Only superuser can fetch friends feeds")
    FriendBlog.objects.fetch_feeds()
    return HttpResponseRedirect(reverse('friends_index'))
Beispiel #9
0
def life_fetch_feeds(request):
    """
    Manually fetch feeds
    (if don't want to use crontab)
    """
    if not request.user.is_superuser:
        return HttpResponseForbidden("Only superuser can fetch life feeds")
    LifeFlow.objects.fetch_feeds()
    return HttpResponseRedirect(reverse('life_index'))
Beispiel #10
0
def life_fetch_feeds(request):
    """
    Manually fetch feeds
    (if don't want to use crontab)
    """
    if not request.user.is_superuser:
        return HttpResponseForbidden("Only superuser can fetch life feeds")
    LifeFlow.objects.fetch_feeds()
    return HttpResponseRedirect(reverse('life_index'))
Beispiel #11
0
def friends_fetch_feeds(request):
    """
    Manually fetch feeds
    (if don't want to use crontab)
    """
    if not request.user.is_superuser:
        return HttpResponseForbidden("Only superuser can fetch friends feeds")
    FriendBlog.objects.fetch_feeds()
    return HttpResponseRedirect(reverse('friends_index'))
Beispiel #12
0
 def feed_links(self, author):
     return ({
         'rel': u'alternate',
         'href': self.feed_id(author)
     }, {
         'rel':
         u'self',
         'href':
         link(
             reverse(get_feed_type(type),
                     'author/%s' % author.username))
     })
Beispiel #13
0
 def feed_links(self, obj):
     return ({
         'rel': u'alternate',
         'href': self.feed_id(obj)
     }, {
         'rel':
         u'self',
         'href':
         link(
             reverse(get_feed_type(type),
                     'comments/%s' % str(getattr(obj, 'id', ''))))
     })
Beispiel #14
0
def merge(request):
    """Merges accounts and switches to a new merged account"""
    if request.POST:
        form = MergeForm(request, request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("profile_edit"))
        else:
            return {'form':form}
    else:
        form = MergeForm(request)
        return {'form':form}
Beispiel #15
0
def merge(request):
    """Merges accounts and switches to a new merged account"""
    if request.POST:
        form = MergeForm(request, request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse("profile_edit"))
        else:
            return {'form': form}
    else:
        form = MergeForm(request)
        return {'form': form}
Beispiel #16
0
def _PostsByTag(Feed, type='atom'):
    class PostsByTag(Feed):
        def get_object(self, bits):
            if len(bits) != 1:
                raise Http404
            else:
                return list_and_is_union(bits[0])

        def feed_id(self, bits):
            try:
                tags, union = bits
            except TypeError:
                raise Http404
            if not tags:
                raise Http404
            return link(reverse('post_by_tag', tag=get_tags_bit(tags, union)))

        link = feed_id

        def feed_title(self, (tags, union)):
            site = Site.objects.get_current()
            if tags:
                filter_type = union and ' union' or ' intersection'
            else:
                filter_type = ''
            return u"%s blog posts with tag%s%s %s" % (
                site.name, pluralize(len(tags)), filter_type, ', '.join(
                    [tag.name for tag in tags]))

        title = feed_title

        def feed_authors(self):
            return ({
                "name": user.name
            } for user in User.objects.filter(is_staff=True))

        def feed_links(self, (tags, union)):
            return ({
                'rel': u'alternate',
                'href': self.feed_id((tags, union))
            }, {
                'rel':
                u'self',
                'href':
                link(
                    reverse(get_feed_type(type),
                            'tag/%s' % get_tags_bit(tags, union)))
            })
Beispiel #17
0
def _PostsByTag(Feed, type='atom'):
    class PostsByTag(Feed):
        def get_object(self, bits):
            if len(bits) != 1:
                raise Http404
            else:
                return list_and_is_union(bits[0])

        def feed_id(self, bits):
            try:
                tags, union = bits
            except TypeError:
                raise Http404
            if not tags:
                raise Http404
            return link(reverse('post_by_tag', tag=get_tags_bit(tags, union)))
        link = feed_id

        def feed_title(self, (tags, union)):
            site = Site.objects.get_current()
            if tags:
                filter_type = union and ' union' or ' intersection'
            else:
                filter_type = ''
            return u"%s blog posts with tag%s%s %s" % (
                site.name,
                pluralize(len(tags)),
                filter_type,
                ', '.join([tag.name for tag in tags]))
        title = feed_title

        def feed_authors(self):
            return ({"name": user.name} for user in User.objects.filter(is_staff=True))

        def feed_links(self, (tags, union)):
            return ({'rel': u'alternate', 'href': self.feed_id((tags, union))},
                    {'rel': u'self', 'href': link(reverse(
                            get_feed_type(type),
                            'tag/%s' % get_tags_bit(tags, union)))})
Beispiel #18
0
 def get_absolute_url(self):
     return reverse('wpimport.views.post_detail', self.id)
Beispiel #19
0
 def feed_id(self, obj):
     if obj:
         return link(obj.get_absolute_url())
     else:
         return link('%s#comments' % reverse('post_list'))
def shorturl(obj):
    return reverse('revcanonical', encode(obj))
Beispiel #21
0
 def feed_id(self):
     return link(reverse('post_list'))
Beispiel #22
0
 def feed_id(self, author):
     return link(reverse('post_by_author', author=author.username))
Beispiel #23
0
 def feed_id(self):
     return link(reverse('post_list'))
Beispiel #24
0
 def feed_id(self, obj):
     if obj:
         return link(obj.get_absolute_url())
     else:
         return link('%s#comments' % reverse('post_list'))
Beispiel #25
0
def shorturl(obj):
    return reverse('revcanonical', encode(obj))
Beispiel #26
0
 def feed_id(self):
     return link(reverse('life_index'))
Beispiel #27
0
 def feed_id(self):
     return link(reverse('friends_index'))
Beispiel #28
0
def get_server():
    url = 'http://%s%s' % (Site.objects.get_current().domain,
                           reverse('openid_endpoint'))
    return server.Server(DjangoidStore(), url)
Beispiel #29
0
 def get_absolute_url(self):
     return reverse('post_by_tag', tag=self.name)
Beispiel #30
0
 def get_absolute_url(self):
     return reverse('post_detail',
                    year=self.date.year,
                    month=self.date.strftime('%m'),
                    day=self.date.strftime('%d'),
                    slug=self.slug)
Beispiel #31
0
 def feed_links(self, author):
     return ({'rel': u'alternate', 'href': self.feed_id(author)},
             {'rel': u'self', 'href': link(reverse(
                     get_feed_type(type),
                     'author/%s' % author.username))})
Beispiel #32
0
 def location(self, obj):
     return reverse(obj)
Beispiel #33
0
def unsubscribe_type_url(content_type):
    return reverse('wl_unsubscribe_type',
                   content_type='.'.join(
                       (content_type.app_label, content_type.model)))
Beispiel #34
0
 def location(self, obj):
     return reverse(obj)
Beispiel #35
0
 def feed_links(self, obj):
     return ({'rel': u'alternate', 'href': self.feed_id(obj)},
             {'rel': u'self', 'href': link(reverse(
                     get_feed_type(type),
                     'comments/%s' % str(getattr(obj, 'id', ''))))})
Beispiel #36
0
def redirect_to_feed(request, url):
    from django.views.generic.simple import redirect_to
    from lib.helpers import reverse
    return redirect_to(request, url=reverse('feed', url=url))
Beispiel #37
0
 def feed_links(self):
     return ({'rel': u'alternate', 'href': self.feed_id()},
             {'rel': u'self', 'href': link(reverse(get_feed_type(type), 'blog'))})
Beispiel #38
0
def subscribe_url(obj):
    ctype = ContentType.objects.get_for_model(obj)
    return reverse('wl_subscribe',
                   content_type='.'.join((ctype.app_label, ctype.model)),
                   object_id=obj.pk)
Beispiel #39
0
 def get_absolute_url(self):
     return reverse('post_by_tag', tag=self.name)
Beispiel #40
0
 def feed_id(self, author):
     return link(reverse('post_by_author', author=author.username))
Beispiel #41
0
def tag_struct(tag):
    return {'name': tag.name,
            'description': tag.name,
            'htmlUrl': tag.get_absolute_url(),
            'rssUrl': reverse('feed', 'tag/%s' % tag.name)}
Beispiel #42
0
 def get_absolute_url(self):
     return reverse('post_detail', year=self.date.year,
                    month=self.date.strftime('%m'),
                    day=self.date.strftime('%d'),
                    slug=self.slug)
Beispiel #43
0
 def location(self, obj):
     return reverse('post_by_tag', tag=obj.name)
Beispiel #44
0
def redirect_to_feed(request, url):
    from django.views.generic.simple import redirect_to
    from lib.helpers import reverse
    return redirect_to(request, url=reverse('feed', url=url))
Beispiel #45
0
 def location(self, obj):
     return reverse('post_by_tag', tag=obj.name)
def revcanonical(obj):
    url = reverse('revcanonical', encode(obj))
    site = getattr(settings, 'REVCANONICAL_SITE', None)
    if not site:
        site = Site.objects.get_current().domain
    return mark_safe(u'<link rev="canonical" href="http://%s%s">' % (site, url))
Beispiel #47
0
 def testEmailChange(self):
     self.assertEquals(self.client.login(email=self.old_email, password=self.name), True)
     check_redirect(lambda: self.client.post(reverse('profile_edit'),
                                             {'email': self.new_email}))
     self.assertEqual(len(mail.outbox), 1)
Beispiel #48
0
def get_server():
    url = 'http://%s%s' % (Site.objects.get_current().domain,
                           reverse('openid_endpoint'))
    return server.Server(DjangoidStore(), url)