summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoretienne2009-12-03 20:14:54 +0000
committeretienne2009-12-03 20:14:54 +0000
commit25e778bebb1804aeaf0d7716119bcbfbe967e8b2 (patch)
tree422921259d8d4512c490f84a208ea3f11b924107
parent4182410b07eaff60effce203be0daaded3b0a8be (diff)
Add tinyMCE editor for description
-rw-r--r--polls/forms.py20
-rw-r--r--settings.py12
-rw-r--r--static/styles.css45
-rw-r--r--static/textareas.js27
-rw-r--r--templates/base.html1
-rw-r--r--templates/create.html5
-rw-r--r--templates/edit.html16
-rw-r--r--urls.py5
8 files changed, 119 insertions, 12 deletions
diff --git a/polls/forms.py b/polls/forms.py
index 732d206..f55db73 100644
--- a/polls/forms.py
+++ b/polls/forms.py
@@ -22,17 +22,24 @@ Forms management
'''
from django import forms
-from django.utils.translation import gettext_lazy as _
-from django.utils.html import escape
-from django.utils.safestring import mark_safe
-from django.forms.util import flatatt
+from django.contrib.admin import widgets as adminwidgets
from papillon.polls.models import Poll, Category
+from papillon import settings
+
+class TextareaWidget(forms.Textarea):
+ """
+ Manage the edition of a text using TinyMCE
+ """
+ class Media:
+ js = ["%stiny_mce.js" % settings.TINYMCE_URL,
+ "%stextareas.js" % settings.MEDIA_URL,]
+
class PollForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(PollForm, self).__init__(*args, **kwargs)
- self.fields['description'].widget = forms.widgets.Textarea()
+ self.fields['description'].widget = TextareaWidget()
class CreatePollForm(PollForm):
class Meta:
@@ -49,3 +56,6 @@ class AdminPollForm(PollForm):
'dated_choices', 'type']
if not Category.objects.all():
exclude.append('category')
+ def __init__(self, *args, **kwargs):
+ super(AdminPollForm, self).__init__(*args, **kwargs)
+ self.fields['enddate'].widget = adminwidgets.AdminSplitDateTime()
diff --git a/settings.py b/settings.py
index 081d7ca..85ae8c8 100644
--- a/settings.py
+++ b/settings.py
@@ -7,7 +7,11 @@ DEBUG = True
TEMPLATE_DEBUG = DEBUG
ROOT_PATH = '/var/local/django/papillon/'
-BASE_SITE = 'http://localhost:8000/papillon'
+SERVER_URL = 'http://localhost:8000/'
+EXTRA_URL = 'papillon/'
+BASE_SITE = SERVER_URL + EXTRA_URL
+
+TINYMCE_URL = 'http://localhost/tinymce/'
# time to live in days
DAYS_TO_LIVE = 30
@@ -44,16 +48,16 @@ USE_I18N = True
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = ROOT_PATH + 'media/'
+MEDIA_ROOT = ROOT_PATH + 'static/'
# URL that handles the media served from MEDIA_ROOT.
# Example: "http://media.lawrence.com"
-MEDIA_URL = BASE_SITE
+MEDIA_URL = BASE_SITE + 'static/'
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
-ADMIN_MEDIA_PREFIX = BASE_SITE + '/media/'
+ADMIN_MEDIA_PREFIX = BASE_SITE + 'media/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'replace_this_with_something_else'
diff --git a/static/styles.css b/static/styles.css
index 605fef3..c329905 100644
--- a/static/styles.css
+++ b/static/styles.css
@@ -168,6 +168,18 @@ width:160px;
height:100px;
}
+.datetime a img{
+border:0;
+}
+
+.datetime input.vTimeField{
+width:68px;
+}
+
+.datetime input.vDateField{
+width:75px;
+}
+
.form_description{
background-color:#6f819d;
color:white;
@@ -310,3 +322,36 @@ text-align:center;
.comments .submit{
width:auto;
}
+
+
+/* CALENDARS & CLOCKS IMPORTED FROM ADMIN */
+
+.calendarbox, .clockbox { margin: 5px auto; font-size: 11px; width: 16em; text-align: center; background: white; position: relative; border: 1px solid #444; }
+.clockbox { width: auto; }
+.clockbox h2 { margin: 0; font-size: 13px; border-bottom: 1px solid #222; padding: 3px; background-color: #EEE; }
+
+.calendar { margin: 0; padding: 0; }
+.calendar table { margin: 0; padding: 0; border-collapse: collapse; background: white; width: 100%; }
+.calendar caption, .calendarbox h2 { margin: 0; font-size: 12px; text-align: center; border-top: none; background-color: #EEE; }
+.calendar caption { height: 18px; font-weight: bold; }
+.calendar th { font-size: 10px; color: #666; padding: 2px 3px; text-align: center; background: #e1e1e1 url(../img/admin/nav-bg.gif) 0 50% repeat-x; border-bottom: 1px solid #ddd; }
+.calendar td { font-size: 11px; text-align: center; padding: 0; border-top: 1px solid #eee; border-bottom: none; }
+.calendar td.selected a { background: #C9DBED; }
+.calendar td.nonday { background: #efefef; }
+.calendar td.today a { background: #ffc; }
+.calendar td a, .timelist a { display: block; font-weight: bold; padding: 4px; text-decoration: none; color: #444; }
+.calendar td a:hover, .timelist a:hover { background: #4A0010; color: white; }
+.calendar td a:active, .timelist a:active { background: #CCC; color: white; }
+.calendarnav { font-size: 10px; text-align: center; color: #ccc; margin: 0; padding: 1px 3px; }
+.calendarnav a:link, #calendarnav a:visited, #calendarnav a:hover { color: #999; }
+.calendar-shortcuts { background: white; font-size: 10px; line-height: 11px; border-top: 1px solid #eee; padding: 3px 0 4px; color: #ccc; }
+.calendarbox .calendarnav-previous, .calendarbox .calendarnav-next { display: block; position: absolute; font-weight: bold; font-size: 12px; background: #AAA url(../img/admin/default-bg.gif) bottom left repeat-x; padding: 1px 4px 2px 4px; color: white; }
+.calendarnav-previous:hover, .calendarnav-next:hover { background: #4A0010; }
+.calendarnav-previous { top: 0; left: 0; }
+.calendarnav-next { top: 0; right: 0; }
+.calendar-cancel { margin: 0 !important; padding: 0; font-size: 10px; background: #e1e1e1 url(../img/admin/nav-bg.gif) 0 50% repeat-x; border-top: 1px solid #ddd; }
+.calendar-cancel a { padding: 2px; color: #999; }
+
+ul.timelist, .timelist li { list-style-type: none; margin: 0; padding: 0; }
+.timelist a { padding: 2px; }
+
diff --git a/static/textareas.js b/static/textareas.js
new file mode 100644
index 0000000..fec83b8
--- /dev/null
+++ b/static/textareas.js
@@ -0,0 +1,27 @@
+/* base function shared by some pages */
+/* Copyright (C) 2009 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as
+published by the Free Software Foundation, either version 3 of the
+License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+See the file COPYING for details.
+*/
+
+tinyMCE.init({
+ mode : "textareas",
+ theme : "advanced",
+ relative_urls : false,
+ theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,bullist,numlist,separator,hr,separator,link",
+ theme_advanced_buttons2 : "",
+ theme_advanced_buttons3 : ""
+});
diff --git a/templates/base.html b/templates/base.html
index ff30024..b66a341 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -4,6 +4,7 @@
<head>
<link rel="stylesheet" href="http://{{root_url}}static/styles.css" />
<title>{% block title %}Papillon{% endblock %}</title>
+ {% block fullscript %}{% endblock %}
</head>
<body>
diff --git a/templates/create.html b/templates/create.html
index 0b779db..7c3d2b3 100644
--- a/templates/create.html
+++ b/templates/create.html
@@ -2,6 +2,11 @@
{% load i18n %}
{% load markup %}
+{% block fullscript %}
+ {{ form.media }}
+{% endblock %}
+
+
{% block content %}
<h2>{% trans "New poll" %}</h2>
<form action="" method="post">
diff --git a/templates/edit.html b/templates/edit.html
index 9ddf138..c8b7d75 100644
--- a/templates/edit.html
+++ b/templates/edit.html
@@ -2,6 +2,13 @@
{% load markup %}
{% load i18n %}
+{% block fullscript %}
+<script type="text/javascript" src="http://{{root_url}}admin/jsi18n/"></script>
+<script type="text/javascript" src="http://{{root_url}}media/js/core.js"></script>
+<script type="text/javascript" src="http://{{root_url}}media/js/admin/RelatedObjectLookups.js"></script>
+{{ form.media }}
+{% endblock %}
+
{% block content %}
{% if not choices %}
<p class='error'>{% blocktrans %}As long as no options were added to the poll,
@@ -16,15 +23,18 @@ it will not be made available.{% endblocktrans %}</p>
<td>
<a href='http://{{root_url}}edit/{{poll.base_url}}'>http://{{root_url}}edit/{{poll.base_url}}</a>
</td>
- <td class='form_description'>
+ <td class='form_description'><p>
{% trans "Copy this address and send it to voters who want to participate to this poll" %}
- </td>
+ </p></td>
</tr>
<tr>
<td><label>{% trans "Administration url" %}</label></td>
<td>
<a href='http://{{root_url}}poll/{{poll.admin_url}}'>http://{{root_url}}poll/{{poll.admin_url}}</a>
- <td class='form_description'>{% trans "Address to modify the current poll" %}</td>
+ </td>
+ <td class='form_description'><p>
+ {% trans "Address to modify the current poll" %}
+ </p></td>
</tr>
{% for field in form %}
{% if field.is_hidden %}
diff --git a/urls.py b/urls.py
index dad8608..cc2852e 100644
--- a/urls.py
+++ b/urls.py
@@ -29,6 +29,8 @@ feeds = {
urlpatterns = patterns('',
(r'^papillon/admin/(.*)', admin.site.root),
+ (r'^papillon/admin/doc/', include('django.contrib.admindocs.urls')),
+ (r'^papillon/admin/jsi18n/$', 'django.views.i18n.javascript_catalog'),
(r'^papillon/$', 'papillon.polls.views.index'),
(r'^papillon/create$', 'papillon.polls.views.create'),
(r'^papillon/edit/(?P<admin_url>\w+)/$',
@@ -41,4 +43,7 @@ urlpatterns = patterns('',
'django.contrib.syndication.views.feed', {'feed_dict': feeds}),
(r'^papillon/static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': 'static/'}),
+ (r'^papillon/media/(?P<path>.*)$', 'django.views.static.serve',
+ {'document_root': 'media/'}),
+ (r'^papillon/tinymce/', include('tinymce.urls')),
)