コード例 #1
0
ファイル: home.py プロジェクト: pombredanne/old-webapp
    def index_ajax(self):
        """Display the OLD Application home page.  This page is generated from
        the entry with name='home' of the table page_table of the model.  This
        page can be edited by administrators.

        """

        response.headers['Content-Type'] = 'application/json'
        result = {}

        # Get the number of Forms in the db
        result['formCount'] = str(h.getFormCount())

        # Get the homepage from the model
        homepage_q = meta.Session.query(model.Page).filter(
            model.Page.name==u'home')
        homepage = homepage_q.first()

        try:
            result['headerText'] = homepage.heading
            result['bodyContent'] = homepage.content
        except AttributeError:
            result['heading'] = u'There is no heading'
            result['content'] = u'There is no content for this page'

        # Perform a series of transformations on the page body content:
        #  1. convert reStructuredText to HTML, 2. link to OLD entities,
        #  3. embed Files and 4. Forms (LAST 3 SHOULD BE DONE CLIENT-SIDE)
        # Convert OLD Markup references to links/representations
        result['bodyContent'] = embedForms(
                                embedFiles(
                                linkToOLDEntitites(
                                h.rst2html(result['bodyContent']))))

        return json.dumps(result)
コード例 #2
0
ファイル: home.py プロジェクト: pombredanne/old-webapp
    def index(self):
        """Display the OLD Application home page.  This page is generated from
        the entry with name='home' of the table page_table of the model.  This
        page can be edited by administrators.
        
        """
        
        # Get the number of Forms in the db
        c.formCount = str(h.getFormCount())
        
        # Get the homepage from the model
        homepage_q = meta.Session.query(model.Page).filter(
            model.Page.name==u'home')
        homepage = homepage_q.first()

        try:
            c.heading = homepage.heading
            c.content = homepage.content
        except AttributeError:
            c.heading = u'There is no heading'
            c.content = u'There is no content for this page'

        # Convert reStructuredText to HTML
        c.content = h.rst2html(c.content)
        
        # Convert OLD Markup references to links/representations
        c.content = linkToOLDEntitites(c.content)
        c.content = embedFiles(c.content)
        c.content = embedForms(c.content)
        
        return render('/derived/home/index.html')
コード例 #3
0
 def view(self, id):
     """View an OLD Speaker.  Requires a Speaker ID as input."""
     
     if id is None:
         abort(404)
     speaker_q = meta.Session.query(model.Speaker)
     c.speaker = speaker_q.get(int(id))
     if c.speaker is None:
         abort(404)
     c.speakerPageContent = h.rst2html(c.speaker.speakerPageContent)
     
     # Convert OLD Markup references to links/representations
     c.speakerPageContent = linkToOLDEntitites(c.speakerPageContent)
     c.speakerPageContent = embedFiles(c.speakerPageContent)
     c.speakerPageContent = embedForms(c.speakerPageContent)
     
     return render('/derived/people/speaker/view.html')
コード例 #4
0
ファイル: researcher.py プロジェクト: jrwdunham/old-webapp
    def view(self, id):
        """View an OLD Researcher.  Requires a Researcher ID as input.
        
        """

        if id is None:
            abort(404)

        researcher_q = meta.Session.query(model.User)
        c.researcher = researcher_q.get(int(id))

        if c.researcher is None:
            abort(404)

        c.personalPageContent = h.rst2html(c.researcher.personalPageContent)

        # Convert OLD Markup references to links/representations
        if c.personalPageContent:
            c.personalPageContent = linkToOLDEntitites(c.personalPageContent)
            c.personalPageContent = embedFiles(c.personalPageContent)
            c.personalPageContent = embedForms(c.personalPageContent)

        return render("/derived/people/researcher/view.html")
コード例 #5
0
ファイル: collection.py プロジェクト: pombredanne/old-webapp
def getCollectionContentsAsHTML(collection):
    """This function formats the contents of a Collection as HTML.  It assumes
    the contents text is written in reStructuredText.
    
    """

    contents = collection.contents

    # formID2Enumerator example: {'9': '4'} means that the first Form with ID=9
    #  occurs as the fourth example (i.e., enumerator = '4') in the Collection
    formID2Enumerator = {}

    # enumerator gives example numbers to embedded forms
    enumerator = 1

    # c.formsDict will be used by template to get the correct Form
    c.formsDict = dict([(form.id, form) for form in collection.forms])

    # Replace each embedding reference to a Collection with its contents
    #  (verbatim). Do this first so that the subsequent rst2html conversion will
    #  convert the composite collection in one go.  This seems easier than doing
    #  rst2html(collection.contents) for each embedded Collection...
    contents = embedContentsOfCollections(contents)

    # Convert collection's contents to HTML using rst2html
    contents = h.rst2html(contents)

    # Replace "form[X]" with an example table, i.e., enumerator in first cell,
    #  form data in second:
    #
    #   (23)    blah    blahblah x
    #           blah    blah-blah x
    #           xyz     xyz-xyz-33
    #           zyz3 3 ayaazy883
    #
    patt = re.compile('([Ff]orm\[([0-9]+)\])')
    newContentsLinesList = []
    contentsLinesList = patt.sub('\n\\1\n', contents).split('\n')

    for line in contentsLinesList:
        if patt.search(line):

            # Update formID2Enumerator only if this is this form's first occurrence
            if patt.search(line).group(2) not in formID2Enumerator:
                formID2Enumerator[patt.search(line).group(2)] = str(enumerator)

            # Replace each match with an example table with an enumerator
            newContentsLinesList.append(
                patt.sub(
                    lambda x: getExampleTable(enumerator, x.group(1),
                                              int(x.group(2))), line))

            enumerator += 1
        else:
            newContentsLinesList.append(line)

    contents = '\n'.join(newContentsLinesList)

    # Replace "ref[x]" with the enumerator of the first occurrence of the Form
    #  with id=x that is embedded in this Collection's content
    refPatt = re.compile('([Rr]ef\[([0-9]+)\])')
    contents = refPatt.sub(
        lambda x: getEnumerator(formID2Enumerator, x.group(2)), contents)

    # Replace each embedding reference to a Form with a representation of that
    #  Form.
    contents = patt.sub(lambda x: getFormAsHTMLTable(x, c.formsDict), contents)

    # Embed OLD Files
    contents = embedFiles(contents)

    # Replace each linking reference to an OLD entity with an HTML link
    contents = linkToOLDEntitites(contents)

    return contents
コード例 #6
0
ファイル: collection.py プロジェクト: jrwdunham/old-webapp
def getCollectionContentsAsHTML(collection):
    """This function formats the contents of a Collection as HTML.  It assumes
    the contents text is written in reStructuredText.
    
    """
    
    contents = collection.contents
    
    # formID2Enumerator example: {'9': '4'} means that the first Form with ID=9
    #  occurs as the fourth example (i.e., enumerator = '4') in the Collection
    formID2Enumerator = {}
    
    # enumerator gives example numbers to embedded forms
    enumerator = 1
    
    # c.formsDict will be used by template to get the correct Form
    c.formsDict = dict([(form.id, form) for form in collection.forms])
    
    # Replace each embedding reference to a Collection with its contents
    #  (verbatim). Do this first so that the subsequent rst2html conversion will
    #  convert the composite collection in one go.  This seems easier than doing
    #  rst2html(collection.contents) for each embedded Collection...
    contents = embedContentsOfCollections(contents)

    # Convert collection's contents to HTML using rst2html
    contents = h.rst2html(contents)
    
    # Replace "form[X]" with an example table, i.e., enumerator in first cell,
    #  form data in second:
    #
    #   (23)    blah    blahblah x
    #           blah    blah-blah x
    #           xyz     xyz-xyz-33
    #           zyz3 3 ayaazy883
    #
    patt = re.compile('([Ff]orm\[([0-9]+)\])')
    newContentsLinesList = []
    contentsLinesList = patt.sub('\n\\1\n', contents).split('\n')

    for line in contentsLinesList:
        if patt.search(line):
            
            # Update formID2Enumerator only if this is this form's first occurrence
            if patt.search(line).group(2) not in formID2Enumerator:
                formID2Enumerator[patt.search(line).group(2)] = str(enumerator)
            
            # Replace each match with an example table with an enumerator
            newContentsLinesList.append(
                patt.sub(
                    lambda x: getExampleTable(
                        enumerator, x.group(1), int(x.group(2))),
                    line
                )
            )

            enumerator += 1
        else:
            newContentsLinesList.append(line)
            
    contents = '\n'.join(newContentsLinesList)

    # Replace "ref[x]" with the enumerator of the first occurrence of the Form
    #  with id=x that is embedded in this Collection's content
    refPatt = re.compile('([Rr]ef\[([0-9]+)\])')
    contents = refPatt.sub(
        lambda x: getEnumerator(formID2Enumerator, x.group(2)), contents)

    # Replace each embedding reference to a Form with a representation of that
    #  Form.
    contents = patt.sub(
        lambda x: getFormAsHTMLTable(x, c.formsDict),
        contents
    )

    # Embed OLD Files
    contents = embedFiles(contents)

    # Replace each linking reference to an OLD entity with an HTML link
    contents = linkToOLDEntitites(contents)
    
    return contents