How to...
...start
Starting a new website you have the following options.- Start by inheriting from one of the high level builder classes (the best approach, since everything will be in place and working, while you only have to write two lines of code.
- Start from scratch (a good approach if the new site has very little in common with everything you did earlier).
- Copy from an earlier project (a good approach when the new website is very similar to an existing project).
- Copy from example parts of this manual (a good approach learning the various possible patterns and library components).
...inherit from one of the hig level builder classes
@@@@@@@@@@@@@@@@@...start from scratch
Starting a website from scratch includes the following actions:
Create the initial files and directories
- The _image will contain a directory structure of all images used in the site.
- The _m contains text module XML files (if the site is not based on a database).
- The _py gets all the dynamically included Python sources (so they can be shared by other applications in the same site) and the __init__.py (predominantly empty file) allows Python to use this directory as importing modules. The file _packagename defines the name of the application module that will be dynamically included (and released) by the application (see Including modules);
- The _xsl directory holds all XSL templates to translate the XML to HTML/Python instructions.
- The _base is an empty file that defines the directory position where all unbased paths (e.g. "./xxx/yyy") refer to.
- The template.xsl is the default template XSL file.
- The index.py holds the main Python application.
Create the main index.py application.
- Decide if you want to base the new website on
- XierpaBuilder, most flexible, but needs more coding'
- LayoutBuilder, allows building the page layout from a gstate set of parameters;
- SiteBuilder, hardly initial coding but a bit less flexible. However, the SiteBuilder installs all the methods that are required for building a site including XierpaBuilder, LayoutBuilder, Ajax control of page parts, remote CSS fuctions and standard database access.
- CmsBuilder or CmsAjaxBuilder implementing all of the above and additionally many ready made CMS functions.
- When using the LayoutBuilder create an UTF-8 file with the following content (assuming for now that there is no database used).
View the result of this code here.
# -*- coding: UTF-8 -*- from xpyth.xierpa.imaging.gstate import gnode from xpyth.xierpa.builders.layoutbuilder import LayoutBuilder from xpyth.xierpa.tools.transformer import px PAGEWIDTH = 900 from css import buildcss class Home(LayoutBuilder): # # Hooks to be called from LayoutBuilder # def headlogo(self, gstate): self.text('My logo goes here') def navigation(self, gstate): self.text('My navigation goes here') def content(self, gstate): self.text('My content goes here') # # Table that defines the page layout # layout = gnode(border=1, nodes=[ gnode(y=0, x=0, w=px(PAGEWIDTH), colspan=2, class_='headlogo', hook=headlogo), gnode(y=1, x=0, w='25%', hook=navigation), gnode(y=1, x=1, w='75%', hook=content), ]) # # Main page methods # def buildhead(self): self.head() self.title() self.text('My website') self._title() self.style() self.tablelayoutcss(self.layout) self._style() self._head() def buildbody(self): self.body() # Show as table construction self.tablelayout(self.layout) self._body() def setup(self): # Initial calculations are done here pass def build(self): self.setup() self.doctype('xhtml-transitional') self.html() self.buildhead() self.buildbody() self._html() Home(e, result).build()
Note: Note that when copying the content of the source from this browser page, you have to adjust the indent from spaces to tabs, or else Python may not recognize the right indentation.
...start from a copy
...use examples
...center the content of a page
The content of a page can be centered by using the pagewrapper tag.Note: The content of the page should use positioning that work within the resulting div tag, such as tables and relative CSS positions.
self.body() self.pagewrapper(width=900, backgroundcolor='gray') ... self._pagewrapper() self._body()
...build intermediate table for the relation many2one-one2many

Create table manually from the CREATE TABLE "cantact" (...) query in the project.graffle.sql file. Then do this once
# Get selection with all entries:
jobselection = getselection(self.agent,'job')
for jobrecord in jobselection:
if jobrecord.contact:
# Now, we presume that the multiple ids is a commaseparated list
for id in jobrecord.intertablename.split(','):
id = int(id)
# You can then do one or two:
newtable = getrecord(self.agent, 'contact', readonly=False)
newtable.job_id = jobrecord.id
newtable.instcontact_id = id
newtable._sync()
# or (and here you won't use 'newtable.job_id = jobrecord.id'
# since it will create dublet 'job_id' field in the new table)
newtable = jobrecord._newrelation('contact')
newtable.instcontact_id = id
newtable._sync()
for jobrecord in jobselection: if jobrecord.contact: for cont in jobrecord.contact_many: self.text(cont.instcontact_id.name)
