Changeset 195

Show
Ignore:
Timestamp:
08/22/08 19:12:15 (3 months ago)
Author:
rgrp
Message:

[shakespeare/misc][s]: remove concordance.py and all references and tidy up guide WUI page.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/shakespeare/controllers/site.py

    Revision 188 Revision 195
    1import logging 1import logging 
    2 2 
    3import genshi 3import genshi 
    4 4 
    5from shakespeare.lib.base import * 5from shakespeare.lib.base import * 
    6 6 
    7import shakespeare 7import shakespeare 
    8import shakespeare.index 8import shakespeare.index 
    9import shakespeare.format 9import shakespeare.format 
    10import shakespeare.concordance   
    11import shakespeare.model as model 10import shakespeare.model as model 
    12 11 
    13# import this after dm so that db connection is set 12# import this after dm so that db connection is set 
    14# import annotater.store 13# import annotater.store 
    15# import annotater.marginalia 14# import annotater.marginalia 
    16 15 
    17log = logging.getLogger(__name__) 16log = logging.getLogger(__name__) 
    18 17 
    19 18 
    20class SiteController(BaseController): 19class SiteController(BaseController): 
    21 20 
    22    def index(self): 21    def index(self): 
    23        c.works_index = shakespeare.index.all 22        c.works_index = shakespeare.index.all 
    24        return render('index') 23        return render('index') 
    25 24 
    26    def guide(self): 25    def guide(self): 
    27        return render('guide') 26        return render('guide') 
    28   
    29    def concordance(self, word=None):   
    30        # TODO: support concordance/word   
    31        return self.concordance_index()   
    32   
    33    def concordance_index(self):   
    34        stats = shakespeare.concordance.Statistics()   
    35        c.words = stats.keys()   
    36        return render('concordance')   
    37   
    38    def concordance_word(self, word=None):   
    39        # TODO: sort by work etc   
    40        import shakespeare.textutils   
    41        refs = []   
    42        cc = shakespeare.concordance.Concordance()   
    43        if word is not None:   
    44            refs = list(cc.get(word))   
    45        newrefs = []   
    46        for ref in refs:   
    47            # we use the 'plain' format when building the concordance   
    48            ff = ref.text.get_text()   
    49            snippet = shakespeare.textutils.get_snippet(ff, ref.char_index)   
    50            ref.snippet = snippet   
    51        c.word = word   
    52        c.refs = refs   
    53        return render('concordance_by_word')   
    54 27 
    55    # 2008-04-26 (rgrp): none of these annotater related items 28    # 2008-04-26 (rgrp): none of these annotater related items 
    56    # seem to working properly 29    # seem to working properly 
    57    # think it is related to annotater so leaving this alone for time being 30    # think it is related to annotater so leaving this alone for time being 
    58 31 
    59    def marginalia(self): 32    def marginalia(self): 
    60        prefix = '/' + h.url_for('marginalia') 33        prefix = '/' + h.url_for('marginalia') 
    61        media_app = annotater.marginalia.MarginaliaMedia(prefix) 34        media_app = annotater.marginalia.MarginaliaMedia(prefix) 
    62        out = media_app(request.environ, self.start_response) 35        out = media_app(request.environ, self.start_response) 
    63        return out 36        return out 
    64 37 
    65    def annotation(self): 38    def annotation(self): 
    66        store = annotater.store.AnnotaterStore() 39        store = annotater.store.AnnotaterStore() 
    67        return store(request.environ, self.start_response) 40        return store(request.environ, self.start_response) 
    68 41 
    69    def view_annotate(self): 42    def view_annotate(self): 
    70        # only one name here ... 43        # only one name here ... 
    71        name = request.params.get('name') 44        name = request.params.get('name') 
    72        textobj = model.Material.byName(name) 45        textobj = model.Material.byName(name) 
    73        tfileobj = textobj.get_text() 46        tfileobj = textobj.get_text() 
    74        formatter = shakespeare.format.TextFormatterAnnotate() 47        formatter = shakespeare.format.TextFormatterAnnotate() 
    75        # not perfect in that we might have the application mounted somewhere 48        # not perfect in that we might have the application mounted somewhere 
    76        annotation_store_fqdn = wsgiref.util.application_uri(request.environ) 49        annotation_store_fqdn = wsgiref.util.application_uri(request.environ) 
    77        page_url = wsgiref.util.request_uri(request.environ) 50        page_url = wsgiref.util.request_uri(request.environ) 
    78        ttext = formatter.format(tfileobj, page_uri=page_url) 51        ttext = formatter.format(tfileobj, page_uri=page_url) 
    79        thtml = genshi.HTML(ttext) 52        thtml = genshi.HTML(ttext) 
    80 53 
    81        prefix = cfg.get('annotater', 'marginalia_prefix') 54        prefix = cfg.get('annotater', 'marginalia_prefix') 
    82        marginalia_media = annotater.marginalia.get_media_header(prefix, 55        marginalia_media = annotater.marginalia.get_media_header(prefix, 
    83                annotation_store_fqdn, 56                annotation_store_fqdn, 
    84                page_url) 57                page_url) 
    85        buttons = annotater.marginalia.get_buttons(page_url) 58        buttons = annotater.marginalia.get_buttons(page_url) 
    86        marginalia_media = genshi.HTML(marginalia_media) 59        marginalia_media = genshi.HTML(marginalia_media) 
    87        buttons = genshi.HTML(buttons) 60        buttons = genshi.HTML(buttons) 
    88 61 
    89        c.text_with_annotation=thtml 62        c.text_with_annotation=thtml 
    90        c.marginalia_media=marginalia_media 63        c.marginalia_media=marginalia_media 
    91        c.annotation_buttons=buttons 64        c.annotation_buttons=buttons 
    92        return render('view_annotate', strip_whitespace=False) 65        return render('view_annotate', strip_whitespace=False) 
    93 66 
  • trunk/shakespeare/controllers/text.py

    Revision 188 Revision 195
    1import logging 1import logging 
    2 2 
    3import genshi 3import genshi 
    4 4 
    5from shakespeare.lib.base import * 5from shakespeare.lib.base import * 
    6 6 
    7import shakespeare 7import shakespeare 
    8import shakespeare.index 8import shakespeare.index 
    9import shakespeare.format 9import shakespeare.format 
    10import shakespeare.concordance   
    11import shakespeare.model as model 10import shakespeare.model as model 
    12 11 
    13# import this after dm so that db connection is set 12# import this after dm so that db connection is set 
    14# import annotater.store 13# import annotater.store 
    15# import annotater.marginalia 14# import annotater.marginalia 
    16 15 
    17log = logging.getLogger(__name__) 16log = logging.getLogger(__name__) 
    18 17 
    19 18 
    20class TextController(BaseController): 19class TextController(BaseController): 
    21 20 
    22    def index(self): 21    def index(self): 
    23        c.works_index = shakespeare.index.all 22        c.works_index = shakespeare.index.all 
    24        return render('text/index') 23        return render('text/index') 
    25 24 
    26    def view(self): 25    def view(self): 
    27        name = request.params.get('name', '') 26        name = request.params.get('name', '') 
    28        format = request.params.get('format', 'plain') 27        format = request.params.get('format', 'plain') 
    29        if format == 'annotate': 28        if format == 'annotate': 
    30            return self.view_annotate(name) 29            return self.view_annotate(name) 
    31        namelist = name.split() 30        namelist = name.split() 
    32        numtexts = len(namelist) 31        numtexts = len(namelist) 
    33        textlist = [model.Material.byName(tname) for tname in namelist] 32        textlist = [model.Material.byName(tname) for tname in namelist] 
    34        # special case (only return the first text) 33        # special case (only return the first text) 
    35        if format == 'raw': 34        if format == 'raw': 
    36            result = textlist[0].get_text().read() 35            result = textlist[0].get_text().read() 
    37            status = '200 OK' 36            status = '200 OK' 
    38            response.headers['Content-Type'] = 'text/plain' 37            response.headers['Content-Type'] = 'text/plain' 
    39            return result 38            return result 
    40        texts = [] 39        texts = [] 
    41        for item in textlist: 40        for item in textlist: 
    42            tfileobj = item.get_text() 41            tfileobj = item.get_text() 
    43            ttext = shakespeare.format.format_text(tfileobj, format) 42            ttext = shakespeare.format.format_text(tfileobj, format) 
    44            thtml = genshi.HTML(ttext) 43            thtml = genshi.HTML(ttext) 
    45            texts.append(thtml) 44            texts.append(thtml) 
    46        # would have assumed this would be 100.0/numtexts but for some reason 45        # would have assumed this would be 100.0/numtexts but for some reason 
    47        # you need to allow more room (maybe because of the scrollbars?) 46        # you need to allow more room (maybe because of the scrollbars?) 
    48        # result is not consistent across browsers ... 47        # result is not consistent across browsers ... 
    49        c.frame_width = 100.0/numtexts - 4.0 48        c.frame_width = 100.0/numtexts - 4.0 
    50        c.texts = texts 49        c.texts = texts 
    51        # set to not strip whitespace as o/w whitespace in pre tag gets removed 50        # set to not strip whitespace as o/w whitespace in pre tag gets removed 
    52        return render('text/view', strip_whitespace=False) 51        return render('text/view', strip_whitespace=False) 
    53 52 
  • trunk/shakespeare/templates/guide.html

    Revision 181 Revision 195
    1<html xmlns:py="http://genshi.edgewall.org/" 1<html xmlns:py="http://genshi.edgewall.org/" 
    2  xmlns:xi="http://www.w3.org/2001/XInclude"> 2  xmlns:xi="http://www.w3.org/2001/XInclude"> 
    3   3   
    4  <py:def function="page_title">Guide to the Web Interface</py:def> 4  <py:def function="page_title">Guide to the Web Interface</py:def> 
    5 5 
    6  <div py:match="content"> 6  <div py:match="content"> 
    7    <p> 7    <p> 
    8      This page provides a guide to the features of the Open Shakespeare web 8      This page provides a guide to the features of the Open Shakespeare web 
    9      interface. 9      interface. 
    10    </p> 10    </p> 
    11    <h2> 11    <h2> 
    12      The Index 12      The Index 
    13    </h2> 13    </h2> 
    14    <p> 14    <p> 
    15      The <a href="/index/">index page</a> contains a list of all of the 15      The <a href="${h.url_for(controller='text', action='index')}">text index 
    16      material on the system. 16        page</a> contains a list of all of the material on the system. 
    17    </p> 17    </p> 
    18    <h2> 18    <h2> 
    19      Viewing Works 19      Viewing Works 
    20    </h2> 20    </h2> 
    21    <p> 21    <p> 
    22      You can view works by clicking on the link available from the index page. 22      You can view works by clicking on the link available from the index page. 
    23      If you know the 'id' of a text you can view it directly by visiting the 23      If you know the 'id' of a text you can view it directly by visiting the 
    24                       url: /view?name={id} (you can work out id names by looking at the lin24      url: ${h.url_for(controller='text', action='view', name='id')} (you can wor
    25                       urls on the index page). 25      out id names by looking at the link urls on the index page). 
    26    </p> 26    </p> 
    27     27     
    28    <h3>Viewing in different formats</h3> 28    <h3>Viewing in different formats</h3> 
    29    <p> 29    <p> 
    30      You can view a given text in a different format by setting the format 30      You can view a given text in a different format by setting the format 
    31      argument in the url query string like so: 31      argument in the url query string like so: 
    32      /view?name={id}&amp;format={format_name} So to view hamlet with line  32     </p> 
    33      numbers visit: <a  33     <pre> 
    34        href="/view?name=hamlet_gut&amp;format=lineno">/view?name=hamlet_gut&amp;format=lineno</a> Available formats are:  34       ${h.url_for(controller='text', action='view', name='id', format='format_name')} 
       35     </pre> 
       36     <p> 
       37       So to view Hamlet with line numbers shown you would visit: 
       38     </p> 
       39     <blockquote><p> 
       40       <a href="${h.url_for(controller='text', action='view', name='hamlet_gut', format='lineno')}"> 
       41         ${h.url_for(controller='text', action='view', name='hamlet_gut', format='lineno')}</a> 
       42     </p></blockquote> 
       43     <p> 
       44       Available formats are: 
    35    </p> 45    </p> 
    36    <ul> 46    <ul> 
    37      <li>format=plain - plain version of the file (default)</li> 47      <li>format=plain - plain version of the file (default)</li> 
    38      <li>format=raw - raw file returned as text/plain</li> 48      <li>format=raw - raw file returned as text/plain</li> 
    39      <li>format=lineno - text with line numbers added</li> 49      <li>format=lineno - text with line numbers added</li> 
    40    </ul>  50    </ul>  
    41 51 
    42    <h3>Multiviews</h3> 52    <h3>Multiviews</h3> 
    43    <p> 53    <p> 
    44      You can view mutiple texts at once by concatenating the name-ids 54      You can view mutiple texts at once by concatenating the name-ids 
    45      separated by '+'. For example to see the Gutenberg folio and non-folio 55      separated by '+'. For example to see the Gutenberg folio and non-folio 
    46      Othello side-by-side you would visit: <a 56      Othello side-by-side you would visit: <a 
    47        href="/view?name=othello_gut_f+othello_gut">/view?name=othello_gut_f+othello_gut</a>  57         href="${h.url_for(controller='text', action='view', name='othello_gut_f othello_gut')}"> 
       58         ${h.url_for(controller='text', action='view', name='othello_gut_f othello_gut')} 
       59       </a> 
    48    </p> 60    </p> 
    49 61 
    50    <h2> 62    <h2> 
    51      Concordance 63      Search 
    52    </h2> 64    </h2> 
    53    <p> 65    <p> 
    54      The <a href="/concordance/">concordance page</a> provides a concordance of 66      See the <a href="${h.url_for(controller='search', action='index')}">search section</a>. 
    55      Shakespeare's work along with some associated statistics on word   
    56      occurences.   
    57    </p> 67    </p> 
      68 
      69    <h2> 
      70      Search 
      71    </h2> 
      72    <p> 
      73      See the <a href="${h.url_for(controller='stats', action='index')}">stats section</a>. 
      74    </p> 
      75 
    58 76 
    59    <h2>Comments</h2> 77    <h2>Comments</h2> 
    60    <p> 78    <p> 
    61      If you wish to comment on this guide (or help improve it!) please visit 79      If you wish to comment on this guide (or help improve it!) please drop a 
    62      <a href="http://www.openshakespeare.org/">http://www.openshakespeare.org</a> 80      line to the Open Shakespeare team via at info [at] okfn [dot] org. 
    63    </p> 81    </p> 
    64  </div> 82  </div> 
    65 83 
    66  <xi:include href="layout.html" /> 84  <xi:include href="layout.html" /> 
    67</html> 85</html> 
  • trunk/shakespeare/tests/functional/test_site.py

    Revision 176 Revision 195
    1from StringIO import StringIO 1from StringIO import StringIO 
    2 2 
    3from shakespeare.tests import * 3from shakespeare.tests import * 
    4 4 
    5class TestSiteController(TestController): 5class TestSiteController(TestController): 
    6 6 
    7    def test_index(self): 7    def test_index(self): 
    8        url = url_for(controller='site') 8        url = url_for(controller='site') 
    9        res = self.app.get(url) 9        res = self.app.get(url) 
    10        print res 10        print res 
    11        assert "Home" in res 11        assert "Home" in res 
    12        assert 'Welcome to the Open Shakespeare web interface' in res 12        assert 'Welcome to the Open Shakespeare web interface' in res 
    13 13 
    14    def test_guide(self): 14    def test_guide(self): 
    15        url = url_for(controller='site', action='guide') 15        url = url_for(controller='site', action='guide') 
    16        res = self.app.get(url) 16        res = self.app.get(url) 
    17        assert 'guide to the features of the Open Shakespeare web' in res 17        assert 'guide to the features of the Open Shakespeare web' in res 
    18   
    19    def _test_concordance(self):   
    20        url = url_for(controller='site', action='concordance')   
    21        res = self.app.get(url)   
    22 18 
    23    # 2008-04-26 rgrp: not working 19    # 2008-04-26 rgrp: not working 
    24    # seems to be issues inside the annotater stuff so leaving for the time 20    # seems to be issues inside the annotater stuff so leaving for the time 
    25    # being. 21    # being. 
    26 22 
    27#     def test_annotation(self): 23#     def test_annotation(self): 
    28#         url = url_for(controller='site', action='annotation') 24#         url = url_for(controller='site', action='annotation') 
    29#         res = self.app.get(url) 25#         res = self.app.get(url) 
    30#         print str(res) 26#         print str(res) 
    31#         assert 'Annotations' in res 27#         assert 'Annotations' in res 
    32 28 
    33#     def test_view_annotate(self): 29#     def test_view_annotate(self): 
    34#         url = url_for(action='view', name='sonnets_gut', format='annotate') 30#         url = url_for(action='view', name='sonnets_gut', format='annotate') 
    35#         res = self.app.get(url) 31#         res = self.app.get(url) 
    36#         assert 'Annotate' in res 32#         assert 'Annotate' in res 
    37#         print str(res) 33#         print str(res) 
    38#         assert 'THE SONNETS' in res 34#         assert 'THE SONNETS' in res 
    39#         assert 'rest-annotate.js' in res 35#         assert 'rest-annotate.js' in res 
    40#  36#  
    41#     def test_marginalia(self): 37#     def test_marginalia(self): 
    42#         url = url_for(controller='site', action='marginalia', url='rest-annotate.js') 38#         url = url_for(controller='site', action='marginalia', url='rest-annotate.js') 
    43#         res = self.app.get(url) 39#         res = self.app.get(url) 
    44#         print str(res) 40#         print str(res) 
    45#         assert 'AnnotationService' in res 41#         assert 'AnnotationService' in res 
    46#  42#  
  • trunk/test.ini

    Revision 148 Revision 195
    1# 1# 
    2# shakespeare - Pylons testing environment configuration 2# shakespeare - Pylons testing environment configuration 
    3# 3# 
    4# The %(here)s variable will be replaced with the parent directory of this file 4# The %(here)s variable will be replaced with the parent directory of this file 
    5# 5# 
    6[DEFAULT] 6[DEFAULT] 
    7debug = true 7debug = true 
    8# Uncomment and replace with the address which should receive any error reports 8# Uncomment and replace with the address which should receive any error reports 
    9#email_to = you@yourdomain.com 9#email_to = you@yourdomain.com 
    10smtp_server = localhost 10smtp_server = localhost 
    11error_email_from = paste@localhost 11error_email_from = paste@localhost 
    12 12 
    13[server:main] 13[server:main] 
    14use = egg:Paste#http 14use = egg:Paste#http 
    15host = 0.0.0.0 15host = 0.0.0.0 
    16port = 5000 16port = 5000 
    17 17 
    18[app:main] 18[app:main] 
    19use = config:development.ini 19use = config:development.ini 
    20 20 
    21# Add additional test specific configuration options as necessary. 21# Add additional test specific configuration options as necessary. 
      22sqlalchemy.url = sqlite:///%(here)s/testshkspr.db