node.py :  » Wiki » Cloud-Wiki » cloudwiki-2.1 » cloud_wiki » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Wiki » Cloud Wiki 
Cloud Wiki » cloudwiki 2.1 » cloud_wiki » node.py
# Copyright (C) 2004 Scott W. Dunlop <sdunlop at users.sourceforge.net>
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

from urllib import quote_plus
from urllib import unquote_plus
from weakref import WeakValueDictionary
from sets import Set
from cStringIO import StringIO

from errors import *
from html import parse_hazeml,normalize,htmlquote

import time
class Node( object ):
    __slots__ = ( 
        'wiki', 
        'key', 'content', 'creation', 'modification', 'creator', 'modifier',
        'contentHtml', 'contentLinks'
    )
    
    DefaultContent = "This node has not been written, yet."
    
    def __init__( 
        self, wiki, key, content = None, 
        creation = None, creator = '',  
        modification = None, modifier = '', 
    ):
        self.wiki = wiki
        self.key = key
        
        self.content = content
        self.contentHtml = None
        self.contentLinks = None

        self.creation = creation
        self.creator = creator
        
        self.modification = modification
        self.modifier = modifier
    
    def getCreation( self ):
        return self.creation
        
    def getModification( self ):
        return self.modification
        
    def getCreator( self ):
        return self.creator
        
    def getModifier( self ):
        return self.modifier
             
    def getReferences( self ):
        return self.getDatabase().fetchReferencesTo( self.getKey() )
        
    def getKey( self ):
        return self.key
    
    def getWiki( self ):
        return self.wiki
        
    def getDatabase( self ):
        return self.getWiki().getDatabase()
        
    def getContent( self ):
        return self.content
    
    def setContent( self, content, user = '' ):
        if self.content == content: return
        
        if self.content is None:
            if content: self.contentCreated( content, user )
        else:
            self.contentHtml = None
            self.contentLinks = None
    
            self.contentChanged( content, user )
        
    def contentCreated( self, newContent, user = '' ):
        db = self.getDatabase()

        self.creator = user
        self.creation = db.getServerTime()
        
        self.content = newContent
        db.nodeContentCreated( self )
        
    def contentChanged( self, newContent, user = '' ):
        db = self.getDatabase()
        time = db.getServerTime()
        oldContent = self.content

        self.modifier = user
        self.modification = time
        self.content = newContent

        self.parseContent( )

        db.nodeContentChanged( self, oldContent )
                
    def parseContent( self, content = None, static = False ):
        content = self.content  #TODO: Why is this here?
        if content:    
            self.contentHtml, self.contentLinks = parse_hazeml( 
                self.getWiki(), content, static = static
            )
        else:
            self.contentHtml = "<i>This node has no content.</i>"
            self.contentLinks = []
    
    def setModification( self, modification, modifier = '' ):
        self.modification = modification
        self.modifier = modifier
        
    def getContentHtml( self, static = False ):
        if static:
            self.parseContent( static = static )
        elif self.contentHtml is None: 
            if self.getContent() is not None:
                self.contentHtml = self.getDatabase().fetchHtml( 
                    self.getKey() 
                )
            
            if self.contentHtml is None:
                self.parseContent( static = static )
                
        return self.contentHtml
    
    def getStaticPage( self ):
        "Used to generate static html pages from a node."

        result = StringIO()
        title = htmlquote( self.getKey() )

        result.write( '<?xml version="1.0" encoding="UTF-8"?>\n' )
        result.write( '<!DOCTYPE\n' )
        result.write( ' html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n' )
        result.write( ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n' )
        result.write( '<html\n ' )
        result.write( ' xmlns="http://www.w3.org/1999/xhtml"\n' )
        result.write( ' xml:lang="en"><head>\n' )

        result.write( '<title>' )
        result.write( title )
        result.write( '</title>\n' )

        result.write( '<link\n' )
        result.write( ' rel="stylesheet"\n' )
        result.write( ' href="style.css"\n' )
        result.write( ' type="text/css" />\n' )
        result.write( '</head><body><div>\n' )

        result.write( '<h2>' )
        result.write( title )
        result.write( '</h2>\n' )

        result.write( self.getContentHtml( static = True ) )

        result.write( '</div></body></html>\n' )

        return result.getvalue()

    def getContentLinks( self ):
        if self.contentLinks is None: self.parseContent()
        return self.contentLinks
    
    def getChanges( self, cutoff = 259200 ): # Defaults to 72 hours.
        return self.getDatabase().getChanges( self.getKey(), cutoff )
        
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.