This repository has been archived by the owner on Jul 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
import logging | ||
from django.contrib import messages | ||
|
||
from django.contrib.admin.templatetags.admin_urls import admin_urlname | ||
from django.core.urlresolvers import reverse | ||
from django.http import HttpResponseRedirect | ||
from django.template.response import TemplateResponse | ||
from django.utils.translation import gettext as _ | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def _confirm_action(modeladmin, request, | ||
action, message, | ||
success_message="", | ||
description='', | ||
pk=None, | ||
extra_context=None, **kwargs): | ||
opts = modeladmin.model._meta | ||
context = dict( | ||
modeladmin.admin_site.each_context(request), | ||
opts=opts, | ||
app_label=opts.app_label, | ||
message=message, | ||
description=description, | ||
**kwargs) | ||
if extra_context: | ||
context.update(extra_context) | ||
|
||
if request.method == 'POST': | ||
ret = action(request) | ||
modeladmin.message_user(request, success_message, messages.SUCCESS) | ||
return ret or HttpResponseRedirect(reverse(admin_urlname(opts, | ||
'changelist'))) | ||
|
||
return TemplateResponse(request, | ||
'admin_extra_urls/confirm.html', | ||
context) | ||
|
||
# class ConfirmActionMixin(object): | ||
# def _confirm(self, request, action, message, description='', info='', **kwargs): | ||
# return _confirm_action(self, request, action, message, description, info, **kwargs) |
31 changes: 31 additions & 0 deletions
31
src/admin_extra_urls/templates/admin_extra_urls/confirm.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{% extends 'admin/base_site.html' %} | ||
{% load i18n admin_static admin_list admin_urls %} | ||
{% block breadcrumbs %} | ||
<ul> | ||
<li><a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> | ||
</li> | ||
<li> | ||
<a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_label|capfirst|escape }}</a> | ||
</li> | ||
<li class="active">{{ opts.verbose_name_plural|capfirst }}</li> | ||
</ul> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<h1>Warning:</h1> | ||
<h2>{{ message }}</h2> | ||
<br> | ||
<div><h3>{{ description }}</h3></div> | ||
<hr> | ||
<br><br><br><br><br> | ||
<form method="post"> | ||
{% csrf_token %} | ||
<input type="submit" class="btn btn-large btn-danger" value="Confirm"> | ||
<input type="button" class="btn btn-large btn-success" | ||
onclick="javascript:history.back()" | ||
value="Go Back"> | ||
</form> | ||
<script> | ||
|
||
</script> | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
import logging | ||
from django.core.urlresolvers import reverse | ||
from django_dynamic_fixture import G | ||
import django_webtest | ||
import pytest | ||
from demo.models import DemoModel2 | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def app(request): | ||
wtm = django_webtest.WebTestMixin() | ||
wtm.csrf_checks = False | ||
wtm._patch_settings() | ||
request.addfinalizer(wtm._unpatch_settings) | ||
return django_webtest.DjangoTestApp() | ||
|
||
|
||
@pytest.fixture | ||
def demomodel2(): | ||
return G(DemoModel2) | ||
|
||
|
||
def test_confirm(app, admin_user): | ||
url = reverse('admin:demo_demomodel1_changelist') | ||
res = app.get(url, user=admin_user) | ||
res = res.click('Confirm') | ||
assert str(res.content).find("Confirm action") | ||
res = res.form.submit().follow() | ||
assert str(res.context['messages']._loaded_messages[0].message) == 'Successfully executed' |