Using StringListProperty efficently in Google App Engine


StringListProperty is a datastore value type that stores list items. Using StringListProperty is very easy:

#!/usr/bin/env python
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext import db

class Page(db.Model):
    title=db.StringProperty(multiline=False)
    keywords=db.StringListProperty()

class MainHandler(webapp.RequestHandler):
    def get(self):
        newpage=Page()
	newpage.title="Suat ATAN's books"
        newpage.keywords=["book","author"]
        newpage.put()

	newpage=Page()
	newpage.title="Suat ATAN's life"
        newpage.keywords=["canada","author"]
        newpage.put()

	newpage=Page()
	newpage.title="Suat ATAN's gusto"
        newpage.keywords=["coffe","pizza"]
        newpage.put()

	pages=Page().all().filter("keywords" = "author")
	for page in pages:
	    print i.title+"--"+i.keywords

def main():
    application = webapp.WSGIApplication([('/', MainHandler)],
                                         debug=True)
    util.run_wsgi_app(application)

if __name__ == '__main__':
    main()

We describe the StringListProperty in Page class and use it directly as newpage.keyword=[“item1″,”item2”]
When we want fetching rows that contains “author” string two rows will shown. Becuase only “Suat ATAN’s book” and “Suat ATAN’s life” pages have this string in its StringListPropery

Reklamlar

Using StringListProperty efficently in Google App Engine


StringListProperty is a datastore value type that stores list items. Using StringListProperty is very easy:

#!/usr/bin/env python
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext import db

class Page(db.Model):
title=db.StringProperty(multiline=False)
keywords=db.StringListProperty()

class MainHandler(webapp.RequestHandler):
def get(self):
newpage=Page()
newpage.title="Suat ATAN's books"
newpage.keywords=["book","author"]
newpage.put()

newpage=Page()
newpage.title="Suat ATAN's life"
newpage.keywords=["canada","author"]
newpage.put()

newpage=Page()
newpage.title="Suat ATAN's gusto"
newpage.keywords=["coffe","pizza"]
newpage.put()

pages=Page().all().filter("keywords" = "author")
for page in pages:
print i.title+"--"+i.keywords

def main():
application = webapp.WSGIApplication([('/', MainHandler)],
debug=True)
util.run_wsgi_app(application)

if __name__ == '__main__':
main()

We describe the StringListProperty in Page class and use it directly as newpage.keyword=[“item1”,“item2”]
When we want fetching rows that contains “author” string two rows will shown. Becuase only “Suat ATAN’s book” and “Suat ATAN’s life” pages have this string in its StringListPropery

A new version of Python template maker


I developed a script early for dressing pages with demanded template here is newer version:

from BeautifulSoup import BeautifulSoup
#Configuration
root="D:/users/suat.atan/Desktop/yenisehrivan/"
cssroot="/htmlres/css/"
jsroot="/htmlres/js/"

class TemplateMaker():
    def generate(self,NUDEPAGE_NAME):
        NUDEPAGE=open(root+"pages/"+NUDEPAGE_NAME+".html").read()
        index=open(root+"pages/index.html").read()
        soup = BeautifulSoup(index)
        head= soup.findAll("head")
        #header
        header_1=soup.findAll("div",id="header")
        #menu
        header_2=soup.findAll("div",id="topmenu")
        #change css
        css=soup.findAll("link",id="maincss")
        css[0]['href']=cssroot+NUDEPAGE_NAME+".css"
        #change js
        js=soup.findAll("script",id="mainjs")
        js[0]['src']=jsroot+NUDEPAGE_NAME+".js"
        HEADER=str(header_1[0])+str(header_2[0])
        HEAD= str(head[0])
        html1="""\n
        """
        html2="""\n
“”” html3=”

\n

\n"
        sign=""
        HTML=html1+HEAD+html2+HEADER+NUDEPAGE+html3
        file =open(root+"pages/gen-"+NUDEPAGE_NAME+".html","w")
        file.write(HTML)
        file.close()
        print "--Generated "+NUDEPAGE_NAME
        return True

tm=TemplateMaker()
tm.generate("detail")

A new version of Python template maker


I developed a script early for dressing pages with demanded template here is newer version:

from BeautifulSoup import BeautifulSoup
#Configuration
root="D:/users/suat.atan/Desktop/yenisehrivan/"
cssroot="/htmlres/css/"
jsroot="/htmlres/js/"

class TemplateMaker():
def generate(self,NUDEPAGE_NAME):
NUDEPAGE=open(root+"pages/"+NUDEPAGE_NAME+".html").read()
index=open(root+"pages/index.html").read()
soup = BeautifulSoup(index)
head= soup.findAll("head")
#header
header_1=soup.findAll("div",id="header")
#menu
header_2=soup.findAll("div",id="topmenu")
#change css
css=soup.findAll("link",id="maincss")
css[0]['href']=cssroot+NUDEPAGE_NAME+".css"
#change js
js=soup.findAll("script",id="mainjs")
js[0]['src']=jsroot+NUDEPAGE_NAME+".js"
HEADER=str(header_1[0])+str(header_2[0])
HEAD= str(head[0])
html1="""n
"""
html2="""n

“”“ html3=”

n

n"
sign=""
HTML=html1+HEAD+html2+HEADER+NUDEPAGE+html3
file =open(root+"pages/gen-"+NUDEPAGE_NAME+".html","w")
file.write(HTML)
file.close()
print "--Generated "+NUDEPAGE_NAME
return True

tm=TemplateMaker()
tm.generate("detail")

Dreamweaver-like html template dressing in Aptana with Python


The best way for dressing multiple page with a single template is Dreamweaver HTML template system. This system is ok but not available in Aptana.  For this problem i coded a simple python script that can launchable under Aptana. This script reading head elements of main page for css and javascript’s after this asks the zero-templated(nude) page name and gets content from zero-templated page and combines template and nude page. After that writing templated page to a html file.

For using this script you must download BeatifulPython script and import it.

from BeautifulSoup import BeautifulSoup
root="D:/users/suat.atan/Desktop/myproject/"
index=open(root+"pages/index.html").read()
soup = BeautifulSoup(index)
head= soup.findAll("head")
HEAD= head[0]
html1=""""""
html2="""""" body_name=raw_input("Template page: (withoyut .html expression)-->") body=open(root+"pages/"+body_name+".html").read() html3=""
HTML=html1+str(HEAD)+html2+body+html3
file =open(root+"pages/new_template.html","w")
file.write(HTML)
file.close()
print "Generated"