Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
5,518 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
*.elc | ||
*.pyc | ||
*~ | ||
*.swp | ||
*.swo | ||
*.bak | ||
*.log | ||
*.svn | ||
.svn | ||
*.nohup | ||
|
||
*.htm.py | ||
*.txt.py | ||
.*.js | ||
.*.css | ||
|
||
*.db | ||
sessions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/python | ||
#coding:utf-8 | ||
|
||
import web | ||
|
||
#for import view and other local module | ||
if __name__!='__main__': | ||
import os | ||
import sys | ||
abspath = os.path.dirname(__file__) | ||
sys.path.append(abspath) | ||
os.chdir(abspath) | ||
|
||
import sys | ||
if sys.getdefaultencoding() != 'utf-8': | ||
reload(sys) | ||
sys.setdefaultencoding('utf-8') | ||
|
||
from view import * | ||
from sqlalchemy.orm import scoped_session, sessionmaker | ||
|
||
def load_sqlalchemy(handler): | ||
web.ctx.orm = scoped_session(sessionmaker(bind=engine)) | ||
try: | ||
return handler() | ||
except web.HTTPError: | ||
web.ctx.orm.commit() | ||
raise | ||
except: | ||
web.ctx.orm.rollback() | ||
raise | ||
finally: | ||
web.ctx.orm.commit() | ||
|
||
|
||
#--- Control settings ---- | ||
urls = ( | ||
'/', 'index', | ||
'/login', 'login', | ||
'/logout', 'logout', | ||
'/events', 'events', | ||
'/event/(\d+)', 'event', | ||
'/articles', 'articles', | ||
'/articles/catalog/(\d+)', 'catalog', | ||
'/articles/catalog/create/(\d+)', 'articles_create', | ||
'/article/(\d+)', 'article_view', | ||
'/article/edit/(\d+)', 'article_edit', | ||
'/article/image/upload/(\d+)', 'article_image_upload', | ||
'/image/delete/(\d+)', 'image_delete', | ||
'/photos', 'photos', | ||
'/photos/year/(\d+)', 'photos_year', | ||
'/photo/(\d+)/(\d+)','photo_view', | ||
'/memories', 'memories', | ||
'/words', 'words', | ||
'/words/create', 'words_create', | ||
'/word/delete/(\d+)', 'word_delete', | ||
'/word/show/(\d+)', 'word_show', | ||
'/word/hide/(\d+)', 'word_hide', | ||
'/vedios', 'vedios', | ||
'/vedio/(\d+)', 'vedio_view', | ||
'/vedio/create', 'vedio_create', | ||
'/vedio/edit/(\d+)', 'vedio_edit', | ||
'/activity/goldencampass', 'activity', | ||
) | ||
|
||
|
||
app = web.application(urls, globals()) | ||
app.add_processor(load_sqlalchemy) | ||
|
||
|
||
#web.config.debug = False | ||
|
||
if __name__!='__main__': | ||
session = web.session.Session(app, web.session.DiskStore(os.path.join(abspath,'sessions')),initializer={'isAdmin':0}) | ||
else: | ||
session = web.session.Session(app, web.session.DiskStore('sessions'),initializer={'isAdmin':0}) | ||
|
||
def session_hook(): | ||
web.ctx.session = session | ||
web.template.Template.globals['session'] = session | ||
|
||
|
||
if __name__ == "__main__": | ||
app.add_processor(web.loadhook(session_hook)) | ||
app.run() | ||
else: | ||
app.add_processor(web.loadhook(session_hook)) | ||
application=app.wsgifunc() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import os | ||
|
||
MAIN_PATH = os.getcwd() | ||
STATIC_PATH = MAIN_PATH + '/static' | ||
PASSWD = '73a21e6a277f2b4c365cfde2fa8e8bb64f566f8eeb8d069dab8a36e0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/python | ||
#coding:utf8 | ||
|
||
import os | ||
import re | ||
|
||
m = re.compile('.*/') | ||
s = m.match(os.getcwd()) | ||
path = s.group(0) | ||
|
||
#path = '/home/tizac/camp/sites/static' | ||
|
||
dirs = ['book', 'icon210', 'img', 'photo', 'vedio_img'] | ||
|
||
for d in dirs: | ||
cmd = 'rm ./static/%s' % (d) | ||
os.system(cmd) | ||
cmd = 'ln -s %sstatic/%s ./static/' % (path, d) | ||
os.system(cmd) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
#!/usr/bin/python | ||
#coding:utf-8 | ||
|
||
import web | ||
import re | ||
import time | ||
|
||
from datetime import datetime | ||
from web.utils import storage | ||
|
||
|
||
from sqlalchemy import create_engine | ||
#engine = create_engine("mysql://tizac:m1y4q5tb@localhost/dongdong?charset=utf8" , echo=False) | ||
engine = create_engine("sqlite:///dongdong.db" , echo=False) | ||
|
||
from sqlalchemy.ext.declarative import declarative_base | ||
Base = declarative_base() | ||
|
||
|
||
from sqlalchemy import Column, Integer, String, DateTime | ||
from sqlalchemy import Table, Text | ||
from sqlalchemy import ForeignKey | ||
from sqlalchemy import and_, or_ | ||
from sqlalchemy.orm import relationship, backref | ||
|
||
|
||
class Word(Base): | ||
__tablename__ = 'Word' | ||
|
||
id = Column(Integer, unique=True, primary_key=True) | ||
title = Column(String(256), nullable=False) | ||
content = Column(Text, nullable=False) | ||
author = Column(String(256), nullable=False) | ||
time = Column(DateTime, nullable=False) | ||
hide = Column(Integer, nullable=False) | ||
|
||
def __init__(self, args): | ||
self.title = args.title | ||
self.content = args.content | ||
self.author = args.author | ||
self.time = datetime.now() | ||
self.hide = 0 | ||
|
||
def __repr__(self): | ||
return "<Word('%r')>" % self.id | ||
|
||
|
||
class Article(Base): | ||
__tablename__ = 'Article' | ||
|
||
id = Column(Integer, unique=True, primary_key=True) | ||
title = Column(String(256), nullable=False) | ||
time = Column(DateTime) | ||
source = Column(String(256)) | ||
content = Column(Text, nullable=False) | ||
catalog_id = Column(Integer, ForeignKey('Catalog.id')) | ||
ishtml = Column(Integer, nullable=False ) | ||
catalog = relationship('Catalog', backref = backref('article', order_by=time)) | ||
|
||
def __init__(self, args): | ||
self.update(args) | ||
|
||
def update(self, args): | ||
self.title = args.title | ||
if args.time: | ||
ttuple = time.strptime(args.time, "%Y-%m-%d") | ||
tdate = datetime(ttuple[0],ttuple[1],ttuple[2]) | ||
self.time = tdate | ||
self.source = args.source | ||
self.content = args.content | ||
try: | ||
c1 = web.ctx.orm.query(Catalog).filter_by(name = args.catalog).one() | ||
except: | ||
c1 = Catalog(args.catalog) | ||
self.catalog = c1 | ||
|
||
def __repr__(self): | ||
return "<Article('%r')>" % self.id | ||
|
||
def content_to_html(self): | ||
#print "%r"%self.content | ||
if self.ishtml==1: | ||
html=self.content | ||
else: | ||
strbr = re.compile(r'\r\n') | ||
html = strbr.sub('<br/>', self.content) | ||
#strspace = re.compile(r' ') | ||
#html = strspace.sub(' ', html) | ||
#html = markdown.markdown(html) | ||
#print html | ||
return html | ||
|
||
|
||
class Catalog(Base): | ||
__tablename__ = 'Catalog' | ||
|
||
id = Column(Integer, unique=True, primary_key=True, autoincrement=True) | ||
name = Column(String(64), nullable=False, unique=True) | ||
weight = Column(Integer, nullable=False ) | ||
channel = Column(Integer, nullable=False ) | ||
|
||
def __init__(self,name): | ||
self.name=name | ||
|
||
def __repr__(self): | ||
return 'Catalog(%r)' % (self.name) | ||
|
||
|
||
class Image(Base): | ||
__tablename__='Image' | ||
|
||
id = Column(Integer, unique=True, primary_key=True, autoincrement=True) | ||
name = Column(String(256), nullable=False, unique=True) | ||
article_id = Column(Integer, ForeignKey('Article.id')) | ||
article = relationship('Article', backref = backref('image')) | ||
|
||
def __init__(self, name, article_id): | ||
self.name = name | ||
a1 = web.ctx.orm.query(Article).filter_by(id = article_id).one() | ||
self.article = a1 | ||
|
||
def __repr__(self): | ||
return 'Image(%r, %r)' % (self.id, self.name) | ||
|
||
|
||
class Photo(Base): | ||
__tablename__='Photo' | ||
|
||
id = Column(Integer, unique=True, primary_key=True, autoincrement=True) | ||
year = Column(Integer) | ||
name = Column(String(256), nullable=False, unique=True) | ||
|
||
|
||
class Vedio(Base): | ||
__tablename__='Vedio' | ||
|
||
id = Column(Integer, unique=True, primary_key=True, autoincrement=True) | ||
#name = Column(String(256), nullable=False, unique=True) | ||
title = Column(String(256), nullable=False, unique=True) | ||
url = Column(String(512), nullable=False, unique=True) | ||
catalog_id = Column(Integer, ForeignKey('Catalog.id')) | ||
catalog = relationship('Catalog', backref = backref('vedio', order_by=title)) | ||
|
||
|
||
|
||
def __init__(self, args): | ||
self.update(args) | ||
|
||
def update(self, args): | ||
self.title= args.title | ||
self.url = args.url | ||
try: | ||
c1 = web.ctx.orm.query(Catalog).filter_by(name = args.catalog).one() | ||
except: | ||
c1 = Catalog(args.catalog) | ||
self.catalog = c1 | ||
|
||
|
||
|
||
#--------------------------------------------------------------------- | ||
|
||
metadata = Base.metadata | ||
|
||
if __name__ == "__main__": | ||
metadata.create_all(engine) | ||
from sqlalchemy.orm import sessionmaker | ||
Session = sessionmaker(bind=engine) | ||
session = Session() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/home/tizac/camp/sites/static/book |
Oops, something went wrong.