From cbd0752740b4dfb054179f68ca330b8ac212ec77 Mon Sep 17 00:00:00 2001 From: Paul Oswald Date: Wed, 15 Feb 2012 10:30:56 +0900 Subject: Move the templates into a named directory --- djangorestframework/utils/staticviews.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'djangorestframework/utils') diff --git a/djangorestframework/utils/staticviews.py b/djangorestframework/utils/staticviews.py index 9bae0ee7..caa63ccd 100644 --- a/djangorestframework/utils/staticviews.py +++ b/djangorestframework/utils/staticviews.py @@ -12,7 +12,7 @@ import base64 # be making settings changes in order to accomodate django-rest-framework @csrf_protect @never_cache -def api_login(request, template_name='api_login.html', +def api_login(request, template_name='djangorestframework/api_login.html', redirect_field_name=REDIRECT_FIELD_NAME, authentication_form=AuthenticationForm): """Displays the login form and handles the login action.""" @@ -57,5 +57,5 @@ def api_login(request, template_name='api_login.html', }, context_instance=RequestContext(request)) -def api_logout(request, next_page=None, template_name='api_login.html', redirect_field_name=REDIRECT_FIELD_NAME): +def api_logout(request, next_page=None, template_name='djangorestframework/api_login.html', redirect_field_name=REDIRECT_FIELD_NAME): return logout(request, next_page, template_name, redirect_field_name) -- cgit v1.2.3 From 50198935af1f772835a3c26943cbb245295c60e5 Mon Sep 17 00:00:00 2001 From: Paul Oswald Date: Mon, 20 Feb 2012 22:16:51 +0900 Subject: Rename templates to 'base.html', 'api.html', 'api.txt' and 'login.html' --- djangorestframework/utils/staticviews.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'djangorestframework/utils') diff --git a/djangorestframework/utils/staticviews.py b/djangorestframework/utils/staticviews.py index caa63ccd..7cbc0b9b 100644 --- a/djangorestframework/utils/staticviews.py +++ b/djangorestframework/utils/staticviews.py @@ -12,7 +12,7 @@ import base64 # be making settings changes in order to accomodate django-rest-framework @csrf_protect @never_cache -def api_login(request, template_name='djangorestframework/api_login.html', +def api_login(request, template_name='djangorestframework/login.html', redirect_field_name=REDIRECT_FIELD_NAME, authentication_form=AuthenticationForm): """Displays the login form and handles the login action.""" @@ -57,5 +57,5 @@ def api_login(request, template_name='djangorestframework/api_login.html', }, context_instance=RequestContext(request)) -def api_logout(request, next_page=None, template_name='djangorestframework/api_login.html', redirect_field_name=REDIRECT_FIELD_NAME): +def api_logout(request, next_page=None, template_name='djangorestframework/login.html', redirect_field_name=REDIRECT_FIELD_NAME): return logout(request, next_page, template_name, redirect_field_name) -- cgit v1.2.3 From af4851f7a873a07677c51fb9615cd26c5eb0cb89 Mon Sep 17 00:00:00 2001 From: Daniel Izquierdo Date: Mon, 20 Feb 2012 18:05:12 +0900 Subject: Move the new `reverse' function from urlresolvers to utils --- djangorestframework/utils/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'djangorestframework/utils') diff --git a/djangorestframework/utils/__init__.py b/djangorestframework/utils/__init__.py index 634d0d68..ba2f6e05 100644 --- a/djangorestframework/utils/__init__.py +++ b/djangorestframework/utils/__init__.py @@ -1,6 +1,6 @@ from django.utils.encoding import smart_unicode from django.utils.xmlutils import SimplerXMLGenerator -from django.core.urlresolvers import resolve +from django.core.urlresolvers import resolve, reverse from django.conf import settings from djangorestframework.compat import StringIO @@ -173,3 +173,6 @@ class XMLRenderer(): def dict2xml(input): return XMLRenderer().dict2xml(input) + +def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current_app=None): + raise NotImplementedError -- cgit v1.2.3 From 13110a386c9d72feee8cc11f0f45024ba1d8a9f2 Mon Sep 17 00:00:00 2001 From: Daniel Izquierdo Date: Mon, 20 Feb 2012 18:46:47 +0900 Subject: Implement a custom reverse that builds absolute URLs with a request object --- djangorestframework/utils/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'djangorestframework/utils') diff --git a/djangorestframework/utils/__init__.py b/djangorestframework/utils/__init__.py index ba2f6e05..f72e0046 100644 --- a/djangorestframework/utils/__init__.py +++ b/djangorestframework/utils/__init__.py @@ -1,6 +1,6 @@ from django.utils.encoding import smart_unicode from django.utils.xmlutils import SimplerXMLGenerator -from django.core.urlresolvers import resolve, reverse +from django.core.urlresolvers import resolve, reverse as django_reverse from django.conf import settings from djangorestframework.compat import StringIO @@ -174,5 +174,6 @@ class XMLRenderer(): def dict2xml(input): return XMLRenderer().dict2xml(input) -def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current_app=None): - raise NotImplementedError + +def reverse(viewname, request, *args, **kwargs): + return request.build_absolute_uri(django_reverse(viewname, *args, **kwargs)) -- cgit v1.2.3 From 6f4fab81d2926af47e75e0c1bae4aad17c6bca91 Mon Sep 17 00:00:00 2001 From: Daniel Izquierdo Date: Tue, 21 Feb 2012 15:30:00 +0900 Subject: Add a docstring for `reverse()' --- djangorestframework/utils/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'djangorestframework/utils') diff --git a/djangorestframework/utils/__init__.py b/djangorestframework/utils/__init__.py index f72e0046..a0519e51 100644 --- a/djangorestframework/utils/__init__.py +++ b/djangorestframework/utils/__init__.py @@ -176,4 +176,8 @@ def dict2xml(input): def reverse(viewname, request, *args, **kwargs): + """ + Do the same as :py:func:`django.core.urlresolvers.reverse` but using + *request* to build a fully qualified URL. + """ return request.build_absolute_uri(django_reverse(viewname, *args, **kwargs)) -- cgit v1.2.3 From f17f3886f42c2068e6e8a41c6e5fe6bfe1408add Mon Sep 17 00:00:00 2001 From: Daniel Izquierdo Date: Tue, 21 Feb 2012 15:55:39 +0900 Subject: Implement `reverse_lazy()' --- djangorestframework/utils/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'djangorestframework/utils') diff --git a/djangorestframework/utils/__init__.py b/djangorestframework/utils/__init__.py index a0519e51..fc8bae92 100644 --- a/djangorestframework/utils/__init__.py +++ b/djangorestframework/utils/__init__.py @@ -1,3 +1,4 @@ +import django from django.utils.encoding import smart_unicode from django.utils.xmlutils import SimplerXMLGenerator from django.core.urlresolvers import resolve, reverse as django_reverse @@ -181,3 +182,13 @@ def reverse(viewname, request, *args, **kwargs): *request* to build a fully qualified URL. """ return request.build_absolute_uri(django_reverse(viewname, *args, **kwargs)) + +if django.VERSION >= (1, 4): + from django.core.urlresolvers import reverse_lazy as django_reverse_lazy + + def reverse_lazy(viewname, request, *args, **kwargs): + """ + Do the same as :py:func:`django.core.urlresolvers.reverse_lazy` but using + *request* to build a fully qualified URL. + """ + return request.build_absolute_uri(django_reverse_lazy(viewname, *args, **kwargs)) -- cgit v1.2.3 From ca9465f11e3310b7b1e18cd893e96b69963f68c9 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 21 Feb 2012 20:47:55 +0000 Subject: reverse gets it's own module --- djangorestframework/utils/__init__.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'djangorestframework/utils') diff --git a/djangorestframework/utils/__init__.py b/djangorestframework/utils/__init__.py index fc8bae92..537d4252 100644 --- a/djangorestframework/utils/__init__.py +++ b/djangorestframework/utils/__init__.py @@ -1,7 +1,7 @@ import django from django.utils.encoding import smart_unicode from django.utils.xmlutils import SimplerXMLGenerator -from django.core.urlresolvers import resolve, reverse as django_reverse +from django.core.urlresolvers import resolve from django.conf import settings from djangorestframework.compat import StringIO @@ -174,21 +174,3 @@ class XMLRenderer(): def dict2xml(input): return XMLRenderer().dict2xml(input) - - -def reverse(viewname, request, *args, **kwargs): - """ - Do the same as :py:func:`django.core.urlresolvers.reverse` but using - *request* to build a fully qualified URL. - """ - return request.build_absolute_uri(django_reverse(viewname, *args, **kwargs)) - -if django.VERSION >= (1, 4): - from django.core.urlresolvers import reverse_lazy as django_reverse_lazy - - def reverse_lazy(viewname, request, *args, **kwargs): - """ - Do the same as :py:func:`django.core.urlresolvers.reverse_lazy` but using - *request* to build a fully qualified URL. - """ - return request.build_absolute_uri(django_reverse_lazy(viewname, *args, **kwargs)) -- cgit v1.2.3 From b074754b54adf172cd2d102e2a326a7f322cf2ef Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 21 Feb 2012 22:13:41 +0000 Subject: Remove ADMIN_MEDIA_PREFIX everywhere --- djangorestframework/utils/__init__.py | 37 -------------------------------- djangorestframework/utils/staticviews.py | 1 - 2 files changed, 38 deletions(-) (limited to 'djangorestframework/utils') diff --git a/djangorestframework/utils/__init__.py b/djangorestframework/utils/__init__.py index 537d4252..ca16b261 100644 --- a/djangorestframework/utils/__init__.py +++ b/djangorestframework/utils/__init__.py @@ -9,11 +9,6 @@ from djangorestframework.compat import StringIO import re import xml.etree.ElementTree as ET - -#def admin_media_prefix(request): -# """Adds the ADMIN_MEDIA_PREFIX to the request context.""" -# return {'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX} - from mediatypes import media_type_matches, is_form_media_type from mediatypes import add_media_type_param, get_media_type_params, order_by_precedence @@ -49,38 +44,6 @@ def url_resolves(url): return True -# From http://www.koders.com/python/fidB6E125C586A6F49EAC38992CF3AFDAAE35651975.aspx?s=mdef:xml -#class object_dict(dict): -# """object view of dict, you can -# >>> a = object_dict() -# >>> a.fish = 'fish' -# >>> a['fish'] -# 'fish' -# >>> a['water'] = 'water' -# >>> a.water -# 'water' -# >>> a.test = {'value': 1} -# >>> a.test2 = object_dict({'name': 'test2', 'value': 2}) -# >>> a.test, a.test2.name, a.test2.value -# (1, 'test2', 2) -# """ -# def __init__(self, initd=None): -# if initd is None: -# initd = {} -# dict.__init__(self, initd) -# -# def __getattr__(self, item): -# d = self.__getitem__(item) -# # if value is the only key in object, you can omit it -# if isinstance(d, dict) and 'value' in d and len(d) == 1: -# return d['value'] -# else: -# return d -# -# def __setattr__(self, item, value): -# self.__setitem__(item, value) - - # From xml2dict class XML2Dict(object): diff --git a/djangorestframework/utils/staticviews.py b/djangorestframework/utils/staticviews.py index 7cbc0b9b..101df4e9 100644 --- a/djangorestframework/utils/staticviews.py +++ b/djangorestframework/utils/staticviews.py @@ -53,7 +53,6 @@ def api_login(request, template_name='djangorestframework/login.html', redirect_field_name: redirect_to, #'site': current_site, #'site_name': current_site.name, - 'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX, }, context_instance=RequestContext(request)) -- cgit v1.2.3 From afdda88b13bb168d91cee267799a7e8d9bf26366 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 23 Feb 2012 09:22:37 +0000 Subject: Remove unused 'staticviews' --- djangorestframework/utils/staticviews.py | 60 -------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 djangorestframework/utils/staticviews.py (limited to 'djangorestframework/utils') diff --git a/djangorestframework/utils/staticviews.py b/djangorestframework/utils/staticviews.py deleted file mode 100644 index 101df4e9..00000000 --- a/djangorestframework/utils/staticviews.py +++ /dev/null @@ -1,60 +0,0 @@ -from django.contrib.auth.views import * -from django.conf import settings -from django.http import HttpResponse -from django.shortcuts import render_to_response -from django.template import RequestContext -import base64 - - -# BLERGH -# Replicate django.contrib.auth.views.login simply so we don't have get users to update TEMPLATE_CONTEXT_PROCESSORS -# to add ADMIN_MEDIA_PREFIX to the RequestContext. I don't like this but really really want users to not have to -# be making settings changes in order to accomodate django-rest-framework -@csrf_protect -@never_cache -def api_login(request, template_name='djangorestframework/login.html', - redirect_field_name=REDIRECT_FIELD_NAME, - authentication_form=AuthenticationForm): - """Displays the login form and handles the login action.""" - - redirect_to = request.REQUEST.get(redirect_field_name, '') - - if request.method == "POST": - form = authentication_form(data=request.POST) - if form.is_valid(): - # Light security check -- make sure redirect_to isn't garbage. - if not redirect_to or ' ' in redirect_to: - redirect_to = settings.LOGIN_REDIRECT_URL - - # Heavier security check -- redirects to http://example.com should - # not be allowed, but things like /view/?param=http://example.com - # should be allowed. This regex checks if there is a '//' *before* a - # question mark. - elif '//' in redirect_to and re.match(r'[^\?]*//', redirect_to): - redirect_to = settings.LOGIN_REDIRECT_URL - - # Okay, security checks complete. Log the user in. - auth_login(request, form.get_user()) - - if request.session.test_cookie_worked(): - request.session.delete_test_cookie() - - return HttpResponseRedirect(redirect_to) - - else: - form = authentication_form(request) - - request.session.set_test_cookie() - - #current_site = get_current_site(request) - - return render_to_response(template_name, { - 'form': form, - redirect_field_name: redirect_to, - #'site': current_site, - #'site_name': current_site.name, - }, context_instance=RequestContext(request)) - - -def api_logout(request, next_page=None, template_name='djangorestframework/login.html', redirect_field_name=REDIRECT_FIELD_NAME): - return logout(request, next_page, template_name, redirect_field_name) -- cgit v1.2.3