diff --git a/Scripts/CentOS-Web/Apps/page.py b/Scripts/CentOS-Web/Apps/page.py index d5d41cd..f6f6d77 100755 --- a/Scripts/CentOS-Web/Apps/page.py +++ b/Scripts/CentOS-Web/Apps/page.py @@ -45,15 +45,15 @@ class Layout(xhtml.Strict): # Define page header. This is the information displayed # between the page top and the page content. self.header = self.logo() - self.header += self.ads_google() - self.header += self.navibar_top() - self.header += self.lastreleases() - self.header += self.appslinks() - self.header += self.navibar_app() + self.header += self.google() + self.header += self.navibar() + self.header += self.releases() + self.header += self.page_links() + self.header += self.page_navibar() # Define page body. This is the information displayed between # the page header and page footer. - self.body = self.content() + self.body = 'None' # Define page footer. This is the information displayed # between the page bottom and the page content, the last @@ -61,7 +61,7 @@ class Layout(xhtml.Strict): self.footer = self.credits() def logo(self): - """Returns XHTML code of page logo. + """Returns The CentOS Logo. The page logo is displayed on the top-left corner of the page. We use this area to show The CentOS Logo, the main visual @@ -78,8 +78,8 @@ class Layout(xhtml.Strict): return self.tag_div(attrs[0], [8,1], self.tag_a(attrs[1], [12,1], self.tag_img(attrs[2], [0,0]), 0), 1) - def ads_google(self): - """Returns XHTML code of Google advertisement (468x60 pixels).""" + def google(self): + """Returns Google advertisements (468x60 pixels).""" output = """
Google Advertisement @@ -107,13 +107,13 @@ class Layout(xhtml.Strict): return output - def navibar_top(self): - """Returns applications top-level navigation bar. + def navibar(self): + """Returns top-level navigation bar. - The top-level navigation bar organizes links to the web - application The CentOS Project makes use of. Links in the - top-level navigation bar remain always visible, no matter what - web application you be visiting (e.g., Wiki, Lists, Forums, + The top-level navigation bar organizes links to main web + applications The CentOS Project makes use of. Links to these + web applications stay always visible, no matter what web + application you be visiting (e.g., Wiki, Lists, Forums, Projects, Bugs, Docs, Downloads and Sponsors.). """ @@ -136,19 +136,19 @@ class Layout(xhtml.Strict): def navibar_tabs(self, names, attrs, focus=''): """Returns navigation tabs. - Arguments: + The navigation tabs are the smaller components a navigation + bar like "top-level navigation bar" and "application + navigation bar" are made of. - names: List of tab names. + names: List containing link names of tabs. - attrs: List of dictionaries for each tab name inside the - `names' list. Dictionaries inside attrs argument contain - the XHTML link attributes (e.g., accesskey, title, and - href) used by tab names so they can be linkable once - rendered. + attrs: List containing a dictionary for each tab link name + inside the `names' list. Dictionaries inside attrs + argument contain the link attributes (e.g., accesskey, + title, and href) used by link names so they can be + linkable once rendered. - focus: Name of the tab marked as current. When no value is - passed to this argument the `Home' value is used as - default value. + focus: Name of the link marked as current. """ navibar_tabs = '' @@ -165,8 +165,22 @@ class Layout(xhtml.Strict): return self.tag_div({'class': 'tabs'}, [8,1], navibar_tabs, 1) - def lastreleases(self, names=['6.0'], attrs=[{'href': '/centos-web/?p=releases&id=6.0'}]): - """Returns last-release information and related RSS link.""" + def releases(self, names=['6.0'], attrs=[{'href': '/centos-web/?p=releases&id=6.0'}]): + """Returns The CentOS Distribution last releases. + + This method introduces the `releases' method by providing + links to it. + + names: List containing release numbers in the form M.N, where M + means major release and N minor release. + + attrs: List containing a dictionary for each release number + provided in `names' argument. These dictionaries provide + the link attributes required by release numbers in order + for them to be transformed into valid links once the page + be rendered. + + """ releases = '' title = self.tag_a({'href': '/centos-web/?p=releases'}, [0,0], 'Last Releases') + ':' @@ -189,21 +203,27 @@ class Layout(xhtml.Strict): return self.tag_div({'id': 'last-releases'}, [8,1], releases + rsslink, 1) - def appslinks(self): - """Returns application related links.""" - appslinks = self.userlinks() - return self.tag_div({'id': 'appslinks'}, [8,1], appslinks, 1) + def user_links_logs(self): + """Return links related to user's logs. + + This function introduces the `logs' module. The `logs' module + registers all user's activity, from login to logout. This link + must be display/accessible only after a user has successfully + login. + """ + last_visit = self.tag_a({'href': '/centos-web/' + self.qs_args({'app':'', 'p':'logs'})}, [0,0], 'Logs') + return self.tag_div({'class': 'logs'}, [12, 1], last_visit, 1) - def lastvisit(self): - last_visit = self.tag_a({'href': '/centos-web/?p=lastvisit'}, [0,0], 'Your last visit was at') - last_visit = self.tag_span({'class': 'title'}, [16, 1], last_visit) - last_visit += self.tag_span({'class': 'datetime'}, [16, 1], '...') - return self.tag_div({'class': 'lastvisit'}, [12, 1], last_visit, 1) + def user_links_session(self): + """Returns links related to user's session. + + This function introduces the `session' module. The `session' + module provides state to user interactions so their action can + be registered individually. - def session(self): - """Returns information related to user's session.""" + """ names = [] attrs = [] session = '' @@ -231,15 +251,19 @@ class Layout(xhtml.Strict): return self.tag_div({'class': 'session'}, [12,1], session, 1) - def trail(self, names=['None'], attrs=[{'href': '/centos-web/'}]): + def user_links_trails(self, names=['None'], attrs=[{'href': '/centos-web/'}]): """Returns page trails (a.k.a. breadcrumbs). - The page breadcrumbs record the last pages visited inside the - current web application. Notice that page breadcrumbs are - user-specific information, so it isn't possible to implement - them until a way to manage user sessions be implemeneted - inside `centos-web.cgi' script. Until then, keep the tag - construction commented and return an empty value. + The page breadcrumbs record the last pages the user visited + inside the current web application. Notice that page + breadcrumbs are user-specific information, so it isn't + possible to implement them until a way to manage user sessions + be implemeneted inside `centos-web.cgi' script. Until then, + keep the tag construction commented and return an empty value. + + names: List with trail link names. + + attrs: Dictionary with trail link attributes. """ links = '' @@ -254,32 +278,31 @@ class Layout(xhtml.Strict): return self.tag_div({'class': 'trail'}, [12,1], links, 1) - def userlinks(self): - """Returns user links. - - Arguments: - - names: List of links you want to have. - - attrs: List of dictionaries with link attributes. In order for - links to be built correctly, both names and attrs lists - must coincide their indexes. + def user_links(self): + """Returns user related links. The user links are specific to each web application. They are - shown in the right-top corner of the application navigation - bar, just over the application navigation tabs. + shown over the application navigation bar. """ - userlinks = self.lastvisit() - userlinks += self.session() - userlinks += self.trail() + userlinks = self.user_links_logs() + userlinks += self.user_links_session() + userlinks += self.user_links_trails() return self.tag_div({'class': 'userlinks'}, [8,1], userlinks, 1) - def navibar_app(self, names=['Welcome'], attrs=[{'href':'/centos-web/?p=welcome'}], focus='Welcome'): - """Returns application's navigation bar.""" + def page_navibar(self, names=['Welcome'], attrs=[{'href':'/centos-web/?p=welcome'}], focus='Welcome'): + """Returns navigation bar for application main pages. + + names: List containing link names. + + attrs: List containing one dictionary for each link name in + `names' argument. Dictionaries here contain the link + attributes needed to make linkable tabs once the page is + rendered. + """ navibar_app = self.navibar_tabs(names, attrs, focus) navibar_app += self.separator({'class': 'page-line white'}, [8,1]) @@ -287,7 +310,16 @@ class Layout(xhtml.Strict): def separator(self, attrs={'class': 'page-line'}, indent=[16,1]): - """Returns a division line.""" + """Returns separator. + + The separator construction is mainly used to clear both sides + inside the page, specially when floating elements are around. + + attrs: Dictionary containing hr's div attributes. + + indent: List containing hr's div indentation values. + + """ line = self.tag_hr({'style': 'display:none;'}, [0,0]) line = self.tag_div(attrs, indent, line) @@ -295,7 +327,7 @@ class Layout(xhtml.Strict): def license(self): - """Retruns link to page license.""" + """Retruns license link.""" license = 'Creative Commons Attribution-Share Alike 3.0 Unported License' license = self.tag_a({'href': 'http://creativecommons.org/licenses/by-sa/3.0/'}, [0,0], license) + '.' @@ -303,7 +335,7 @@ class Layout(xhtml.Strict): def metadata(self): - """Returns page metadata.""" + """Returns metadata.""" metadata = self.tag_meta({'http-equiv': 'content-type', 'content': 'text/html; charset=UTF-8'}, [4,1]) metadata += self.tag_meta({'http-equiv': 'content-style-type', 'content': 'text/css'}, [4,0]) metadata += self.tag_meta({'http-equiv': 'content-language', 'content': str(self.language)}, [4,1]) @@ -317,16 +349,154 @@ class Layout(xhtml.Strict): return self.tag_head('', [0,1], metadata) - def content(self, content='Page empty.'): + def qs_args(self, names={}): + """Returns query string arguments. + + The query string arguments are used to build links dynamically + and, this way, to create a browsable and logically organized + web environment. Such a construction generally needs to + retrive some of the values previously passed to the query + string and add new ones to it. + + names: A dictionary containing the variable name and value + pair used to build a new query string. + + When a variable is provied without a value, then its value is + retrived from the current query string. If a value isn't found + there neither, then the variable is removed from the new query + string. + + When a variable is provided with its value, then its value is + used to build the new query string. + + """ + output = '' + for key in names.keys(): + if names[key] == '': + if key in self.qs: + names[key] = self.qs[key][0] + else: + continue + if output == '': + output = '?' + else: + output += '&' + output += key + '=' + names[key] + + return output + + + def form_search_content(self): + """Returns content search form.""" + + action = self.tag_input({'type':'text', 'value':'', 'size':'20'}, [24,1]) + action += self.tag_input({'type':'submit', 'value':'Search'}, [24,1]) + action = self.tag_span('', [20,1], action, 1) + result = self.tag_span({'class':'last'}, [20,1], 'No result found.') + output = self.tag_div({'class':'actions'}, [16,1], action + result, 1) + return self.tag_form({'action':'/centos-web/' + self.qs_args({'app':'', 'p':''}), 'method':'post', 'title':'Search'}, [12,1], output, 1) + + + def content_list(self, category='None.'): + """Returns content list. + + The content list is used to summarize all the information + available in a specific application main page. The content + list introduces the `pagination' and `searching' (with + pagination) modules, so finding content can be achieved + easily. + + The content list is organized in articles. Each article is + organized in categories and described through the following + fields: + + id: (Required) A unique numerical value referring the + article identification. This is the value used on + administrative tasks like updating and deleting. + + title: (Required) A few words phrase describing the + content, up to 255 characters. + + author_email: (Required) A string referring the user email + address, up to 255 characters. The user email address + is used as id inside The CentOS User LDAP server, + where user specific information (e.g., surname, + lastname, office, phone, etc.) are stored in. This is + the field that connects the user with the content + he/she produces. + + commit_date: (Required). A string referring the date and + time the author_email published the article for time. + + update_date: (Optional) A string representing the date and + time the author_email updated/revised the article for + last time. + + category: (Required) A number refering the category id the + author_email wrote the article for. + + abstract: (Optional) One or two paragraphs describing the + article content. This information is used to build the + page metadata information. When this value is not + provided no abstract information is displayed in the + page, but the is built + using article's first 255 characters. + + keywords: (Optional) A few words describing the content, + up to 255 characters. This information is used to + build the page metadata information and as source for + `searching' module. When this value is not provided + the title is prepared and used insted as source of + values here. + + The article's content itself is not displayed in the content + list view, but in the detailed view of content. + + """ + output = self.form_search_content() + output += str(cgi.parse()) + return output + + + def page_top(self): + """Returns page top anchor.""" + return self.tag_a({'name':'top'}, [0,1]) + + + def page_header(self): + """Returns page header.""" + return self.tag_div({'id': 'page-header'}, [4,1], self.header, 1) + + + def page_content(self): """Returns page content.""" - return content + return self.tag_div({'id':'content'}, [8,1], self.body, 1) + + + def page_body(self): + """Returns page body.""" + return self.tag_div({'id':'page-body'}, [4,1], self.page_content(), 1) + + + def page_links(self): + """Returns application-specific links.""" + page_links = self.user_links() + return self.tag_div({'id': 'pagelinks'}, [8,1], page_links, 1) + + + def page_footer(self): + """Retruns page footer.""" + return self.tag_div({'id': 'page-footer'}, [4,1], self.credits(), 1) + + + def page_wrap(self): + """Returns page wrap.""" + return self.tag_div({'id': 'wrap'}, [0,1], self.page_header() + self.page_body() + self.page_footer(), 1) def admonition(self, title='Note', subtitle="", content=""): """Returns page admonition. - Arguments: - title: Admonition's title. subtitle: Admonition's subtitle. The value of this argument is @@ -382,16 +552,9 @@ class Layout(xhtml.Strict): def page(self): """Returns page final output.""" - header = self.tag_div({'id': 'page-header'}, [4,1], self.header, 1) - top = self.tag_a({'name':'top'}, [0,1]) - body = self.tag_div({'id':'content'}, [8,1], self.body, 1) - body = self.tag_div({'id':'page-body'}, [4,1], body, 1) - footer = self.tag_div({'id': 'page-footer'}, [4,1], self.credits(), 1) - wrap = self.tag_div({'id': 'wrap'}, [0,1], header + body + footer, 1) - body = self.tag_body('', [0,1], top + wrap) html = self.doctype() html += self.tag_html({'xmlns': 'http://www.w3.org/1999/xhtml', 'dir': 'ltr', - 'lang': str(self.language), 'xml:lang': - str(self.language)}, [0,1], self.metadata() + body) + 'lang': str(self.language), 'xml:lang': str(self.language)}, [0,1], + self.metadata() + self.page_top() + self.page_wrap()) return html