Permalink
Browse files

added README, settings and default css styles

  • Loading branch information...
1 parent 9c22b43 commit 2dc2f422056399c7f47bdb634232f918d4c26379 @mmahnic committed Feb 15, 2011
View
@@ -0,0 +1,60 @@
+
+Django CMS plugin for creating simple tables using CSV
+======================================================
+
+Installation
+------------
+
+Add the plugin to the installed applications::
+
+ INSTALLED_APPS = (
+ # ...
+ 'cmsplugin_csvtable',
+ # ...
+
+ # migrations
+ 'south',
+ )
+
+
+Configuration
+-------------
+
+* CMSPLUGIN_CSVTABLE_WRAPPER_STYLES
+
+ A tuple with the styles for the table wrapper. Used mostly for alignment.
+ The default is::
+
+ CMSPLUGIN_CSVTABLE_WRAPPER_STYLES = (
+ ('ta-plain', _('Normal')),
+ ('ta-left', _('Align left')),
+ ('ta-right', _('Align right')),
+ ('ta-center', _('Centered')),
+ )
+
+* CMSPLUGIN_CSVTABLE_TABLE_STYLES
+
+ A tuple with the styles for the table. This defines the look of the table.
+ The default is::
+
+ CMSPLUGIN_CSVTABLE_TABLE_STYLES = (
+ ('ts-default', _('Default')),
+ ('ts-empty', _('Empty')),
+ ('ts-plain', _('Plain')),
+ )
+
+* CMSPLUGIN_CSVTABLE_TABLE_WIDTHS
+
+ A tuple with predefined widths for the table. Value 0 means Auto-Size,
+ other values widths in percent of the containing element. The default is::
+
+ CMSPLUGIN_CSVTABLE_TABLE_WIDTHS = (
+ (0, _('Auto')), (20, '20%'), (30, '30%'), (40, '40%'), (50, '50%'),
+ (60, '60%'), (70, '70%'), (80, '80%'), (90, '90%'), (100, '100%')
+ )
+
+CSS styles
+----------
+
+The default styles are defined in media/cmsplugin_csvtable/csvtable.scss.
+
@@ -0,0 +1,38 @@
+div.csvtable-wraper {
+ margin: 4px; }
+ div.csvtable-wraper .caption {
+ padding-top: 4px;
+ color: #4d4d4d; }
+ div.csvtable-wraper table.csvtable {
+ border-collapse: collapse; }
+ div.csvtable-wraper table.csvtable td, div.csvtable-wraper table.csvtable th {
+ border: 1px solid gray;
+ padding: 2px; }
+ div.csvtable-wraper table.ts-empty th {
+ border: none; }
+ div.csvtable-wraper table.ts-empty td {
+ border: none; }
+ div.csvtable-wraper table.ts-default th {
+ background: #cccccc;
+ border: 1px solid gray;
+ padding: 2px; }
+ div.csvtable-wraper table.ts-default td {
+ border: 1px solid gray;
+ padding: 2px; }
+ div.csvtable-wraper table.ts-default .even {
+ background: #e6e6e6; }
+ div.csvtable-wraper table.ts-default .odd {
+ background: white; }
+
+div.ta-left {
+ display: inline;
+ float: left;
+ margin: 0.5em 1em 1em 4px; }
+
+div.ta-right {
+ display: inline;
+ float: right;
+ margin: 0.5em 4px 1em 1em; }
+
+div.ta-center {
+ margin: 0.5em auto 1em auto; }
@@ -0,0 +1,81 @@
+
+$doc-back-color: #ffffff;
+$doc-color: #000000;
+$csv-table-caption-color: lighten($doc-color, 30%);
+$csv-row-back-head: darken($doc-back-color, 20%);
+$csv-row-back-odd: $doc-back-color;
+$csv-row-back-even: darken($doc-back-color, 10%);
+$csv-table-border-color: lighten($doc-color, 50%);
+
+// Table wrapper: table + caption
+div.csvtable-wraper {
+ margin: 4px;
+
+ .caption {
+ padding-top: 4px;
+ color: $csv-table-caption-color;
+ }
+ // .ts-default-caption { padding-top: 4px; background: #d5d5d5; color: $button-back-color; }
+
+ // Default table formatting
+ table.csvtable {
+ border-collapse: collapse;
+ td, th {
+ border: 1px solid $csv-table-border-color;
+ padding: 2px;
+ }
+ }
+
+ // User-selectable styles of the table (registered in settings)
+
+ // Table style: Plain
+ table.ts-plain {
+ }
+
+ // Table style: Empty
+ table.ts-empty {
+ th {
+ border: none;
+ }
+ td {
+ border: none;
+ }
+ }
+
+ // Table style: Default
+ table.ts-default {
+ th {
+ background: $csv-row-back-head;
+ border: 1px solid $csv-table-border-color;
+ padding: 2px;
+ }
+ td {
+ border: 1px solid $csv-table-border-color;
+ padding: 2px;
+ }
+ .even {
+ background: $csv-row-back-even;
+ }
+ .odd {
+ background: $csv-row-back-odd;
+ }
+ }
+}
+
+// Alignment styles for the wrapper
+div.ta-plain {}
+div.ta-left {
+ display: inline;
+ float: left;
+ margin: 0.5em 1em 1em 4px;
+}
+div.ta-right {
+ display: inline;
+ float: right;
+ margin: 0.5em 4px 1em 1em;
+}
+div.ta-center {
+ margin: 0.5em auto 1em auto;
+}
+
+// vim:set fileencoding=utf-8 sw=3 ts=8 et:vim
@@ -0,0 +1,13 @@
+#!/bin/bash -
+
+target="csvtable.css"
+while true; do
+ for fin in *.scss; do
+ if [ $fin -nt $target ]; then
+ sass --no-cache csvtable.scss $target
+ echo "$(date): $target updated."
+ break
+ fi
+ done
+ sleep 1
+done
@@ -3,59 +3,43 @@
# Author: Marko Mahnič
# Created: mar 2010
-import csv
-
from django.utils.translation import ugettext_lazy as _
from django.db import models
-from django.conf import settings
-
from cms.models import CMSPlugin
-
-TMP = getattr(settings, "CMSPLUGIN_CSVTABLE_WRAPPER_STYLES", (
- ('ta-plain', 'Normal'),
- ('ta-left', 'Align left'),
- ('ta-right', 'Align right'),
- ('ta-center', 'Centered'),
-))
-CMSPLUGIN_CSVTABLE_WRAPPER_STYLES = tuple( (item[0], _(item[1])) for item in TMP)
-
-TMP = getattr(settings, "CMSPLUGIN_CSVTABLE_TABLE_STYLES", (
- ('ts-default', 'Default'),
-))
-CMSPLUGIN_CSVTABLE_TABLE_STYLES = tuple( (item[0], _(item[1])) for item in TMP)
-
-CMSPLUGIN_CSVTABLE_TABLE_WIDTHS = (
- (0, _('Auto')), (20, '20%'), (30, '30%'), (40, '40%'), (50, '50%'),
- (60, '60%'), (70, '70%'), (80, '80%'), (90, '90%'), (100, '100%')
-)
+import settings
+import csv
class CsvCell:
def __init__(self, content, row, order):
self.content = content
self.row = row
self.odrer = order
+
class CsvRow:
def __init__(self, number, columns):
self.odd = number % 2 != 0
self.cells = [CsvCell(c, self, ic) for ic,c in enumerate(columns)]
-# Derived from CMSPlugin => doesn't exist outside of a page
+
class CsvTablePlugin(CMSPlugin):
caption = models.CharField(_('Caption'), max_length=200, blank=True)
headrows = models.IntegerField(_('Header rows'), default=1)
#columns = models.CharField(_('Column layout'), max_length=200, blank=True
# help_text=_(
- # 'Describe the column width and alignment in a comma separated list.\n' +
+ # 'TODO Describe the column width and alignment in a comma separated list.\n' +
# 'Value: 5>,3,10< means: '
# 'column 1 is 5 units wide and right aligned, ' +
# 'column 2 is 3 units wide and centered, ' +
# 'column 3 is 10 units wide and left aligned.'
# ))
csv_data = models.TextField(_('CSV Data'))
- width = models.IntegerField(_('Table width'), choices=CMSPLUGIN_CSVTABLE_TABLE_WIDTHS, default=40)
- table_css = models.CharField(_('Table style'), choices=CMSPLUGIN_CSVTABLE_TABLE_STYLES, max_length=20, blank=True)
- wrapper_css = models.CharField(_('Table placement'), choices=CMSPLUGIN_CSVTABLE_WRAPPER_STYLES, max_length=20, blank=True)
+ width = models.IntegerField(_('Table width'), default=40,
+ choices=settings.CMSPLUGIN_CSVTABLE_TABLE_WIDTHS)
+ table_css = models.CharField(_('Table style'), max_length=20, blank=True,
+ choices=settings.CMSPLUGIN_CSVTABLE_TABLE_STYLES)
+ wrapper_css = models.CharField(_('Table placement'), max_length=20, blank=True,
+ choices=settings.CMSPLUGIN_CSVTABLE_WRAPPER_STYLES)
def __unicode__(self):
return u'%s' % (self.caption)
@@ -0,0 +1,22 @@
+
+from django.conf import settings as django_settings
+from django.utils.translation import ugettext_lazy as _
+
+CMSPLUGIN_CSVTABLE_WRAPPER_STYLES = getattr(django_settings, "CMSPLUGIN_CSVTABLE_WRAPPER_STYLES", (
+ ('ta-plain', _('Normal')),
+ ('ta-left', _('Align left')),
+ ('ta-right', _('Align right')),
+ ('ta-center', _('Centered')),
+))
+
+CMSPLUGIN_CSVTABLE_TABLE_STYLES = getattr(django_settings, "CMSPLUGIN_CSVTABLE_TABLE_STYLES", (
+ ('ts-default', _('Default')),
+ ('ts-empty', _('Empty')),
+ ('ts-plain', _('Plain')),
+))
+
+CMSPLUGIN_CSVTABLE_TABLE_WIDTHS = (
+ (0, _('Auto')), (20, '20%'), (30, '30%'), (40, '40%'), (50, '50%'),
+ (60, '60%'), (70, '70%'), (80, '80%'), (90, '90%'), (100, '100%')
+)
+

0 comments on commit 2dc2f42

Please sign in to comment.