import web,re,traceback
urls=(
"/","displaythreads"
"/viewthread","displaythreads",
"/viewthread/(.*)","displaythread",
"/viewthread/(.*)/Vote/(Up|Down)","vote",
"/newthread/(.*)","newthread",
"/newthread","newthread"
)
entries={}###{entryname:{property:value}}
entrylength=0
class displaythreads:
    pass
class newthread:
    template=web.template.frender("newthread.html")
    default=template("DEFAULT",0)
    def initialize():
        pass
    def GET():
        return default
    def POST():
        data = web.input()
        try:
            username,threadname = data.username,data.threadname
        except:
            return template(mode)
        if threadname in entries:
            return template("Exists")
        entries[threadname]={"creator":username,"points":0,"totvotes":0}
class displaythread:
    template=web.template.frender('Thread Viewer Template.html')
    def initialize():
        pass
    def GET(self):
        return self.template(
            entrylength,
            entries.keys(),
            [value['name'] for value in entries.values()]

                      )
class vote:
    template=web.template.frender('vote.html')
    def initialize():
        pass
    def GET(self,thread,vote):
        try:
            current=web.cookies().get("Voted:"+thread)
        except:
            current="BEING DELETED" #act like it is being deleted if its not there.
        ######Set cookies and change votes#########
        ##Removing/Adding an extra vote if it was previously voted the other way##
        if vote=="Up":
            setcookie("Voted:"+thread,"up")
            if current=="down":
                entries[thread]["votes"]+=1
            entries[thread]["votes"]+=1
            id=0
        elif vote=="Down":
            setcookie("Voted:"+thread,"down")
            if current=="up":
                entries[thread]["votes"]-=1
            entries[thread]["votes"]-=1
            id=0
        elif vote=="Remove":
            if current=="up":
                entries[thread]["votes"]-=1
            elif current=="down":
                entries[thread]["votes"]+=1
            setcookie("Voted:"+thread,"BEING DELETED",expires=1)
            id=1
            if current != "BEING DELETED":# if he hasn't already voted, increase the total vote count by 1
                totvotes+=1
        return self.template(vote,id)
#classes = [eval(item) for item,number in enumerate(urls) if number%2==1]
#for i in classes:
    #i.initialize()
app = web.application(urls, globals())
if __name__ == "__main__":
    try:
        app.run()
    except:
        traceback.print_exc()
        input()

web.py latest version from gihub.
Macintosh python 2.7.6 32 bit
It's a forum.
12a0465434da395b02201ddd0667d28f

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.