Changeset 267:8df4c4afb100
- Timestamp:
- 02/13/10 20:54:33 (7 months ago)
- Author:
- rgrp <http://rufuspollock.org>
- Branch:
- default
- Message:
-
[anno][m]: set doc uri and userid when doing annotation (taking advantage of nickstenning's latest commits).
- New functionality under test plus actual use by js tested by eye (since no other option for js)
- In addition now require login to do annotation (redirect to login)
- controllers/user.py: try to use came_from option in repoze to redirect after login (but not working -- came_from does not seem to arrive at login controller post login ...)
- Location:
- shakespeare
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r257
|
r267
|
|
| 5 | 5 | |
| 6 | 6 | from shakespeare.lib.base import * |
| | 7 | from shakespeare.controllers.our_resource import render_resource |
| 7 | 8 | |
| 8 | 9 | log = logging.getLogger(__name__) |
| … |
… |
|
| 19 | 20 | |
| 20 | 21 | def annotate(self, id=None): |
| | 22 | c.error = '' |
| | 23 | c.content = '' |
| 21 | 24 | c.server_api = self.server_api |
| 22 | | if id: |
| 23 | | text = id |
| 24 | | else: |
| 25 | | text = request.params.get('text', '') |
| 26 | | c.error = '' |
| | 25 | text = id if id else request.params.get('text', '') |
| | 26 | |
| | 27 | if not c.user: |
| | 28 | h.redirect_to(controller='user', action='login', |
| | 29 | came_from=request.url) |
| | 30 | |
| 27 | 31 | if not text: |
| 28 | 32 | c.error = 'No text to annotate!' |
| 29 | | c.content = '' |
| 30 | 33 | else: |
| | 34 | c.uri = text |
| | 35 | # allow for possibility in future of not having logged in users |
| | 36 | c.userid = c.user.id |
| 31 | 37 | mat = model.Material.by_name(text) |
| 32 | | content = mat.get_text().read() |
| 33 | | # HACK: limit size for present |
| 34 | | # content = content[:500] |
| 35 | | c.content = genshi.HTML('<pre>%s</pre>' % content) |
| 36 | | out = render('anno/annotate.html') |
| 37 | | # out is a webhelpers.html.builder.literal |
| 38 | | # we want to work with raw html ... |
| 39 | | # out = unicode(out) |
| 40 | | # out = self.anno_middleware.modify_html(out, include_jquery=False) |
| 41 | | return out |
| | 38 | # get first resource that isn't pdf |
| | 39 | res = filter(lambda x: x.format != 'pdf', mat.resources)[0] |
| | 40 | c.content = genshi.HTML(render_resource(res)) |
| | 41 | return render('anno/annotate.html') |
| 42 | 42 | |
-
|
r239
|
r267
|
|
| 29 | 29 | return form |
| 30 | 30 | else: |
| 31 | | h.redirect_to(controller='user', action='read', id=c.user.id) |
| | 31 | came_from = request.params.get('came_from', None) |
| | 32 | if came_from: |
| | 33 | h.redirect_to(str(came_from)) |
| | 34 | else: |
| | 35 | h.redirect_to(controller='user', action='read', id=c.user.id) |
| 32 | 36 | |
| 33 | 37 | def logout(self): |
-
|
r257
|
r267
|
|
| 7 | 7 | |
| 8 | 8 | <py:def function="page_specific_css"> |
| | 9 | <!-- |
| 9 | 10 | <script src="http://github.com/nickstenning/annotator/raw/0.5/pkg/annotator.min.js"></script> |
| 10 | 11 | <link href="http://github.com/nickstenning/annotator/raw/0.5/pkg/annotator.min.css" type="text/css" rel="stylesheet" /> |
| 11 | | <!-- |
| 12 | | <script src="/jsannotate/annotator.min.js"></script> |
| 13 | | <link href="/jsannotate/annotator.min.css" type="text/css" rel="stylesheet" /> |
| 14 | | --> |
| 15 | | <!-- |
| 16 | | <script src="/jsannotate-lib/vendor/jquery.json.js"></script> |
| | 12 | --> |
| | 13 | |
| 17 | 14 | <script src="/jsannotate-lib/vendor/jquery.pluginfactory.js"></script> |
| 18 | 15 | <script src="/jsannotate-lib/vendor/jquery.sji.js"></script> |
| | 16 | <script src="/jsannotate-lib/vendor/jquery.json.js"></script> |
| 19 | 17 | <script src="/jsannotate-lib/extensions.js"></script> |
| 20 | 18 | <script src="/jsannotate-lib/annotator.js"></script> |
| | 19 | <script src="/jsannotate-lib/annotation_store.js"></script> |
| 21 | 20 | <link rel="stylesheet" type="text/css" href="/jsannotate-lib/annotator.css" /> |
| 22 | | --> |
| 23 | 21 | </py:def> |
| 24 | 22 | |
| … |
… |
|
| 33 | 31 | var annotator_prefix = '/anno_store/annotation'; |
| 34 | 32 | // an identifier for the document |
| 35 | | var annotator_doc_uri = 'xxx'; |
| | 33 | var annotator_doc_uri = '${c.text}'; |
| 36 | 34 | $('#text-to-annotate').annotator(); |
| 37 | | $('#text-to-annotate').annotationStore({'prefix': annotator_prefix}); |
| | 35 | $('#text-to-annotate').annotationStore({ |
| | 36 | 'prefix': annotator_prefix, |
| | 37 | 'annotationData': { |
| | 38 | 'uri': '${c.uri}', |
| | 39 | 'user': '${c.userid}', |
| | 40 | } |
| | 41 | }); |
| 38 | 42 | // 'uri': annotator_doc_uri}); |
| 39 | 43 | }); |
-
|
r256
|
r267
|
|
| 1 | 1 | from shakespeare.tests import * |
| | 2 | import shakespeare.model as model |
| 2 | 3 | |
| 3 | 4 | class TestAnnoController(TestController): |
| … |
… |
|
| 5 | 6 | def setup_class(self): |
| 6 | 7 | self.text = TestData.make_fixture() |
| | 8 | self.username = u'xyz.com' |
| 7 | 9 | |
| 8 | 10 | @classmethod |
| 9 | 11 | def teardown_class(self): |
| 10 | | TestData.remove_fixtures() |
| | 12 | model.repo.rebuild_db() |
| 11 | 13 | |
| 12 | 14 | def test_index(self): |
| … |
… |
|
| 14 | 16 | assert 'Choose a text to annotate' in res |
| 15 | 17 | |
| 16 | | def test_annotate(self): |
| 17 | | res = self.app.get(url_for(controller='anno', action='annotate')) |
| | 18 | def test_annotate_no_text(self): |
| | 19 | res = self.app.get(url_for(controller='anno', action='annotate'), |
| | 20 | extra_environ={'REMOTE_USER': str(self.username)} |
| | 21 | ) |
| 18 | 22 | assert 'Annotate' in res |
| 19 | 23 | assert 'No text to annotate' in res |
| … |
… |
|
| 23 | 27 | form = res.forms[0] |
| 24 | 28 | form['text'] = self.text.name |
| 25 | | res = form.submit() |
| | 29 | res = form.submit(extra_environ={'REMOTE_USER': str(self.username)}) |
| 26 | 30 | assert 'Annotate' in res |
| 27 | 31 | assert self.text.content.split()[0] in res, res |
| 28 | 32 | assert '<pre' in res |
| | 33 | |
| | 34 | def test_annotate(self): |
| | 35 | res = self.app.get( |
| | 36 | url_for(controller='anno', action='annotate', id=self.text.name), |
| | 37 | extra_environ={'REMOTE_USER': str(self.username)} |
| | 38 | ) |
| | 39 | assert "'uri': '%s'" % self.text.name |
| | 40 | userid = model.User.query.filter_by(openid=self.username).first().id |
| | 41 | assert "'user': '%s'" % userid |
| 29 | 42 | |
| 30 | 43 | # run this last |