Changeset 267:8df4c4afb100

Show
Ignore:
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:
4 modified

Legend:

Unmodified
Added
Removed
  • shakespeare/controllers/anno.py

    r257 r267  
    55 
    66from shakespeare.lib.base import * 
     7from shakespeare.controllers.our_resource import render_resource 
    78 
    89log = logging.getLogger(__name__) 
     
    1920 
    2021    def annotate(self, id=None): 
     22        c.error = '' 
     23        c.content = '' 
    2124        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 
    2731        if not text: 
    2832            c.error = 'No text to annotate!'  
    29             c.content = '' 
    3033        else: 
     34            c.uri = text 
     35            # allow for possibility in future of not having logged in users 
     36            c.userid = c.user.id 
    3137            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') 
    4242 
  • shakespeare/controllers/user.py

    r239 r267  
    2929            return form 
    3030        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) 
    3236 
    3337    def logout(self): 
  • shakespeare/templates/anno/annotate.html

    r257 r267  
    77 
    88  <py:def function="page_specific_css"> 
     9    <!-- 
    910    <script src="http://github.com/nickstenning/annotator/raw/0.5/pkg/annotator.min.js"></script> 
    1011    <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 
    1714    <script src="/jsannotate-lib/vendor/jquery.pluginfactory.js"></script> 
    1815    <script src="/jsannotate-lib/vendor/jquery.sji.js"></script> 
     16    <script src="/jsannotate-lib/vendor/jquery.json.js"></script> 
    1917    <script src="/jsannotate-lib/extensions.js"></script> 
    2018    <script src="/jsannotate-lib/annotator.js"></script> 
     19    <script src="/jsannotate-lib/annotation_store.js"></script> 
    2120    <link rel="stylesheet" type="text/css" href="/jsannotate-lib/annotator.css" /> 
    22     --> 
    2321  </py:def> 
    2422 
     
    3331          var annotator_prefix = '/anno_store/annotation'; 
    3432          // an identifier for the document 
    35           var annotator_doc_uri = 'xxx'; 
     33          var annotator_doc_uri = '${c.text}'; 
    3634          $('#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          }); 
    3842          // 'uri': annotator_doc_uri}); 
    3943        }); 
  • shakespeare/tests/functional/test_anno.py

    r256 r267  
    11from shakespeare.tests import * 
     2import shakespeare.model as model 
    23 
    34class TestAnnoController(TestController): 
     
    56    def setup_class(self): 
    67        self.text = TestData.make_fixture() 
     8        self.username = u'xyz.com' 
    79 
    810    @classmethod 
    911    def teardown_class(self): 
    10         TestData.remove_fixtures() 
     12        model.repo.rebuild_db() 
    1113 
    1214    def test_index(self): 
     
    1416        assert 'Choose a text to annotate' in res 
    1517 
    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            ) 
    1822        assert 'Annotate' in res 
    1923        assert 'No text to annotate' in res 
     
    2327        form = res.forms[0] 
    2428        form['text'] = self.text.name 
    25         res = form.submit() 
     29        res = form.submit(extra_environ={'REMOTE_USER': str(self.username)}) 
    2630        assert 'Annotate' in res  
    2731        assert self.text.content.split()[0] in res, res 
    2832        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 
    2942 
    3043    # run this last