wdcms / admin.py

# -*- coding: utf-8 -*-
from settings import  *
from model import  collection,content
import logging,os
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template
import yui
from google.appengine.ext import db

class Admin(yui.HtmlRequestHandler):
#    @yui.authorized(False)
    def get(self):
        COLLECTIONS=collection.all()
        template_values = {
        'COLLECTIONS':COLLECTIONS,
        }
        path = os.path.join(os.path.dirname(__file__), 'tpl','admin.html')
        self.write(template.render(path, template_values))
    def post(self):
        delitem=self.request.get_all('delitem')
        for item in delitem:
            try:
                for i in db.get(item).content_set:
                    i.delete()
            except:
                pass
            db.get(item).delete()

        self.redirect('/admin')


class CollectionHandler(yui.RequestHandler):
#    @yui.authorized(False)
    def post(self,flag):
        if flag=="addormodhtml":
            type='html'
            tcontent=self.POST['content']
            head=self.POST['head']
            url=self.POST['url']
            title=self.POST['title']
            examkey=self.POST['examkey']
            if self.POST['header']=="true":
                header=True
            else:
                header=False
            if self.POST['footer']=="true":
                footer=True
            else:
                footer=False
            COLLECTION=db.get(examkey)
            if self.POST["contentkey"]:
                CONTENT=db.get(self.POST["contentkey"])
            else:
                CONTENT=content()
            CONTENT.user=COLLECTION
            CONTENT.time=getCNnow()
            CONTENT.content=tcontent
            CONTENT.head=head
            CONTENT.url=url
            CONTENT.title=title
            CONTENT.type=type
            CONTENT.header=header
            CONTENT.footer=footer
            CONTENT.put()
            if self.POST["contentkey"]:
                self.redirect('/%s/%s'%(COLLECTION.url,CONTENT.url))
                return
    
        elif flag=="addormodcss":
            type='css'
            tcontent=self.POST['content']
            url=self.POST['url']
            title=url
            examkey=self.POST['examkey']
            COLLECTION=db.get(examkey)
            if self.POST["contentkey"]:
                CONTENT=db.get(self.POST["contentkey"])
            else:
                CONTENT=content()
            CONTENT.user=COLLECTION
            CONTENT.time=getCNnow()
            CONTENT.content=tcontent
            CONTENT.head=''
            CONTENT.url=url
            CONTENT.title=title
            CONTENT.type=type
            CONTENT.header=False
            CONTENT.footer=False
            CONTENT.put()
            if self.POST["contentkey"]:
                self.redirect('/%s/%s'%(COLLECTION.url,CONTENT.url))
                return
    

        elif flag=="addcollection":
                url=self.POST['url']
                COLLECTION=collection()
                COLLECTION.url=url
                COLLECTION.time=getCNnow()
                COLLECTION.put()



        self.redirect('/admin')
            

application = yui.WsgiApplication([
    ('/admin', Admin),
    ('/admin/(.*)', CollectionHandler),
])

def main():
    util.run_wsgi_app(application)

if __name__ == '__main__':
    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.