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)
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)
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))
def feed_links(self): return ({ 'rel': u'alternate', 'href': self.feed_id() }, { 'rel': u'self', 'href': link(reverse(get_feed_type(type), 'blog')) })
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)))
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))
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'))
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'))
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)) })
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', '')))) })
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}
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}
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))) })
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)))})
def get_absolute_url(self): return reverse('wpimport.views.post_detail', self.id)
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))
def feed_id(self): return link(reverse('post_list'))
def feed_id(self, author): return link(reverse('post_by_author', author=author.username))
def feed_id(self): return link(reverse('life_index'))
def feed_id(self): return link(reverse('friends_index'))
def get_server(): url = 'http://%s%s' % (Site.objects.get_current().domain, reverse('openid_endpoint')) return server.Server(DjangoidStore(), url)
def get_absolute_url(self): return reverse('post_by_tag', tag=self.name)
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)
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))})
def location(self, obj): return reverse(obj)
def unsubscribe_type_url(content_type): return reverse('wl_unsubscribe_type', content_type='.'.join( (content_type.app_label, content_type.model)))
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', ''))))})
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))
def feed_links(self): return ({'rel': u'alternate', 'href': self.feed_id()}, {'rel': u'self', 'href': link(reverse(get_feed_type(type), 'blog'))})
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)
def tag_struct(tag): return {'name': tag.name, 'description': tag.name, 'htmlUrl': tag.get_absolute_url(), 'rssUrl': reverse('feed', 'tag/%s' % tag.name)}
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))
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)