mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
mergeed to trunk r1266
git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@1269 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
commit
ef7a5d7346
1
django/conf/app_template/views.py
Normal file
1
django/conf/app_template/views.py
Normal file
@ -0,0 +1 @@
|
||||
# Create your views here.
|
@ -102,7 +102,6 @@ class FormWrapper:
|
||||
self.manipulator, self.data = manipulator, data
|
||||
self.error_dict = error_dict
|
||||
self._inline_collections = None
|
||||
self.fields = [self.__getitem__(field.field_name) for field in self.manipulator.fields]
|
||||
self.edit_inline = edit_inline
|
||||
|
||||
def __repr__(self):
|
||||
@ -134,6 +133,15 @@ class FormWrapper:
|
||||
def has_errors(self):
|
||||
return self.error_dict != {}
|
||||
|
||||
def _get_fields(self):
|
||||
try:
|
||||
return self._fields
|
||||
except AttributeError:
|
||||
self._fields = [self.__getitem__(field.field_name) for field in self.manipulator.fields]
|
||||
return self._fields
|
||||
|
||||
fields = property(_get_fields)
|
||||
|
||||
class FormFieldWrapper:
|
||||
"A bridge between the template system and an individual form field. Used by FormWrapper."
|
||||
def __init__(self, formfield, data, error_list):
|
||||
|
@ -247,7 +247,7 @@ def ngettext(singular, plural, number):
|
||||
return t.ngettext(singular, plural, number)
|
||||
if _default is None:
|
||||
from django.conf import settings
|
||||
_default = translation('*', settings.LANGUAGE_CODE)
|
||||
_default = translation(settings.LANGUAGE_CODE)
|
||||
return _default.ngettext(singular, plural, number)
|
||||
|
||||
gettext_lazy = lazy(gettext, str)
|
||||
|
@ -389,7 +389,7 @@ You use this custom manipulator exactly as you would use an auto-generated one.
|
||||
Here's a simple function that might drive the above form::
|
||||
|
||||
def contact_form(request):
|
||||
manipulator = ContactFormManipulator()
|
||||
manipulator = ContactManipulator()
|
||||
if request.POST:
|
||||
new_data = request.POST.copy()
|
||||
errors = manipulator.get_validation_errors(new_data)
|
||||
|
@ -76,33 +76,34 @@ couple of common cases: rendering a template when no view logic is needed,
|
||||
and issuing a redirect. These views are:
|
||||
|
||||
``direct_to_template``
|
||||
Renders a given template using any extra parameters passed in the
|
||||
urlpattern; requires the ``template`` argument.
|
||||
|
||||
Renders a given template, passing it a ``{{ params }}`` template variable,
|
||||
which is a dictionary of the parameters captured in the URL. This requires
|
||||
the ``template`` argument.
|
||||
|
||||
For example, given the following URL patterns::
|
||||
|
||||
|
||||
urlpatterns = patterns('django.views.generic.simple',
|
||||
(r'^foo/$', 'direct_to_template', {'template' : 'foo_index'}),
|
||||
(r'^foo/(?P<id>\d+)/$', 'direct_to_template', {'template' : 'foo_detail'}),
|
||||
(r'^foo/$', 'direct_to_template', {'template': 'foo_index'}),
|
||||
(r'^foo/(?P<id>\d+)/$', 'direct_to_template', {'template': 'foo_detail'}),
|
||||
)
|
||||
|
||||
|
||||
... a request to ``/foo/`` would cause the ``foo_index`` template to be
|
||||
rendered, and a request to ``/foo/15/`` would cause the ``foo_detail``
|
||||
template to be rendered with a context variable ``{{ params.id }}`` that is
|
||||
set to ``15``.
|
||||
|
||||
|
||||
``redirect_to``
|
||||
Issue a redirect to a given URL.
|
||||
|
||||
The given url may contain dict-style string formatting which will be
|
||||
The given URL may contain dict-style string formatting, which will be
|
||||
interpolated against the params in the URL. For example, to redirect from
|
||||
``/foo/<id>/`` to ``/bar/<id>/``, you could use the following urlpattern::
|
||||
|
||||
urlpatterns = patterns('django.views.generic.simple',
|
||||
('^foo/(?p<id>\d+)/$', 'redirect_to', {'url' : '/bar/%(id)s/'}),
|
||||
)
|
||||
|
||||
If the given url is ``None``, a HttpResponseGone (410) will be issued.
|
||||
|
||||
If the given URL is ``None``, an ``HttpResponseGone`` (410) will be issued.
|
||||
|
||||
Using date-based generic views
|
||||
==============================
|
||||
|
@ -77,12 +77,19 @@ It's easy either way.
|
||||
Installing the official version
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
There IS no official version yet. But once there is, here's how it'll work:
|
||||
1. Download Django-0.90.tar.gz from our `download page`_.
|
||||
2. ``tar xzvf Django-0.90.tar.gz``
|
||||
3. ``cd Django-0.90``
|
||||
4. ``sudo python setup.py install``
|
||||
|
||||
1. Download the tarball of the latest official version from our `download page`_.
|
||||
2. ``tar xzvf django-1.0.0.tar.gz``
|
||||
3. ``cd django-1.0.0``
|
||||
4. ``python setup.py install``
|
||||
Note that the last command will automatically download and install setuptools_
|
||||
if you don't already have it installed. This requires a working Internet
|
||||
connection.
|
||||
|
||||
This will install Django in your Python installation's ``site-packages``
|
||||
directory.
|
||||
|
||||
.. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools
|
||||
|
||||
Installing the development version
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -246,11 +246,12 @@ variables:
|
||||
|
||||
* ``user`` -- An ``auth.User`` instance representing the currently
|
||||
logged-in user (or an ``AnonymousUser`` instance, if the client isn't
|
||||
logged in).
|
||||
logged in). See the `user authentication docs`.
|
||||
* ``messages`` -- A list of ``auth.Message`` objects for the currently
|
||||
logged-in user.
|
||||
* ``perms`` -- An instance of ``django.core.extensions.PermWrapper``,
|
||||
representing the permissions that the currently logged-in user has.
|
||||
representing the permissions that the currently logged-in user has. See
|
||||
the `permissions docs`_.
|
||||
|
||||
Also, if your ``DEBUG`` setting is set to ``True``, every ``DjangoContext``
|
||||
instance has the following two extra variables:
|
||||
@ -280,6 +281,9 @@ This technique has two caveats:
|
||||
* You'll have to be careful not to set the variable ``current_time`` when
|
||||
you populate this context. If you do, you'll override the other one.
|
||||
|
||||
.. _user authentication docs: http://www.djangoproject.com/documentation/models/authentication/#users
|
||||
.. _permissions docs: http://www.djangoproject.com/documentation/models/authentication/#permissions
|
||||
|
||||
Loading templates
|
||||
-----------------
|
||||
|
||||
|
@ -131,8 +131,7 @@ That'll create a directory structure like this::
|
||||
models/
|
||||
__init__.py
|
||||
polls.py
|
||||
views/
|
||||
__init__.py
|
||||
views.py
|
||||
|
||||
This directory structure will house the poll application.
|
||||
|
||||
|
@ -81,8 +81,8 @@ Now, try logging in. You should see the Django admin index page:
|
||||
:alt: Django admin index page
|
||||
:target: http://media.djangoproject.com/img/doc/tutorial/admin02.png
|
||||
|
||||
By default, you should see four types of editable content: groups, users,
|
||||
redirects and flat pages. These are core features Django ships with by default.
|
||||
By default, you should see two types of editable content: groups and users.
|
||||
These are core features Django ships with by default.
|
||||
|
||||
.. _"I can't log in" questions: http://www.djangoproject.com/documentation/faq/#the-admin-site
|
||||
|
||||
|
@ -73,10 +73,10 @@ this::
|
||||
from django.conf.urls.defaults import *
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^polls/$', 'myproject.apps.polls.views.polls.index'),
|
||||
(r'^polls/(?P<poll_id>\d+)/$', 'myproject.apps.polls.views.polls.detail'),
|
||||
(r'^polls/(?P<poll_id>\d+)/results/$', 'myproject.apps.polls.views.polls.results'),
|
||||
(r'^polls/(?P<poll_id>\d+)/vote/$', 'myproject.apps.polls.views.polls.vote'),
|
||||
(r'^polls/$', 'myproject.apps.polls.views.index'),
|
||||
(r'^polls/(?P<poll_id>\d+)/$', 'myproject.apps.polls.views.detail'),
|
||||
(r'^polls/(?P<poll_id>\d+)/results/$', 'myproject.apps.polls.views.results'),
|
||||
(r'^polls/(?P<poll_id>\d+)/vote/$', 'myproject.apps.polls.views.vote'),
|
||||
)
|
||||
|
||||
This is worth a review. When somebody requests a page from your Web site --
|
||||
@ -84,8 +84,8 @@ say, "/polls/23/", Django will load this Python module, because it's pointed to
|
||||
by the ``ROOT_URLCONF`` setting. It finds the variable named ``urlpatterns``
|
||||
and traverses the regular expressions in order. When it finds a regular
|
||||
expression that matches -- ``r'^polls/(?P<poll_id>\d+)/$'`` -- it loads the
|
||||
associated Python package/module: ``myproject.apps.polls.views.polls.detail``. That
|
||||
corresponds to the function ``detail()`` in ``myproject/apps/polls/views/polls.py``.
|
||||
associated Python package/module: ``myproject.apps.polls.views.detail``. That
|
||||
corresponds to the function ``detail()`` in ``myproject/apps/polls/views.py``.
|
||||
Finally, it calls that ``detail()`` function like so::
|
||||
|
||||
detail(request=<HttpRequest object>, poll_id=23)
|
||||
@ -99,9 +99,9 @@ what you can do with them. And there's no need to add URL cruft such as
|
||||
``.php`` -- unless you have a sick sense of humor, in which case you can do
|
||||
something like this::
|
||||
|
||||
(r'^polls/latest\.php$', 'myproject.apps.polls.views.polls.index'),
|
||||
(r'^polls/latest\.php$', 'myproject.apps.polls.views.index'),
|
||||
|
||||
But, don't do that. It's stupid.
|
||||
But, don't do that. It's silly.
|
||||
|
||||
If you need help with regular expressions, see `Wikipedia's entry`_ and the
|
||||
`Python documentation`_. Also, the O'Reilly book "Mastering Regular
|
||||
@ -125,16 +125,21 @@ Fire up the Django development Web server::
|
||||
django-admin.py runserver --settings=myproject.settings
|
||||
|
||||
Now go to "http://localhost:8000/polls/" on your domain in your Web browser.
|
||||
You should get a Python traceback with the following error message::
|
||||
You should get a pleasantly-colored error page with the following message::
|
||||
|
||||
ViewDoesNotExist: Could not import myproject.apps.polls.views.polls. Error
|
||||
was: No module named polls
|
||||
ViewDoesNotExist at /polls/
|
||||
|
||||
Tried index in module myproject.apps.polls.views. Error was: 'module'
|
||||
object has no attribute 'index'
|
||||
|
||||
This error happened because you haven't written a function ``index()`` in the
|
||||
module ``myproject/apps/polls/views.py``.
|
||||
|
||||
Try "/polls/23/", "/polls/23/results/" and "/polls/23/vote/". The error
|
||||
messages should tell you which view Django tried (and failed to find, because
|
||||
you haven't written any views yet).
|
||||
messages tell you which view Django tried (and failed to find, because you
|
||||
haven't written any views yet).
|
||||
|
||||
Time to write the first view. Create the file ``myproject/apps/polls/views/polls.py``
|
||||
Time to write the first view. Open the file ``myproject/apps/polls/views.py``
|
||||
and put the following Python code in it::
|
||||
|
||||
from django.utils.httpwrappers import HttpResponse
|
||||
@ -374,19 +379,19 @@ Take some time to play around with the views and template system. As you edit
|
||||
the URLconf, you may notice there's a fair bit of redundancy in it::
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^polls/$', 'myproject.apps.polls.views.polls.index'),
|
||||
(r'^polls/(?P<poll_id>\d+)/$', 'myproject.apps.polls.views.polls.detail'),
|
||||
(r'^polls/(?P<poll_id>\d+)/results/$', 'myproject.apps.polls.views.polls.results'),
|
||||
(r'^polls/(?P<poll_id>\d+)/vote/$', 'myproject.apps.polls.views.polls.vote'),
|
||||
(r'^polls/$', 'myproject.apps.polls.views.index'),
|
||||
(r'^polls/(?P<poll_id>\d+)/$', 'myproject.apps.polls.views.detail'),
|
||||
(r'^polls/(?P<poll_id>\d+)/results/$', 'myproject.apps.polls.views.results'),
|
||||
(r'^polls/(?P<poll_id>\d+)/vote/$', 'myproject.apps.polls.views.vote'),
|
||||
)
|
||||
|
||||
Namely, ``myproject.apps.polls.views.polls`` is in every callback.
|
||||
Namely, ``myproject.apps.polls.views`` is in every callback.
|
||||
|
||||
Because this is a common case, the URLconf framework provides a shortcut for
|
||||
common prefixes. You can factor out the common prefixes and add them as the
|
||||
first argument to ``patterns()``, like so::
|
||||
|
||||
urlpatterns = patterns('myproject.apps.polls.views.polls',
|
||||
urlpatterns = patterns('myproject.apps.polls.views',
|
||||
(r'^polls/$', 'index'),
|
||||
(r'^polls/(?P<poll_id>\d+)/$', 'detail'),
|
||||
(r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
|
||||
@ -435,7 +440,7 @@ Now that we've decoupled that, we need to decouple the
|
||||
'myproject.apps.polls.urls' urlconf by removing the leading "polls/" from each
|
||||
line::
|
||||
|
||||
urlpatterns = patterns('myproject.apps.polls.views.polls',
|
||||
urlpatterns = patterns('myproject.apps.polls.views',
|
||||
(r'^$', 'index'),
|
||||
(r'^(?P<poll_id>\d+)/$', 'detail'),
|
||||
(r'^(?P<poll_id>\d+)/results/$', 'results'),
|
||||
|
@ -44,9 +44,9 @@ Now, let's create a Django view that handles the submitted data and does
|
||||
something with it. Remember, in `Tutorial 3`_, we create a URLconf that
|
||||
included this line::
|
||||
|
||||
(r'^polls/(?P<poll_id>\d+)/vote/$', 'myproject.apps.polls.views.polls.vote'),
|
||||
(r'^polls/(?P<poll_id>\d+)/vote/$', 'myproject.apps.polls.views.vote'),
|
||||
|
||||
So let's create a ``vote()`` function in ``myproject/apps/polls/views/polls.py``::
|
||||
So let's create a ``vote()`` function in ``myproject/apps/polls/views.py``::
|
||||
|
||||
from django.core.extensions import get_object_or_404, render_to_response
|
||||
from django.models.polls import choices, polls
|
||||
@ -158,7 +158,7 @@ so far::
|
||||
|
||||
from django.conf.urls.defaults import *
|
||||
|
||||
urlpatterns = patterns('myproject.apps.polls.views.polls',
|
||||
urlpatterns = patterns('myproject.apps.polls.views',
|
||||
(r'^$', 'index'),
|
||||
(r'^(?P<poll_id>\d+)/$', 'detail'),
|
||||
(r'^(?P<poll_id>\d+)/results/$', 'results'),
|
||||
@ -178,7 +178,7 @@ Change it like so::
|
||||
(r'^$', 'django.views.generic.list_detail.object_list', info_dict),
|
||||
(r'^(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict),
|
||||
(r'^(?P<object_id>\d+)/results/$', 'django.views.generic.list_detail.object_detail', dict(info_dict, template_name='polls/results')),
|
||||
(r'^(?P<poll_id>\d+)/vote/$', 'myproject.apps.polls.views.polls.vote'),
|
||||
(r'^(?P<poll_id>\d+)/vote/$', 'myproject.apps.polls.views.vote'),
|
||||
)
|
||||
|
||||
We're using two generic views here: ``object_list`` and ``object_detail``.
|
||||
@ -217,7 +217,7 @@ In the ``vote()`` view, change the template call from ``polls/detail`` to
|
||||
``polls/polls_detail``, and pass ``object`` in the context instead of ``poll``.
|
||||
|
||||
Finally, you can delete the ``index()``, ``detail()`` and ``results()`` views
|
||||
from ``polls/views/polls.py``. We don't need them anymore.
|
||||
from ``polls/views.py``. We don't need them anymore.
|
||||
|
||||
For full details on generic views, see the `generic views documentation`_.
|
||||
|
||||
|
@ -14,7 +14,7 @@ the appropriate options to ``use_setuptools()``.
|
||||
This file can also be run as a script to install or upgrade setuptools.
|
||||
"""
|
||||
import sys
|
||||
DEFAULT_VERSION = "0.6a5"
|
||||
DEFAULT_VERSION = "0.6a7"
|
||||
DEFAULT_URL = "http://cheeseshop.python.org/packages/%s/s/setuptools/" % sys.version[:3]
|
||||
|
||||
md5_data = {
|
||||
@ -30,6 +30,10 @@ md5_data = {
|
||||
'setuptools-0.6a4-py2.4.egg': '7f33c3ac2ef1296f0ab4fac1de4767d8',
|
||||
'setuptools-0.6a5-py2.3.egg': '748408389c49bcd2d84f6ae0b01695b1',
|
||||
'setuptools-0.6a5-py2.4.egg': '999bacde623f4284bfb3ea77941d2627',
|
||||
'setuptools-0.6a6-py2.3.egg': '7858139f06ed0600b0d9383f36aca24c',
|
||||
'setuptools-0.6a6-py2.4.egg': 'c10d20d29acebce0dc76219dc578d058',
|
||||
'setuptools-0.6a7-py2.3.egg': 'cfc4125ddb95c07f9500adc5d6abef6f',
|
||||
'setuptools-0.6a7-py2.4.egg': 'c6d62dab4461f71aed943caea89e6f20',
|
||||
}
|
||||
|
||||
import sys, os
|
||||
|
26
setup.py
26
setup.py
@ -4,8 +4,8 @@ ez_setup.use_setuptools()
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name = "django",
|
||||
version = "1.0.0",
|
||||
name = "Django",
|
||||
version = "0.90",
|
||||
url = 'http://www.djangoproject.com/',
|
||||
author = 'Lawrence Journal-World',
|
||||
author_email = 'holovaty@gmail.com',
|
||||
@ -13,7 +13,27 @@ setup(
|
||||
license = 'BSD',
|
||||
packages = find_packages(),
|
||||
package_data = {
|
||||
'django.contrib.admin': ['templates/admin/*.html',
|
||||
'': ['*.TXT'],
|
||||
'django.conf': ['locale/bn/LC_MESSAGES/*',
|
||||
'locale/cs/LC_MESSAGES/*',
|
||||
'locale/cy/LC_MESSAGES/*',
|
||||
'locale/da/LC_MESSAGES/*',
|
||||
'locale/de/LC_MESSAGES/*',
|
||||
'locale/en/LC_MESSAGES/*',
|
||||
'locale/es/LC_MESSAGES/*',
|
||||
'locale/fr/LC_MESSAGES/*',
|
||||
'locale/gl/LC_MESSAGES/*',
|
||||
'locale/is/LC_MESSAGES/*',
|
||||
'locale/it/LC_MESSAGES/*',
|
||||
'locale/no/LC_MESSAGES/*',
|
||||
'locale/pt_BR/LC_MESSAGES/*',
|
||||
'locale/ro/LC_MESSAGES/*',
|
||||
'locale/ru/LC_MESSAGES/*',
|
||||
'locale/sk/LC_MESSAGES/*',
|
||||
'locale/sr/LC_MESSAGES/*',
|
||||
'locale/sv/LC_MESSAGES/*',
|
||||
'locale/zh_CN/LC_MESSAGES/*'],
|
||||
'django.contrib.admin':['templates/admin/*.html',
|
||||
'templates/admin_doc/*.html',
|
||||
'templates/registration/*.html',
|
||||
'templates/widget/*.html',
|
||||
|
Loading…
x
Reference in New Issue
Block a user