Changeset 197:cc2f0c5d2514
- Timestamp:
- 09/26/09 12:54:54 (11 months ago)
- Author:
- rgrp
- Branch:
- default
- convert_revision:
- svn:0ead1229-0713-0410-96cd-f668dbfad531/trunk@285
- Message:
-
[multi,resource][s]: fix major bug in multiviews (was not working at all!) and get related test working.
- To get test working create new Resource locator_type (inline) which allows for storing of text inline
- model/dm.py, tests/test_model.py: update Resource.get_stream
- use this type when setting up standard fixtures tests/init.py (this allows us multi functional test to run)
- format.py: fix up conversion to unicode (only do it when necessary -- not needed for inline resource fileobj for example as already unicode)
- Location:
- shakespeare
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r185
|
r197
|
|
| 24 | 24 | text1 = request.params.get('text_1', None) |
| 25 | 25 | text2 = request.params.get('text_2', None) |
| 26 | | if not text1 or text2: |
| | 26 | if not text1 or not text2: |
| 27 | 27 | c.error = 'Texts incorrectly specified' |
| 28 | 28 | return render('multi/view.html') |
| … |
… |
|
| 34 | 34 | for item in textlist: |
| 35 | 35 | tfileobj = item.get_text() |
| 36 | | # hack for time being ... |
| 37 | | if item.format == 'mkd': |
| 38 | | ttext = h.markdown(tfileobj.read()) |
| 39 | | else: |
| 40 | | ttext = shakespeare.format.format_text(tfileobj, format) |
| | 36 | # TODO: check format |
| | 37 | ttext = shakespeare.format.format_text(tfileobj, format) |
| 41 | 38 | texthtml[item.name] = genshi.HTML(ttext) |
| 42 | 39 | c.frame_width = 100.0/numtexts - 4.0 |
-
|
r122
|
r197
|
|
| 43 | 43 | def format(self, file): |
| 44 | 44 | self.file = file |
| 45 | | out = unicode(self.file.read(), 'utf-8') |
| | 45 | out = self.file.read() |
| | 46 | if not isinstance(out, unicode): |
| | 47 | out = unicode(out, 'utf-8') |
| 46 | 48 | out = self.escape_chars(out) |
| 47 | 49 | out = \ |
-
|
r193
|
r197
|
|
| 33 | 33 | # url or path |
| 34 | 34 | Column('locator', UnicodeText), |
| 35 | | # types: url, cache, package, disk |
| | 35 | # types: url, cache, package, disk, inline |
| 36 | 36 | Column('locator_type', UnicodeText, default=u'url'), |
| 37 | 37 | ) |
| … |
… |
|
| 97 | 97 | fileobj = pkg_resources.resource_stream(package, path) |
| 98 | 98 | return fileobj |
| | 99 | elif self.locator_type == u'inline': |
| | 100 | from StringIO import StringIO |
| | 101 | return StringIO(self.locator) |
| 99 | 102 | else: |
| 100 | 103 | raise NotImplementedError |
-
|
r192
|
r197
|
|
| 76 | 76 | work=sonnet18_work, |
| 77 | 77 | ) |
| | 78 | if not sonnet18.resources: |
| | 79 | res = model.Resource(locator_type=u'inline', |
| | 80 | locator=sonnet18_text) |
| | 81 | sonnet18.resources.append(res) |
| 78 | 82 | assert len(sonnet18_work.materials)==1 |
| 79 | 83 | model.Session.flush() |
-
|
r185
|
r197
|
|
| 30 | 30 | # TODO: 2009-07-16 this should be uncommented |
| 31 | 31 | # however form setting does not seem to work (don't know why!) |
| 32 | | # assert not 'Error' in res, res |
| | 32 | assert not 'Error' in res, res |
| 33 | 33 | |
| 34 | 34 | def test_view(self): |
-
|
r193
|
r197
|
|
| 56 | 56 | |
| 57 | 57 | |
| | 58 | class TestResource: |
| | 59 | def test_get_stream_inline(self): |
| | 60 | sometext = u'aaaaaaaaaaaaa' |
| | 61 | res = model.Resource(locator=sometext, locator_type=u'inline') |
| | 62 | out = res.get_stream() |
| | 63 | assert out.read() == sometext |
| | 64 | |
| | 65 | |
| 58 | 66 | class TestStatistic: |
| 59 | 67 | |