Merge remote-tracking branch 'origin/develop' into inline-formsets

Conflicts:
	djadmin2/templates/admin2/bootstrap/model_add_form.html
	djadmin2/templates/admin2/bootstrap/model_edit_form.html
	djadmin2/views.py
This commit is contained in:
Andrew Ingram 2013-05-22 00:58:53 +01:00
commit 05f69775b2
9 changed files with 146 additions and 30 deletions

View file

@ -1,5 +1,5 @@
{% extends "admin2/bootstrap/base.html" %}
{% load admin2_urls %}
{% load admin2_tags %}
{% block content %}

View file

@ -1,5 +1,5 @@
{% extends "admin2/bootstrap/base.html" %}
{% load admin2_urls %}
{% load admin2_tags %}
{% block title %}Select {{ model }} to change{% endblock %}

View file

@ -0,0 +1,26 @@
{% extends "admin2/bootstrap/base.html" %}
{% block title %}{{ action }} {{ model }}{% endblock %}
{% block page_title %}{{ action }} {{ model }}{% endblock %}
{% block content %}
<div class="row">
<div class="span12">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
{% for formset in inlines %}
{{ formset }}
{% endfor %}
<button class="btn btn-small" type="submit" name="_addanother">Save and add another</button>
<button class="btn btn-small" type="submit" name="_continue">Save and continue editing</button>
<button class="btn btn-small btn-success" type="submit" name="_save">Save</button>
</form>
</div>
</div>
{% endblock content %}

View file

@ -1 +1,35 @@
# TODO - stub out tests
from django.db import models
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
from ..models import ModelAdmin2
from ..core import Admin2
class Thing(models.Model):
pass
class Admin2Test(TestCase):
def setUp(self):
self.admin2 = Admin2()
def test_register(self):
self.admin2.register(Thing)
self.assertTrue(isinstance(self.admin2.registry[Thing], ModelAdmin2))
def test_register_error(self):
self.admin2.register(Thing)
self.assertRaises(ImproperlyConfigured, self.admin2.register, Thing)
def test_deregister(self):
self.admin2.register(Thing)
self.admin2.deregister(Thing)
self.assertTrue(Thing not in self.admin2.registry)
def test_deregister_error(self):
self.assertRaises(ImproperlyConfigured, self.admin2.deregister, Thing)
def test_get_urls(self):
self.admin2.register(Thing)
self.assertEquals(4, len(self.admin2.get_urls()))

View file

@ -11,6 +11,8 @@ from braces.views import AccessMixin
import extra_views
from .templatetags.admin2_tags import admin2_urlname
ADMIN2_THEME_DIRECTORY = getattr(settings, "ADMIN2_THEME_DIRECTORY", "admin2/bootstrap")
@ -77,6 +79,20 @@ class AdminModel2Mixin(Admin2Mixin, AccessMixin):
return modelform_factory(self.get_model())
class Admin2ModelFormMixin(object):
def get_success_url(self):
if '_continue' in self.request.POST:
view_name = admin2_urlname(self, 'update')
return reverse(view_name, kwargs={'pk': self.object.pk})
if '_addanother' in self.request.POST:
return reverse(admin2_urlname(self, 'create'))
# default to index view
return reverse(admin2_urlname(self, 'index'))
class IndexView(Admin2Mixin, generic.TemplateView):
default_template_name = "index.html"
registry = None
@ -101,37 +117,35 @@ class ModelListView(Admin2Mixin, generic.ListView):
context['model_pluralized'] = self.get_model()._meta.verbose_name_plural
return context
def get_success_url(self):
view_name = 'admin2:{}_{}_detail'.format(self.app_label, self.model_name)
return reverse(view_name, kwargs={'pk': self.object.pk})
class ModelDetailView(AdminModel2Mixin, generic.DetailView):
default_template_name = "model_detail.html"
permission_type = 'view'
class ModelEditFormView(AdminModel2Mixin, extra_views.UpdateWithInlinesView):
class ModelEditFormView(AdminModel2Mixin, Admin2ModelFormMixin, extra_views.UpdateWithInlinesView):
form_class = None
success_url = "../../"
default_template_name = "model_edit_form.html"
default_template_name = "model_update_form.html"
permission_type = 'change'
def get_context_data(self, **kwargs):
context = super(ModelEditFormView, self).get_context_data(**kwargs)
context['model'] = self.get_model()._meta.verbose_name
context['action'] = "Change"
return context
class ModelAddFormView(AdminModel2Mixin, extra_views.CreateWithInlinesView):
class ModelAddFormView(AdminModel2Mixin, Admin2ModelFormMixin, generic.extra_views.CreateWithInlinesView):
form_class = None
default_template_name = "model_add_form.html"
default_template_name = "model_update_form.html"
permission_type = 'add'
def get_context_data(self, **kwargs):
context = super(ModelAddFormView, self).get_context_data(**kwargs)
context['model'] = self.get_model()._meta.verbose_name
context['action'] = "Add"
return context
def get_success_url(self):
view_name = 'admin2:{}_{}_detail'.format(self.app_label, self.model_name)
return reverse(view_name, kwargs={'pk': self.object.pk})
class ModelDeleteView(AdminModel2Mixin, generic.DeleteView):
success_url = "../../"

View file

@ -46,6 +46,8 @@ Tips
Setting up topic branches and generating pull requests
======================================================
.. note:: This is our way of describing our version of git-flow.
While it's handy to provide useful code snippets in an issue, it is better for
you as a developer to submit pull requests. By submitting pull request your
contribution to django-admin2 will be recorded by Github.
@ -72,7 +74,7 @@ To create a topic branch, its easiest to use the convenient ``-b`` argument to `
You should use a verbose enough name for your branch so it is clear what it is
about. Now you can commit your changes and regularly merge in the upstream
master as described below.
develop as described below.
When you are ready to generate a pull request, either for preliminary review,
or for consideration of merging into the project you must first push your local
@ -84,7 +86,10 @@ Now when you go to your fork on GitHub, you will see this branch listed under
the "Source" tab where it says "Switch Branches". Go ahead and select your
topic branch from this list, and then click the "Pull request" button.
Here you can add a comment about your branch. If this in response to
Your pull request should be applied to the **develop** branch of django-admin2.
Be sure to change from the default of ``master`` to ``develop``.
Next, you can add a comment about your branch. If this in response to
a submitted issue, it is good to put a link to that issue in this initial
comment. The repo managers will be notified of your pull request and it will
be reviewed (see below for best practices). Note that you can continue to add
@ -101,16 +106,16 @@ Pull upstream changes into your fork regularly
To pull in upstream changes::
git remote add upstream https://github.com/pydanny/django-admin2.git
git fetch upstream
git remote add upstream https://github.com/twoscoops/django-admin2.git
git fetch upstream develop
Check the log to be sure that you actually want the changes, before merging::
git log upstream/master
git log upstream/develop
Then merge the changes that you fetched::
git merge upstream/master
git merge upstream/develop
For more info, see http://help.github.com/fork-a-repo/
@ -151,10 +156,10 @@ django-admin2 pull requests should be as small/atomic as possible. Large, wide-s
#. If you are fixing a view don't '*cleanup*' unrelated views. That cleanup belongs in another pull request.
#. Changing permissions on a file should be in its own pull request with explicit reasons why.
Follow PEP-8 and keep your code simple!
---------------------------------------
Best Practices
--------------
Memorize the Zen of Python::
Follow PEP-0008 and memorize the Zen of Python::
>>> python -c 'import this'
@ -166,6 +171,11 @@ Furthermore, the pixel shortage is over. We want to see:
* `grid` instead of `g`
* `my_function_that_does_things` instead of `mftdt`
As much as possible, we follow the advice of the `Two Scoops of Django`_ book. Periodically the book will be referenced either for best practices or as a blunt object by the project lead in order to end bike-shedding.
.. _`Two Scoops of Django`: https://2scoops.org
How pull requests are checked, tested, and done
===============================================
@ -181,11 +191,11 @@ Then we run the tests::
We finish with a non-fastforward merge (to preserve the branch history) and push to GitHub::
git checkout master
git checkout develop
git merge --no-ff <branch-name>
git push upstream master
git push upstream develop
.. _installation: install.html
.. _GitHub project: https://github.com/pydanny/django-admin2
.. _issue tracker: https://github.com/pydanny/django-admin2/issues
.. _GitHub project: https://github.com/twoscoops/django-admin2
.. _issue tracker: https://github.com/twoscoops/django-admin2/issues
.. _pydanny: http://pydanny.com

View file

@ -51,7 +51,34 @@ class PostCreateViewTest(BaseIntegrationTest):
follow=True)
self.assertTrue(Post.objects.filter(title="a_post_title").exists())
post = Post.objects.get(title="a_post_title")
self.assertRedirects(response, reverse("admin2:blog_post_detail",
self.assertRedirects(response, reverse("admin2:blog_post_index"))
def test_save_and_add_another_redirects_to_create(self):
"""
Tests that choosing 'Save and add another' from the model create
page redirects the user to the model create page.
"""
post_data = {"title": "a_post_title",
"body": "a_post_body",
"_addanother": ""}
self.client.login(username='admin', password='password')
response = self.client.post(reverse("admin2:blog_post_create"),
post_data)
post = Post.objects.get(title='a_post_title')
self.assertRedirects(response, reverse("admin2:blog_post_create"))
def test_save_and_continue_editing_redirects_to_update(self):
"""
Tests that choosing "Save and continue editing" redirects
the user to the model update form.
"""
post_data = {"title": "Unique",
"body": "a_post_body",
"_continue": ""}
response = self.client.post(reverse("admin2:blog_post_create"),
post_data)
post = Post.objects.get(title="Unique")
self.assertRedirects(response, reverse("admin2:blog_post_update",
args=(post.pk, )))

View file

@ -172,4 +172,9 @@ INTERNAL_IPS = ('127.0.0.1',)
MIDDLEWARE_CLASSES += (
'debug_toolbar.middleware.DebugToolbarMiddleware',
)
DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS': False,
'SHOW_TEMPLATE_CONTEXT': True,
}
########## END TOOLBAR CONFIGURATION