Esempio n. 1
0
    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)
Esempio n. 2
0
    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')
Esempio n. 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')
Esempio n. 4
0
    def applicationhelp(self):
        """Display the OLD Application help page.  This page is generated from
        the entry with name='help' of the page table of the model.  This page
        can be edited by administrators.
        
        """

        # Get the helppage from the model
        helppage_q = meta.Session.query(model.Page).filter(model.Page.name == u"help")
        helppage = helppage_q.first()

        c.heading = helppage.heading

        # Get the help page content and translate it to HTML
        content = helppage.content
        content = h.literal(h.rst2html(content))

        c.content = content

        return render("/derived/help/help.html")
Esempio n. 5
0
    def applicationhelp(self):
        """Display the OLD Application help page.  This page is generated from
        the entry with name='help' of the page table of the model.  This page
        can be edited by administrators.
        
        """

        # Get the helppage from the model
        helppage_q = meta.Session.query(
            model.Page).filter(model.Page.name == u'help')
        helppage = helppage_q.first()

        c.heading = helppage.heading

        # Get the help page content and translate it to HTML
        content = helppage.content
        content = h.literal(h.rst2html(content))

        c.content = content

        return render('/derived/help/help.html')
Esempio n. 6
0
def createUserGuideHTMLFile():
    """Function opens the reStructuredText file docs/user_guide.txt and uses
    docutils.core.publish_parts to generate an html file from it.  The html file
    is written to templates/derived/help
    
    """

    try:
        userGuideFile = codecs.open("./docs/user_guide.txt", encoding="utf-8")
        userGuideString = userGuideFile.read()
        userGuideHTML = h.rst2html(userGuideString)
    except IOError:
        userGuideHTML = ""

    try:
        userGuideAbsPath = os.path.join(
            config["pylons.paths"]["root"], "templates", "derived", "help", "user_guide_body.html"
        )
        outputFile = open(userGuideAbsPath, "w")
        outputFile.write(userGuideHTML)
    except IOError:
        pass
Esempio n. 7
0
def createUserGuideHTMLFile():
    """Function opens the reStructuredText file docs/user_guide.txt and uses
    docutils.core.publish_parts to generate an html file from it.  The html file
    is written to templates/derived/help
    
    """

    try:
        userGuideFile = codecs.open('./docs/user_guide.txt', encoding='utf-8')
        userGuideString = userGuideFile.read()
        userGuideHTML = h.rst2html(userGuideString)
    except IOError:
        userGuideHTML = ''

    try:
        userGuideAbsPath = os.path.join(config['pylons.paths']['root'],
                                        'templates', 'derived', 'help',
                                        'user_guide_body.html')
        outputFile = open(userGuideAbsPath, 'w')
        outputFile.write(userGuideHTML)
    except IOError:
        pass
Esempio n. 8
0
    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")
Esempio n. 9
0
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
Esempio n. 10
0
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