Wiking branch, master, updated. 2826e78c89c43d9a9bdf44372ddc84dffb177864
Tomas Cerha
cerha at devel.brailcom.org
Fri Nov 4 17:19:48 CET 2011
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Wiking".
The branch, master has been updated
via 2826e78c89c43d9a9bdf44372ddc84dffb177864 (commit)
via edacfc9b08b1852426122cb069417a29298dfee3 (commit)
from ac9b74c314a6a08701c8b65add994a1ba6104d88 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 2826e78c89c43d9a9bdf44372ddc84dffb177864
Author: Tomas Cerha <cerha at brailcom.org>
Date: Fri Nov 4 16:55:34 2011 +0100
Remove obsolete image attachemnt support
commit edacfc9b08b1852426122cb069417a29298dfee3
Author: Tomas Cerha <cerha at brailcom.org>
Date: Fri Nov 4 16:54:44 2011 +0100
Add an explicit checkbox for image gallery inclusion
-----------------------------------------------------------------------
Summary of changes:
lib/wiking/cms/cms.py | 230 ++++++++------------------------
sql/{upgrade.25.sql => upgrade.26.sql} | 55 ++++----
sql/wiking.sql | 57 +++-----
3 files changed, 108 insertions(+), 234 deletions(-)
copy sql/{upgrade.25.sql => upgrade.26.sql} (64%)
diff --git a/lib/wiking/cms/cms.py b/lib/wiking/cms/cms.py
index 302a026..138690e 100644
--- a/lib/wiking/cms/cms.py
+++ b/lib/wiking/cms/cms.py
@@ -1402,6 +1402,7 @@ class Pages(ContentManagementModule):
content = [lcg.Container(sections)]
# Attachment list
resources = []
+ gallery_images = []
attachments_list = []
attachment_base_uri = '/'+ record['identifier'].export() + '/attachments'
needs_lightbox = False
@@ -1412,15 +1413,19 @@ class Pages(ContentManagementModule):
if a.mime_type.startswith('image/'):
cls = lcg.Image
if a.thumbnail_size:
- thumbnail = lcg.Image(a.filename,
- uri=req.make_uri(attachment_base_uri+'/'+a.filename,
- action='thumbnail'),
+ thumbnail_uri = req.make_uri(attachment_base_uri+'/'+a.filename,
+ action='thumbnail')
+ thumbnail = lcg.Image(a.filename, uri=thumbnail_uri,
title=a.title, descr=a.descr,
size=(a.thumbnail_width, a.thumbnail_height),
)
kwargs['thumbnail'] = thumbnail
needs_lightbox = True
uri = req.make_uri(attachment_base_uri+'/'+a.filename, action='image')
+ else:
+ thumbnail_uri = None
+ if a.in_gallery:
+ gallery_images.append((a, uri, thumbnail_uri))
elif a.filename.lower().endswith('mp3'):
cls = lcg.Audio
elif a.filename.lower().endswith('flv'):
@@ -1440,6 +1445,8 @@ class Pages(ContentManagementModule):
lcg.Script('scriptaculous.js'),
lcg.Script('lightbox.js'),
lcg.Stylesheet('lightbox.css')))
+ if gallery_images:
+ content.append(Attachments.ImageGallery(gallery_images))
if attachments_list:
# Translators: Section title. Attachments as in email attachments.
content.append(lcg.Section(title=_("Attachments"), content=lcg.ul(attachments_list),
@@ -1604,8 +1611,8 @@ class Attachments(ContentManagementModule):
computer=computer(lambda r, file: file and pp.format_byte_size(len(file)))),
Field('thumbnail', '', type=pd.Image(), computer=computer(self._thumbnail)),
# Translators: Thumbnail is a small image preview in computer terminology.
- Field('thumbnail_size', _("Preview size"),
- enumerator=enum(('small', 'medium', 'large')), not_null=False,
+ Field('thumbnail_size', _("Preview size"), not_null=False,
+ enumerator=enum(('small', 'medium', 'large')), default='medium',
display=self._thumbnail_size_display, prefer_display=True,
null_display=_("Full size (don't resize)"),
selection_type=pp.SelectionType.RADIO,
@@ -1619,12 +1626,19 @@ class Attachments(ContentManagementModule):
Field('thumbnail_width', computer=computer(self._thumbnail_width)),
Field('thumbnail_height', computer=computer(self._thumbnail_height)),
Field('image', type=pd.Image(), computer=computer(self._image)),
+ Field('in_gallery', _("In Gallery"),
+ #editable=computer(lambda r, thumbnail_size: thumbnail_size is not None),
+ # The computer doesn't work (probably a PresentedRow issue?).
+ #computer=computer(lambda r, thumbnail_size: thumbnail_size is not None),
+ descr=_("Check if you want the image to appear in an image Gallery "
+ "below the page text.")),
Field('listed', _("Listed"), default=True,
descr=_("Check if you want the item to appear in the listing of attachments at "
"the bottom of the page.")),
- Field('is_image'),
- Field('_filename', virtual=True,
- computer=self._filename_computer()),
+ #Field('author', _("Author"), width=30),
+ #Field('location', _("Location"), width=50),
+ #Field('exif_date', _("EXIF date"), type=DateTime()),
+ Field('_filename', virtual=True, computer=computer(self._filename)),
)
def _ext(self, record, filename):
if filename is None:
@@ -1680,12 +1694,9 @@ class Attachments(ContentManagementModule):
return thumbnail.image().size[1]
else:
return None
- def _filename_computer(self, append=''):
- """Return a computer computing filename for storing the file."""
- def func(record, attachment_id, ext):
- fname = str(attachment_id) + append + '.' + ext
- return os.path.join(cfg.storage, cfg.dbname, self.table, fname)
- return computer(func)
+ def _filename(self, record, attachment_id, ext):
+ fname = str(attachment_id) +'.'+ ext
+ return os.path.join(cfg.storage, cfg.dbname, self.table, fname)
def _thumbnail_size_display(self, size):
# Translators: Size label related to "Preview size" field (pronoun).
labels = {'small': _("Small") + " (%dpx)" % cfg.image_thumbnail_sizes[0],
@@ -1693,12 +1704,32 @@ class Attachments(ContentManagementModule):
'large': _("Large") + " (%dpx)" % cfg.image_thumbnail_sizes[2]}
return labels.get(size, size)
- def redirect(self, req, record):
- return record and record['is_image'].value() and 'Images' or None
- layout = ('file', 'title', 'description', 'thumbnail_size' , 'listed')
- columns = ('filename', 'title', 'bytesize', 'mime_type', 'thumbnail_size', 'listed', 'mapping_id')
+ layout = ('file', 'title', 'description', 'thumbnail_size' , 'in_gallery', 'listed')
+ columns = ('filename', 'title', 'bytesize', 'mime_type', 'thumbnail_size', 'in_gallery', 'listed', 'mapping_id')
sorting = (('filename', ASC),)
+ class ImageGallery(lcg.Content):
+
+ def __init__(self, attachments):
+ self._attachments = attachments
+ super(Attachments.ImageGallery, self).__init__()
+
+ def _export_item(self, context, a, uri, thumbnail_uri):
+ g = context.generator()
+ title = a.title
+ if a.descr:
+ title += ': '+ a.descr
+ if thumbnail_uri:
+ img = g.img(thumbnail_uri, width=a.thumbnail_width, height=a.thumbnail_height)
+ return g.a(img, href=uri, rel='lightbox[gallery]', title=title)
+ else:
+ return g.img(uri)
+
+ def export(self, context):
+ g = context.generator()
+ content = [self._export_item(context, *args) for args in self._attachments]
+ return g.div(content, cls='wiking-image-gallery')
+
class Attachment(object):
def __init__(self, row):
self.filename = filename = row['filename'].export()
@@ -1710,6 +1741,7 @@ class Attachments(ContentManagementModule):
self.thumbnail_width = row['thumbnail_width'].value()
self.thumbnail_height = row['thumbnail_height'].value()
self.mime_type = row['mime_type'].value()
+ self.in_gallery = row['in_gallery'].value()
_ACTIONS = (
#Action(_("New image"), 'insert_image', descr=_("Insert a new image attachment"),
@@ -1717,7 +1749,6 @@ class Attachments(ContentManagementModule):
# Translators: Button label
Action(_("Move"), 'move', descr=_("Move the attachment to another page.")),
)
- _STORED_FIELDS = (('file', '_filename'),) # Define which fields are stored as files.
_INSERT_LABEL = _("New attachment")
_REFERER = 'filename'
_LAYOUT = {'move': ('mapping_id',)}
@@ -1766,20 +1797,19 @@ class Attachments(ContentManagementModule):
def _save_files(self, record):
if not os.path.exists(cfg.storage) \
- or not os.access(cfg.storage, os.W_OK):
+ or not os.access(cfg.storage, os.W_OK):
import getpass
raise Exception("The configuration option 'storage' points to '%(dir)s', but this "
"directory does not exist or is not writable by user '%(user)s'." %
dict(dir=cfg.storage, user=getpass.getuser()))
- for id, filename_id in self._STORED_FIELDS:
- fname = record[filename_id].value()
- dir = os.path.split(fname)[0]
- if not os.path.exists(dir):
- os.makedirs(dir, 0700)
- buf = record[id].value()
- if buf is not None:
- log(OPR, "Saving file:", (fname, pp.format_byte_size(len(buf))))
- buf.save(fname)
+ fname = record['_filename'].value()
+ dir = os.path.split(fname)[0]
+ if not os.path.exists(dir):
+ os.makedirs(dir, 0700)
+ buf = record['file'].value()
+ if buf is not None:
+ log(OPR, "Saving file:", (fname, pp.format_byte_size(len(buf))))
+ buf.save(fname)
def _insert_transaction(self, req, record):
return self._transaction()
@@ -1842,148 +1872,6 @@ class Attachments(ContentManagementModule):
else:
return ('image/%s' % value.image().format.lower(), str(value.buffer()))
RIGHTS_image = (Roles.ANYONE)
-
-
-class ImageGallery(Module, Embeddable):
- """Extend page content by including a gallery of images present within attachments."""
-
- _TITLE = _("Image Gallery")
-
- class Gallery(lcg.Content):
- def export(self, context):
- g = context.generator()
- req = context.req()
- page = req.page
- context.resource('prototype.js')
- context.resource('scriptaculous.js')
- context.resource('lightbox.js')
- context.resource('lightbox.css')
- base_uri = '/'+ page['identifier'].export() + '/attachments'
- content = [self._export_item(context, base_uri, a)
- for a in wiking.module('Attachments').attachments(req,
- page['mapping_id'].value(),
- page['lang'].value())
- if a.mime_type.startswith('image/') and a.thumbnail_size is not None]
- return g.div(content, cls='wiking-image-gallery')
-
- def _export_item(self, context, base_uri, a):
- g = context.generator()
- req = context.req()
- uri = base_uri +'/'+ a.filename
- img = g.img(req.make_uri(uri, action='thumbnail'),
- width=a.thumbnail_width, height=a.thumbnail_height)
- title = a.title
- if a.descr:
- title += ': '+ a.descr
- return g.a(img, href=req.make_uri(uri, action='image'), rel='lightbox[gallery]',
- title=title)
-
- def embed(self, req):
- return [self.Gallery()]
-
-
-class Images(Attachments):
- class Spec(Attachments.Spec):
- table = 'attachments'
- def fields(self):
- overridde = (
- Field('title',
- descr=_("Image title. If empty, the file name will be used instead.")),
- Field('description', maxlen=512,
- descr=_("Optional image description.")),
- Field('listed', _("In galery"),
- descr=_("Check if you want the image to appear an automatically generated "
- "galery.")),
- Field('is_image', default=True),
- )
- extra = (
- Field('image', virtual=True, editable=ALWAYS, computer=computer(self._image),
- type=pd.Image(maxsize=(3000, 3000))),
- #Field('resized', virtual=True, editable=ALWAYS, type=pd.Image(),
- # computer=self._resize_computer('resized', '_resized_filename', (800, 800))),
- #Field('thumbnail', virtual=True, type=pd.Image(),
- # computer=self._resize_computer('thumbnail', '_thumbnail_filename', (130, 130))),
- Field('author', _("Author"), width=30),
- Field('location', _("Location"), width=50),
- Field('width', _("Width"),
- computer=computer(lambda r, image: image and image.size[0])),
- Field('height', _("Height"),
- computer=computer(lambda r, image: image and image.size[1])),
- #Field('size', _("Pixel size"), virtual=True,
- # computer=computer(lambda r, width, height:
- # width is not None and '%dx%d' % (width, height))),
- #Field('exif_date', _("EXIF date"), type=DateTime()),
- #Field('exif'),
- Field('_thumbnail_filename', virtual=True,
- computer=self._filename_computer('-thumbnail')),
- Field('_resized_filename', virtual=True,
- computer=self._filename_computer('-resized')),
- )
- return self._inherited_fields(Images, override=overridde) + extra
- def _image(self, record):
- # Use lazy get to prevent running the computer (to find out, whether a new file was
- # uploaded and prevent loading the previously saved file in that case).
- file = record.get('file', lazy=True).value()
- if file is not None and file.path() is None:
- log(OPR, "Loading image:", len(file))
- import PIL.Image
- stream = cStringIO.StringIO(file.buffer())
- try:
- image = PIL.Image.open(stream)
- except IOError:
- return None
- else:
- return image
- return None
- def _resize_computer(self, cid, filename, size):
- """Return a computer loading field value from file."""
- def func(record):
- value = record[cid]
- result = value.value()
- if result is not None:
- return result
- else:
- img = copy.copy(record['image'].value())
- if img:
- # Recompute the value by resizing the original image.
- from PIL.Image import ANTIALIAS
- log(OPR, "Resizing image:", (img.size, size))
- img.thumbnail(size, ANTIALIAS)
- stream = cStringIO.StringIO()
- img.save(stream, img.format)
- return pd.Image.Buffer(buffer(stream.getvalue()))
- elif not record.new():
- #log(OPR, "Loading file:", record[filename].value())
- return value.type().Buffer(record[filename].value(),
- type=str(record['mime_type'].value()))
- return result
- return computer(func)
- layout = ('file', 'title', 'description', 'author', 'location', 'listed')
-
- _STORED_FIELDS = (('file', '_filename'),
- ('resized', '_resized_filename'),
- ('thumbnail', '_thumbnail_filename')
- )
- _INSERT_LABEL = _("New attachment")
-
- def _binding_forward(self, req):
- # HACK: This module is always accessed through redirect in Attachments, but the parent
- # method does not take that into account.
- for fw in reversed(req.forwards()):
- if fw.arg('binding') is not None:
- if fw.module().name() == 'Attachments':
- return fw
- else:
- return None
- return None
-
- #def action_resized(self, req, record):
- # return (str(record['mime_type'].value()), record['resized'].value().buffer())
- #RIGHTS_resized = (Roles.ANYONE,)
-
- #def action_thumbnail(self, req, record):
- # return (str(record['mime_type'].value()), record['thumbnail'].value().buffer())
- #RIGHTS_thumbnail = (Roles.ANYONE,)
class News(ContentManagementModule, EmbeddableCMSModule):
diff --git a/sql/upgrade.25.sql b/sql/upgrade.26.sql
similarity index 64%
copy from sql/upgrade.25.sql
copy to sql/upgrade.26.sql
index 48028ca..6803ea3 100644
--- a/sql/upgrade.25.sql
+++ b/sql/upgrade.26.sql
@@ -1,43 +1,41 @@
-alter table _attachments add column image bytea;
-alter table _attachments add column thumbnail bytea;
-alter table _attachments add column thumbnail_size text;
-alter table _attachments add column thumbnail_width int;
-alter table _attachments add column thumbnail_height int;
-
drop view attachments;
+drop table _images;
+alter table _attachments drop column "timestamp";
+alter table _attachments add column in_gallery boolean not null default false;
+alter table _attachments add column author text;
+alter table _attachments add column "location" text;
+alter table _attachments add column width int;
+alter table _attachments add column height int;
+alter table _attachments add column "timestamp" timestamp;
create or replace view attachments
as select a.attachment_id ||'.'|| l.lang as attachment_variant_id, l.lang,
- a.attachment_id, a.mapping_id, a.filename, a.mime_type, a.bytesize,
+ a.attachment_id, a.mapping_id, d.title, d.description,
+ a.filename, a.mime_type, a.bytesize,
a.image, a.thumbnail, a.thumbnail_size, a.thumbnail_width, a.thumbnail_height,
- a.listed, a."timestamp", d.title, d.description, i.width is not null as is_image,
- i.width, i.height, i.author, i."location", i.exif_date, i.exif
+ a.in_gallery, a.listed, a.author, a."location", a.width, a.height, a."timestamp"
from _attachments a JOIN _mapping m using (mapping_id) cross join languages l
- left outer join _attachment_descr d using (attachment_id, lang)
- left outer join _images i using (attachment_id);
+ left outer join _attachment_descr d using (attachment_id, lang);
create or replace rule attachments_insert as
on insert to attachments do instead (
insert into _attachment_descr (attachment_id, lang, title, description)
select new.attachment_id, new.lang, new.title, new.description
where new.title IS not null OR new.description IS not null;
- insert into _images (attachment_id, width, height, author, "location", exif_date, exif)
- select new.attachment_id, new.width, new.height, new.author, new."location",
- new.exif_date, new.exif
- where new.is_image;
- insert into _attachments (attachment_id, mapping_id, filename, mime_type, bytesize,
+ insert into _attachments (attachment_id, mapping_id, filename, mime_type, bytesize,
image, thumbnail, thumbnail_size, thumbnail_width, thumbnail_height,
- listed)
+ in_gallery, listed, author, "location", width, height, "timestamp")
VALUES (new.attachment_id, new.mapping_id, new.filename, new.mime_type,
new.bytesize, new.image, new.thumbnail, new.thumbnail_size,
- new.thumbnail_width, new.thumbnail_height, new.listed)
+ new.thumbnail_width, new.thumbnail_height, new.in_gallery, new.listed,
+ new.author, new."location", new.width, new.height, new."timestamp")
returning
attachment_id ||'.'|| (select max(lang) from _attachment_descr
where attachment_id=attachment_id), NULL::char(2),
- attachment_id, mapping_id, filename, mime_type, bytesize, image,
- thumbnail, thumbnail_size, thumbnail_width, thumbnail_height, listed,
- "timestamp", NULL::text, NULL::text, NULL::boolean, NULL::int,
- NULL::int, NULL::text, NULL::text, NULL::timestamp, NULL::text
+ attachment_id, mapping_id, NULL::text, NULL::text,
+ filename, mime_type, bytesize, image, thumbnail,
+ thumbnail_size, thumbnail_width, thumbnail_height, in_gallery, listed,
+ author, "location", width, height, "timestamp"
);
create or replace rule attachments_update as
@@ -52,15 +50,13 @@ create or replace rule attachments_update as
thumbnail_size = new.thumbnail_size,
thumbnail_width = new.thumbnail_width,
thumbnail_height = new.thumbnail_height,
- listed = new.listed
- where attachment_id = old.attachment_id;
- UPDATE _images SET
- width = new.width,
- height = new.height,
+ listed = new.listed,
+ in_gallery = new.in_gallery,
author = new.author,
"location" = new."location",
- exif_date = new.exif_date,
- exif = new.exif
+ width = new.width,
+ height = new.height,
+ "timestamp" = new."timestamp"
where attachment_id = old.attachment_id;
UPDATE _attachment_descr SET title=new.title, description=new.description
where attachment_id = old.attachment_id and lang = old.lang;
@@ -74,3 +70,4 @@ create or replace rule attachments_delete as
on delete to attachments do instead (
delete from _attachments where attachment_id = old.attachment_id;
);
+
diff --git a/sql/wiking.sql b/sql/wiking.sql
index fee0a4f..94fbda5 100644
--- a/sql/wiking.sql
+++ b/sql/wiking.sql
@@ -250,8 +250,13 @@ create table _attachments (
thumbnail_size text, -- desired size - small/medium/large
thumbnail_width int, -- the actual pixel width of the thumbnail
thumbnail_height int, -- the actual pixel height of the thumbnail
+ in_gallery boolean not null default false,
listed boolean not null default true,
- "timestamp" timestamp not null default now(),
+ author text,
+ "location" text,
+ width int,
+ height int,
+ "timestamp" timestamp,
unique (mapping_id, filename)
);
@@ -263,48 +268,34 @@ create table _attachment_descr (
unique (attachment_id, lang)
);
-create table _images (
- attachment_id int not null references _attachments on delete cascade initially deferred,
- width int not null,
- height int not null,
- author text,
- "location" text,
- exif_date timestamp,
- exif text
-);
-
create or replace view attachments
as select a.attachment_id ||'.'|| l.lang as attachment_variant_id, l.lang,
- a.attachment_id, a.mapping_id, a.filename, a.mime_type, a.bytesize,
+ a.attachment_id, a.mapping_id, d.title, d.description,
+ a.filename, a.mime_type, a.bytesize,
a.image, a.thumbnail, a.thumbnail_size, a.thumbnail_width, a.thumbnail_height,
- a.listed, a."timestamp", d.title, d.description, i.width is not null as is_image,
- i.width, i.height, i.author, i."location", i.exif_date, i.exif
+ a.in_gallery, a.listed, a.author, a."location", a.width, a.height, a."timestamp"
from _attachments a JOIN _mapping m using (mapping_id) cross join languages l
- left outer join _attachment_descr d using (attachment_id, lang)
- left outer join _images i using (attachment_id);
+ left outer join _attachment_descr d using (attachment_id, lang);
create or replace rule attachments_insert as
on insert to attachments do instead (
insert into _attachment_descr (attachment_id, lang, title, description)
select new.attachment_id, new.lang, new.title, new.description
where new.title IS not null OR new.description IS not null;
- insert into _images (attachment_id, width, height, author, "location", exif_date, exif)
- select new.attachment_id, new.width, new.height, new.author, new."location",
- new.exif_date, new.exif
- where new.is_image;
- insert into _attachments (attachment_id, mapping_id, filename, mime_type, bytesize,
+ insert into _attachments (attachment_id, mapping_id, filename, mime_type, bytesize,
image, thumbnail, thumbnail_size, thumbnail_width, thumbnail_height,
- listed)
+ in_gallery, listed, author, "location", width, height, "timestamp")
VALUES (new.attachment_id, new.mapping_id, new.filename, new.mime_type,
new.bytesize, new.image, new.thumbnail, new.thumbnail_size,
- new.thumbnail_width, new.thumbnail_height, new.listed)
+ new.thumbnail_width, new.thumbnail_height, new.in_gallery, new.listed,
+ new.author, new."location", new.width, new.height, new."timestamp")
returning
attachment_id ||'.'|| (select max(lang) from _attachment_descr
where attachment_id=attachment_id), NULL::char(2),
- attachment_id, mapping_id, filename, mime_type, bytesize, image,
- thumbnail, thumbnail_size, thumbnail_width, thumbnail_height, listed,
- "timestamp", NULL::text, NULL::text, NULL::boolean, NULL::int,
- NULL::int, NULL::text, NULL::text, NULL::timestamp, NULL::text
+ attachment_id, mapping_id, NULL::text, NULL::text,
+ filename, mime_type, bytesize, image, thumbnail,
+ thumbnail_size, thumbnail_width, thumbnail_height, in_gallery, listed,
+ author, "location", width, height, "timestamp"
);
create or replace rule attachments_update as
@@ -319,15 +310,13 @@ create or replace rule attachments_update as
thumbnail_size = new.thumbnail_size,
thumbnail_width = new.thumbnail_width,
thumbnail_height = new.thumbnail_height,
- listed = new.listed
- where attachment_id = old.attachment_id;
- UPDATE _images SET
- width = new.width,
- height = new.height,
+ listed = new.listed,
+ in_gallery = new.in_gallery,
author = new.author,
"location" = new."location",
- exif_date = new.exif_date,
- exif = new.exif
+ width = new.width,
+ height = new.height,
+ "timestamp" = new."timestamp"
where attachment_id = old.attachment_id;
UPDATE _attachment_descr SET title=new.title, description=new.description
where attachment_id = old.attachment_id and lang = old.lang;
hooks/post-receive
--
Wiking
More information about the Wiking-cvs
mailing list