为Jango管理颜色框弹出菜单

apidev-coop_colorbox的Python项目详细描述


coop colorbox,使jquery.colorbox在django应用程序中易于使用

安装

管道:

pip install apidev_coop-colorbox

设置

在settings.py中:

INSTALLED_APPS = (
    '...',
    'colorbox',
)

视图

视图:

from django.utils.decorators import method_decorator
from django.http import HttpResponseRedirect, Http404

from colorbox.decorators import popup_redirect
class MyView(FormView):
    """edit the profile of the current user"""
    template_name = "form_popup_template.html"

    @method_decorator(popup_redirect)
    def dispatch(self, request, *args, **kwargs):
        """Manage close of the colorbox popup"""
        self.user = request.user
        return super(EditProfileView, self).dispatch(request, *args, **kwargs)

    def get_form_class(self):
        """returns the form class to use"""
        return MyForm

    def form_valid(self, form):
        form.save()
        return HttpResponseRedirect(reverse(’next_step'))

表单弹出模板

模板:

{% extends "colorbox/popup_form_base.html" %}
{% load i18n %}
{% block title %}{% trans "Edit" %}{% endblock %}
{% block form_url %}{% url 'my_view' %}{% endblock %}

您还可以重写或扩展{%block form{u intro%}{%block form{u fields%}`{%block popup_buttons%}{%block extra_head%}

主模板

模板:

{% load static i18n %}
<script type="text/javascript" charset="utf-8" src="{% static 'js/jquery.colorbox-min.js' %}"></script>
<script type="text/javascript" charset="utf-8" src="{% static 'js/jquery.form.js' %}"></script>
<script type="text/javascript" src="{% static 'js/colorbox.coop.js' %}"></script>
<link rel="stylesheet" href="{% static 'css/colorbox.css' %}" type="text/css" />
<script>
  $(function () {
    // activate popups
    $("a.colorbox-form").colorboxify();
  });
</script>
<a class="colorbox-form" href="{% url 'my_view' %}">{% trans "Edit" %}</a>

在测试中

测试:

from colorbox.utils import assert_popup_redirects
assert_popup_redirects(response, reverse('my_view'))

许可证

coop colorbox使用bsd许可证请参见license.txt

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Spring框架服务单元测试   在Java中遍历hashmaps的hashmap以检索字符串值   如何使用CodeQL检查Java注释是否具有特定属性?   java为什么在Spring Boot中访问此资源而不是登录弹出窗口需要始终获得完全身份验证   处理将多集计数转换为列表的过程   java另一个线性布局,没有出现按钮   eclipse Java映像加载未显示在jar中   java Junit类无法加载基本测试类ApplicationContext   java如何在main中使用my getvalues()方法打印列表   java Sonar,S128:切换案例应该以无条件的“中断”语句结束,而不是继续   java从socket读取字符串错误连接重置错误   java使用新数据刷新任意图表饼图   java通过异步运行lambda访问方法参数   java错误的结果一旦我处理try and catch