Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit c02ecfa6833f148783cf4598d4c12c254382f4db @danirus committed Nov 7, 2012
@@ -0,0 +1,12 @@
+*.pyc
+*~
+*.*~
+*.zip
+*.egg-info
+*.db
+docs/_build
+build/
+dist/
+example/demo/media/cache/
+example/demo/static/
+example/demo/server-static/
@@ -0,0 +1 @@
+Daniel Rus Morales <mbox@danir.us>
23 LICENSE
@@ -0,0 +1,23 @@
+Copyright (c) 2011, Daniel Rus Morales
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,3 @@
+include AUTHORS
+include LICENSE
+recursive-include docs *
@@ -0,0 +1,22 @@
+Django-wysihtml5
+================
+
+By Daniel Rus Morales <http://danir.us/>
+
+* http://pypi.python.org/pypi/django-wysihtml5/
+* http://github.com/danirus/django-wysihtml5/
+
+Simple Django app that provides a Wysihtml5 rich text editor textarea widget.
+
+Includes a **demo project** and a **test suite**. If you commit code, please consider adding proper coverage (especially if it has a chance for a regression) in the test suite.
+
+Run the tests with: ``python setup.py test``
+
+
+Quick start
+===========
+
+1. Add ``wysihtml5`` to ``INSTALLED_APPS`` in your settings module.
+2. Create a model with a field of type ``Wysihtml5TextField``.
+3. Create an admin class for that model by inheriting from both ``wysihtml5.admin.AdminWysihtml5TextFieldMixin`` and Django's ``admin.ModelAdmin``.
+4. Hit your app's admin URL and see the `wysihtml5 <https://github.com/xing/wysihtml5>`_ editor in action.
No changes.
No changes.
@@ -0,0 +1,14 @@
+from django.contrib import admin
+from wysihtml5.admin import AdminWysihtml5TextFieldMixin
+from demo.articles.models import Article
+
+class ArticleAdmin(AdminWysihtml5TextFieldMixin, admin.ModelAdmin):
+ list_display = ('title', 'publish')
+ list_filter = ('publish',)
+ search_fields = ('title', 'abstract', 'body')
+ prepopulated_fields = {'slug': ('title',)}
+ fieldsets = ((None,
+ {'fields': ('title', 'slug', 'abstract', 'body',
+ 'publish',)}),)
+
+admin.site.register(Article, ArticleAdmin)
@@ -0,0 +1,39 @@
+from datetime import datetime
+
+from django.db import models
+from django.db.models import permalink
+
+from wysihtml5.fields import Wysihtml5TextField
+
+class PublicManager(models.Manager):
+ """Returns published articles that are not in the future."""
+
+ def published(self):
+ return self.get_query_set().filter(publish__lte=datetime.now())
+
+
+class Article(models.Model):
+ """Article, that accepts comments."""
+
+ title = models.CharField(max_length=200)
+ slug = models.SlugField(unique_for_date='publish')
+ abstract = models.TextField()
+ body = Wysihtml5TextField()
+ publish = models.DateTimeField(default=datetime.now)
+
+ objects = PublicManager()
+
+ class Meta:
+ db_table = 'demo_articles'
+ ordering = ('-publish',)
+
+ def __unicode__(self):
+ return u'%s' % self.title
+
+ @permalink
+ def get_absolute_url(self):
+ return ('articles-article-detail', None,
+ {'year': self.publish.year,
+ 'month': int(self.publish.strftime('%m').lower()),
+ 'day': self.publish.day,
+ 'slug': self.slug})
@@ -0,0 +1,15 @@
+from django.conf.urls.defaults import patterns, url
+from django.views.generic import ListView, DateDetailView
+
+from demo.articles.models import Article
+
+urlpatterns = patterns('',
+ url(r'^$',
+ ListView.as_view(queryset=Article.objects.published()),
+ name='articles-index'),
+
+ url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>[-\w]+)/$',
+ DateDetailView.as_view(model=Article, date_field="publish",
+ month_format="%m"),
+ name='articles-article-detail'),
+)
@@ -0,0 +1,4 @@
+python manage.py dumpdata --indent 4 --format json \
+ sites.Site \
+ auth.User \
+ articles.Article > initial_data.json
@@ -0,0 +1,39 @@
+[
+ {
+ "pk": 1,
+ "model": "sites.site",
+ "fields": {
+ "domain": "localhost:8000",
+ "name": "localhost:8000"
+ }
+ },
+ {
+ "pk": 1,
+ "model": "auth.user",
+ "fields": {
+ "username": "admin",
+ "first_name": "Administrator",
+ "last_name": "",
+ "is_active": true,
+ "is_superuser": true,
+ "is_staff": true,
+ "last_login": "2012-11-07T19:48:29.536",
+ "groups": [],
+ "user_permissions": [],
+ "password": "pbkdf2_sha256$10000$9tIx8DuB1nP5$Ak2t8EgR7Kwz1bWQ638v7S2aUQvxD2pmNcIH/vLILzA=",
+ "email": "admin@example.com",
+ "date_joined": "2012-01-12T10:49:55"
+ }
+ },
+ {
+ "pk": 1,
+ "model": "articles.article",
+ "fields": {
+ "body": "<h1 class=\"wysiwyg-text-align-center\">Introduction</h1><p class=\"wysiwyg-text-align-center\">Just the good ol' boys, never meanin' no harm. Beats all you've ever saw, been in trouble with the law since the day they was born. Straight'nin' the curve, flat'nin' the hills. Someday the mountain might get 'em, but the law never will. Makin' their way, the only way they know how, that's just a little bit more than the law will allow. Just good ol' boys, wouldn't change if they could, fightin' the system like a true modern day Robin Hood.</p>\r\n\r\n\r\n\r\n<h2 class=\"wysiwyg-text-align-center\">First Section</h2><p>An example list with colors:</p><ol><li>This is the <span class=\"wysiwyg-color-silver\"><b>silver</b></span>&nbsp;color</li><li>This is the <span class=\"wysiwyg-color-gray\"><b>gray</b></span> color</li><li>This is the <span class=\"wysiwyg-color-maroon\"><b>maroon</b></span> color</li><li>This is the <span class=\"wysiwyg-color-red\"><b>red</b></span> color</li><li>This is the <span class=\"wysiwyg-color-purple\"><b>purple</b></span> color</li><li>This is the <span class=\"wysiwyg-color-green\"><b>green</b></span> color</li><li>This is the <span class=\"wysiwyg-color-olive\"><b>olive</b></span> color</li><li>This is the <span class=\"wysiwyg-color-navy\"><b>navy</b></span> color</li><li>This is the <span class=\"wysiwyg-color-blue\"><b>blue</b></span> color</li></ol><h2 class=\"wysiwyg-text-align-center\">Second Section</h2>The following image has been inserted through the \"insertImage\" command provided with <a rel=\"nofollow\" target=\"_blank\" href=\"https://github.com/xing/wysihtml5\">Wysihtml5</a>:<br><br><div class=\"wysiwyg-text-align-center\"><img alt=\"\" src=\"http://mw2.google.com/mw-panoramio/photos/medium/64824025.jpg\"><br></div><p>That's the&nbsp;<b>Ordesa Valley</b>, in the Pyrenees, <i>Huesca</i>, <i>Spain</i>.&nbsp;The image is retrieved from&nbsp;<a rel=\"nofollow\" target=\"_blank\" href=\"http://www.panoramio.com/map\">Panoramio</a> by simple posting the URL in the \"insert link\" control. Install the app, get&nbsp;admin access and taste it. It's delicious!<br></p><h2 class=\"wysiwyg-text-align-center\">Section Three</h2>An example quote here:<br><blockquote>I don't know half of you half as well as I should like, and I like less than half of you half as well as you deserve.&nbsp;</blockquote><p class=\"wysiwyg-text-align-right\"><i><span class=\"wysiwyg-color-gray\">Bilbo Baggins</span></i></p>",
+ "abstract": "This is a Django example project using django-wysihtml5. The following text has been formatted using the rich-text editor Wysihtml5. Django-wysihtml5 offers a widget that converts a regular Textarea into a rich text editor based on Wysihtml5. The editor comes with a set of formatting commands available through a toolbar.",
+ "slug": "example-article",
+ "publish": "2012-11-06T21:04:03",
+ "title": "Example Article"
+ }
+ }
+]
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+import sys
+sys.path.insert(0, '../..') # parent of inline_media directory
+sys.path.insert(0, '..')
+
+import os
+os.environ["DJANGO_SETTINGS_MODULE"] = "demo.settings"
+
+from django.core.management import execute_manager
+import imp
+try:
+ imp.find_module('settings') # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
+ sys.exit(1)
+
+import settings
+
+if __name__ == "__main__":
+ execute_manager(settings)
@@ -0,0 +1,149 @@
+#-*- coding: utf-8 -*-
+
+import os
+
+PRJ_PATH = os.path.abspath(os.path.curdir)
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+THUMBNAIL_DEBUG = DEBUG
+
+ADMINS = (
+ ("Alice Bloggs", "alice@example.com"),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': "django.db.backends.sqlite3",
+ 'NAME': "wysihtml5_demo.db",
+ 'USER': "",
+ 'PASSWORD': "",
+ 'HOST': "",
+ 'PORT': "",
+ }
+}
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = "Europe/Brussels"
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = "en-us"
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = os.path.join(PRJ_PATH, "media")
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = "/media/"
+
+# Absolute path to the directory static files should be collected to.
+# Don't put anything in this directory yourself; store your static files
+# in apps' "static/" subdirectories and in STATICFILES_DIRS.
+# Example: "/home/media/media.lawrence.com/static/"
+STATIC_ROOT = os.path.join(PRJ_PATH, "server-static")
+
+# URL prefix for static files.
+# Example: "http://media.lawrence.com/static/"
+STATIC_URL = "/static/"
+
+# Additional locations of static files
+STATICFILES_DIRS = (
+ # Put strings here, like "/home/html/static" or "C:/www/django/static".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+# List of finder classes that know how to find static files in
+# various locations.
+STATICFILES_FINDERS = (
+ 'django.contrib.staticfiles.finders.FileSystemFinder',
+ 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
+)
+
+SECRET_KEY = "v2824l&2-n+4zznbsk9c-ap5i)b3e8b+%*a=dxqlahm^%)68jn"
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ "django.template.loaders.filesystem.Loader",
+ "django.template.loaders.app_directories.Loader",
+)
+
+MIDDLEWARE_CLASSES = (
+ "django.middleware.common.CommonMiddleware",
+ "django.contrib.sessions.middleware.SessionMiddleware",
+ "django.middleware.csrf.CsrfViewMiddleware",
+ "django.contrib.auth.middleware.AuthenticationMiddleware",
+ 'django.contrib.messages.middleware.MessageMiddleware',
+)
+
+ROOT_URLCONF = "urls"
+
+TEMPLATE_DIRS = (
+ os.path.join(os.path.dirname(__file__), "templates"),
+)
+
+INSTALLED_APPS = (
+ "django.contrib.auth",
+ "django.contrib.contenttypes",
+ "django.contrib.sessions",
+ "django.contrib.sites",
+ 'django.contrib.messages',
+ "django.contrib.staticfiles",
+ "django.contrib.admin",
+
+ "wysihtml5",
+ "articles",
+)
+
+# A sample logging configuration. The only tangible logging
+# performed by this configuration is to send an email to
+# the site admins on every HTTP 500 error.
+# See http://docs.djangoproject.com/en/dev/topics/logging for
+# more details on how to customize your logging configuration.
+LOGGING = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'formatters': {
+ 'simple': {
+ 'format': '%(levelname)s %(asctime)s %(module)s %(message)s'
+ }
+ },
+ 'handlers': {
+ 'mail_admins': {
+ 'level': 'ERROR',
+ 'class': 'django.utils.log.AdminEmailHandler'
+ },
+ 'console': {
+ 'level': 'INFO',
+ 'class': 'logging.StreamHandler',
+ 'formatter': 'simple'
+ }
+ },
+ 'loggers': {
+ 'django.request': {
+ 'handlers': ['mail_admins'],
+ 'level': 'ERROR',
+ 'propagate': True,
+ },
+ 'wysihtml5': {
+ 'handlers': ['console'],
+ 'level': 'INFO',
+ }
+ }
+}
@@ -0,0 +1,21 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block css %}
+<link href="{{ STATIC_URL }}wysihtml5/css/stylesheet.css" rel="Stylesheet">
+{% endblock %}
+
+{% block header %}{{ block.super }}{% trans "Article Detail" %}{% endblock %}
+
+{% block content %}
+<H2 style="text-align:center">{{ object.title }}</H2>
+<div style="width:540px; margin:10px auto; font-size:1.1em">
+ {{ object.abstract|safe }}
+</div>
+<div style="font-size:.8em; text-align:center; font-style:italic">Published {{ object.publish }}</div>
+<div style="width:640px; margin:10px auto">
+ {{ object.body|safe }}
+</div>
+
+<a href="{% url articles-index %}">{% trans "back to the articles list" %}</a>
+{% endblock %}
@@ -0,0 +1,20 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block header %}{{ block.super }}{% trans "Article List" %}{% endblock %}
+
+{% block content %}
+{% if object_list %}
+<UL>
+ {% for article in object_list %}
+ <li>
+ <a href="{{ article.get_absolute_url }}">{{ article.title }}</a>
+ <span style="font-size:0.8em">{{ article.publish|date:"d-F-Y" }}</span>
+ </li>
+{% endfor %}
+</UL>
+{% endif %}
+<p style="padding: 5px 15px; background:#ddd">
+ <a href="{% url homepage %}">{% trans "Home" %}</a>
+</p>
+{% endblock %}
Oops, something went wrong.

0 comments on commit c02ecfa

Please sign in to comment.