Mercurial > hg > documentViewer
comparison documentViewer.py @ 613:c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/281
author | casties |
---|---|
date | Thu, 17 Oct 2013 16:25:39 +0200 |
parents | a79e4e4b3e37 |
children | d6eca930a534 7aefbddddaf9 |
comparison
equal
deleted
inserted
replaced
612:a79e4e4b3e37 | 613:c57d80a649ea |
---|---|
2 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate | 2 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
3 from Products.PageTemplates.PageTemplateFile import PageTemplateFile | 3 from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
4 from App.ImageFile import ImageFile | 4 from App.ImageFile import ImageFile |
5 from AccessControl import ClassSecurityInfo | 5 from AccessControl import ClassSecurityInfo |
6 from AccessControl import getSecurityManager | 6 from AccessControl import getSecurityManager |
7 from Globals import package_home | |
8 | 7 |
9 import xml.etree.ElementTree as ET | 8 import xml.etree.ElementTree as ET |
10 | 9 |
11 import os | 10 import os |
12 import sys | |
13 import urllib | 11 import urllib |
14 import logging | 12 import logging |
15 import math | 13 import math |
16 import urlparse | 14 import urlparse |
17 import re | |
18 import string | |
19 import json | 15 import json |
20 | 16 |
21 from Products.MetaDataProvider import MetaDataFolder | 17 from Products.MetaDataProvider import MetaDataFolder |
22 | 18 |
23 from SrvTxtUtils import getInt, utf8ify, getText, getHttpData, refreshingImageFileIndexHtml | 19 from SrvTxtUtils import getInt, utf8ify, getText, getHttpData, refreshingImageFileIndexHtml |
24 | 20 |
25 def serializeNode(node, encoding="utf-8"): | |
26 """returns a string containing node as XML""" | |
27 s = ET.tostring(node) | |
28 | |
29 # 4Suite: | |
30 # stream = cStringIO.StringIO() | |
31 # Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding) | |
32 # s = stream.getvalue() | |
33 # stream.close() | |
34 return s | |
35 | 21 |
36 def getMDText(node): | 22 def getMDText(node): |
37 """returns the @text content from the MetaDataProvider metadata node""" | 23 """returns the @text content from the MetaDataProvider metadata node""" |
38 if isinstance(node, dict): | 24 if isinstance(node, dict): |
39 return node.get('@text', None) | 25 return node.get('@text', None) |
991 | 977 |
992 return pageinfo | 978 return pageinfo |
993 | 979 |
994 | 980 |
995 def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0): | 981 def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0): |
996 """returns dict with array of page information for one screenfull of thumbnails""" | 982 """Return dict with array of page information for one screenfull of thumbnails. |
983 | |
984 :param start: index of current page | |
985 :param rows: number of rows in one batch | |
986 :param cols: number of columns in one batch | |
987 :param pageFlowLtr: do indexes increase from left to right | |
988 :param pageZero: is there a zeroth non-visible page | |
989 :param minIdx: minimum index to use | |
990 :param maxIdx: maximum index to use | |
991 :returns: dict with | |
992 first: first page index | |
993 last: last page index | |
994 batches: list of all possible batches(dict: 'start': index, 'end': index) | |
995 pages: list for current batch of rows(list of cols(list of pages(dict: 'idx': index))) | |
996 nextStart: first index of next batch | |
997 prevStart: first index of previous batch | |
998 """ | |
997 logging.debug("getPageBatch start=%s minIdx=%s maxIdx=%s"%(start,minIdx,maxIdx)) | 999 logging.debug("getPageBatch start=%s minIdx=%s maxIdx=%s"%(start,minIdx,maxIdx)) |
998 batch = {} | 1000 batch = {} |
999 grpsize = rows * cols | 1001 grpsize = rows * cols |
1000 if maxIdx == 0: | 1002 if maxIdx == 0: |
1001 maxIdx = start + grpsize | 1003 maxIdx = start + grpsize |
1002 | 1004 |
1003 np = maxIdx - minIdx + 1 | 1005 np = maxIdx - minIdx + 1 |
1006 if pageZero: | |
1007 # correct number of pages for batching | |
1008 np += 1 | |
1009 | |
1004 nb = int(math.ceil(np / float(grpsize))) | 1010 nb = int(math.ceil(np / float(grpsize))) |
1011 | |
1005 # list of all batch start and end points | 1012 # list of all batch start and end points |
1006 batches = [] | 1013 batches = [] |
1007 if pageZero: | 1014 if pageZero: |
1008 ofs = minIdx - 1 | 1015 ofs = minIdx - 1 |
1009 else: | 1016 else: |
1014 e = min((i + 1) * grpsize + ofs - 1, maxIdx) | 1021 e = min((i + 1) * grpsize + ofs - 1, maxIdx) |
1015 batches.append({'start':s, 'end':e}) | 1022 batches.append({'start':s, 'end':e}) |
1016 | 1023 |
1017 batch['batches'] = batches | 1024 batch['batches'] = batches |
1018 | 1025 |
1026 # list of pages for current screen | |
1019 pages = [] | 1027 pages = [] |
1020 if pageZero and start == minIdx: | 1028 if pageZero and start == minIdx: |
1021 # correct beginning | 1029 # correct beginning |
1022 idx = minIdx - 1 | 1030 idx = minIdx - 1 |
1023 else: | 1031 else: |
1043 batch['prevStart'] = max(start - grpsize, minIdx) | 1051 batch['prevStart'] = max(start - grpsize, minIdx) |
1044 else: | 1052 else: |
1045 batch['prevStart'] = None | 1053 batch['prevStart'] = None |
1046 | 1054 |
1047 if start + grpsize <= maxIdx: | 1055 if start + grpsize <= maxIdx: |
1048 batch['nextStart'] = start + grpsize | 1056 if pageZero and start == minIdx: |
1057 # correct nextStart for pageZero | |
1058 batch['nextStart'] = grpsize | |
1059 else: | |
1060 batch['nextStart'] = start + grpsize | |
1049 else: | 1061 else: |
1050 batch['nextStart'] = None | 1062 batch['nextStart'] = None |
1051 | 1063 |
1052 batch['pages'] = pages | 1064 batch['pages'] = pages |
1053 batch['first'] = minIdx | 1065 batch['first'] = minIdx |
1054 batch['last'] = maxIdx | 1066 batch['last'] = maxIdx |
1067 logging.debug("batch: %s"%repr(batch)) | |
1055 return batch | 1068 return batch |
1069 | |
1056 | 1070 |
1057 def getBatch(self, start=1, size=10, end=0, data=None, fullData=True): | 1071 def getBatch(self, start=1, size=10, end=0, data=None, fullData=True): |
1058 """returns dict with information for one screenfull of data.""" | 1072 """returns dict with information for one screenfull of data.""" |
1059 batch = {} | 1073 batch = {} |
1060 if end == 0: | 1074 if end == 0: |