Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Going to work on site configurator.

  • Loading branch information...
commit 155091b458ee50f268da4c7800311c46b821add4 1 parent 1e5945e
@livid authored
View
19 backstage.py
@@ -18,15 +18,20 @@
from v2ex.babel import Counter
from v2ex.babel import Section
from v2ex.babel import Node
+from v2ex.babel import Site
from v2ex.babel import SYSTEM_VERSION
from v2ex.babel.security import *
from v2ex.babel.ext.cookies import Cookies
+from v2ex.babel.ua import *
+from v2ex.babel.da import *
class BackstageHomeHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
template_values['member'] = member
@@ -47,7 +52,9 @@ def get(self):
class BackstageNewSectionHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
template_values['member'] = member
@@ -62,7 +69,9 @@ def get(self):
self.redirect('/signin')
def post(self):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
template_values['member'] = member
@@ -159,7 +168,9 @@ def post(self):
class BackstageSectionHandler(webapp.RequestHandler):
def get(self, section_name):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
if (member):
@@ -187,7 +198,9 @@ def get(self, section_name):
class BackstageNewNodeHandler(webapp.RequestHandler):
def get(self, section_name):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
if (member):
@@ -207,7 +220,9 @@ def get(self, section_name):
self.redirect('/signin')
def post(self, section_name):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
if (member):
@@ -313,7 +328,9 @@ def post(self, section_name):
class BackstageNodeHandler(webapp.RequestHandler):
def get(self, node_name):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
if (member):
@@ -354,7 +371,9 @@ def get(self, node_name):
self.redirect('/signin')
def post(self, node_name):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
if (member):
View
8 feed.py
@@ -24,12 +24,14 @@ def head(self):
self.response.out.write('')
def get(self):
+ site = GetSite()
output = memcache.get('feed_index')
if output is None:
template_values = {}
- template_values['site_domain'] = 'www.v2ex.com'
- template_values['site_name'] = 'V2EX'
- template_values['site_slogan'] = 'way to explore'
+ template_values['site'] = site
+ template_values['site_domain'] = site.domain
+ template_values['site_name'] = site.title
+ template_values['site_slogan'] = site.slogan
template_values['feed_url'] = 'http://' + template_values['site_domain'] + '/index.xml'
template_values['site_updated'] = datetime.datetime.now()
q = db.GqlQuery("SELECT * FROM Topic ORDER BY created DESC LIMIT 10")
View
2  mail.py
@@ -25,7 +25,7 @@ def extract_address(raw):
class MailHandler(InboundMailHandler):
def receive(self, message):
- bodies = message.bodies(content_type='text/plain')
+ bodies = message.bodies(content_type = 'text/plain')
for body in bodies:
to = extract_address(message.to)
sender = extract_address(message.sender.lower())
View
36 main.py
@@ -246,9 +246,11 @@ def get(self):
self.response.out.write(output)
def post(self):
+ site = GetSite()
browser = detect(self.request)
template_values = {}
- template_values['page_title'] = u'V2EX › 登入'
+ template_values['site'] = site
+ template_values['page_title'] = site.title + u' › 登入'
template_values['system_version'] = SYSTEM_VERSION
u = self.request.get('u').strip()
p = self.request.get('p').strip()
@@ -278,13 +280,15 @@ def post(self):
class SignupHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
chtml = captcha.displayhtml(
public_key = config.recaptcha_public_key,
use_ssl = False,
error = None)
browser = detect(self.request)
template_values = {}
- template_values['page_title'] = u'V2EX › 注册'
+ template_values['site'] = site
+ template_values['page_title'] = site.title + u' › 注册'
template_values['system_version'] = SYSTEM_VERSION
template_values['errors'] = 0
template_values['captchahtml'] = chtml
@@ -296,9 +300,11 @@ def get(self):
self.response.out.write(output)
def post(self):
+ site = GetSite()
browser = detect(self.request)
template_values = {}
- template_values['page_title'] = u'V2EX › 注册'
+ template_values['site'] = site
+ template_values['page_title'] = site.title + u' › 注册'
template_values['system_version'] = SYSTEM_VERSION
errors = 0
# Verification: username
@@ -437,9 +443,11 @@ def post(self):
class SignoutHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
browser = detect(self.request)
template_values = {}
- template_values['page_title'] = u'V2EX › 登出'
+ template_values['site'] = site
+ template_values['page_title'] = site.title + u' › 登出'
template_values['system_version'] = SYSTEM_VERSION
cookies = Cookies(self, max_age = 86400, path = '/')
del cookies['auth']
@@ -452,23 +460,27 @@ def get(self):
class ForgotHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
browser = detect(self.request)
template_values = {}
+ template_values['site'] = site
member = CheckAuth(self)
if member:
template_values['member'] = member
- template_values['page_title'] = u'V2EX › 重新设置密码'
+ template_values['page_title'] = site.title + u' › 重新设置密码'
path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'forgot.html')
output = template.render(path, template_values)
self.response.out.write(output)
def post(self):
+ site = GetSite()
browser = detect(self.request)
template_values = {}
+ template_values['site'] = site
member = CheckAuth(self)
if member:
template_values['member'] = member
- template_values['page_title'] = u'V2EX › 重新设置密码'
+ template_values['page_title'] = site.title + u' › 重新设置密码'
# Verification: username & email
username = self.request.get('username').strip().lower()
email = self.request.get('email').strip().lower()
@@ -516,7 +528,9 @@ def post(self):
class PasswordResetHandler(GenericHandler):
def get(self, token):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
token = str(token.strip().lower())
q = db.GqlQuery("SELECT * FROM PasswordResetToken WHERE token = :1 AND valid = 1", token)
if q.count() == 1:
@@ -532,7 +546,9 @@ def get(self, token):
self.response.out.write(output)
def post(self, token):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
token = str(token.strip().lower())
q = db.GqlQuery("SELECT * FROM PasswordResetToken WHERE token = :1 AND valid = 1", token)
if q.count() == 1:
@@ -578,9 +594,11 @@ def post(self, token):
class NodeHandler(webapp.RequestHandler):
def get(self, node_name):
+ site = GetSite()
browser = detect(self.request)
self.session = Session()
template_values = {}
+ template_values['site'] = site
template_values['rnd'] = random.randrange(1, 100)
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
@@ -677,9 +695,11 @@ def get(self, node_name):
class NodeApiHandler(webapp.RequestHandler):
def get(self, node_name):
+ site = GetSite()
node = GetKindByName('Node', node_name)
if node:
template_values = {}
+ template_values['site'] = site
template_values['node'] = node
path = os.path.join(os.path.dirname(__file__), 'tpl', 'api', 'node.json')
self.response.headers['Content-type'] = 'application/json;charset=UTF-8'
@@ -690,12 +710,14 @@ def get(self, node_name):
class SearchHandler(webapp.RequestHandler):
def get(self, q):
+ site = GetSite()
q = urllib.unquote(q)
template_values = {}
+ template_values['site'] = site
member = CheckAuth(self)
if member:
template_values['member'] = member
- template_values['page_title'] = 'V2EX › 搜索 ' + q
+ template_values['page_title'] = site.title + ' › 搜索 ' + q
template_values['q'] = q
if config.fts_enabled is not True:
path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'search_unavailable.html')
View
29 member.py
@@ -35,9 +35,11 @@
class MemberHandler(webapp.RequestHandler):
def get(self, member_username):
+ site = GetSite()
browser = detect(self.request)
self.session = Session()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
template_values['member'] = member
@@ -49,7 +51,7 @@ def get(self, member_username):
one = GetMemberByUsername(member_username)
if one is not False:
template_values['one'] = one
- template_values['page_title'] = u'V2EX' + one.username
+ template_values['page_title'] = site.title + u'' + one.username
if one is not False:
q2 = db.GqlQuery("SELECT * FROM Topic WHERE member_num = :1 ORDER BY created DESC LIMIT 10", one.num)
template_values['topics'] = q2
@@ -97,14 +99,16 @@ def get(self, member_username):
class MemberApiHandler(webapp.RequestHandler):
def get(self, member_username):
+ site = GetSite()
one = GetMemberByUsername(member_username)
if one:
if one.avatar_mini_url:
if (one.avatar_mini_url[0:1] == '/'):
- one.avatar_mini_url = 'http://v2ex.appspot.com' + one.avatar_mini_url
- one.avatar_normal_url = 'http://v2ex.appspot.com' + one.avatar_normal_url
- one.avatar_large_url = 'http://v2ex.appspot.com' + one.avatar_large_url
+ one.avatar_mini_url = 'http://' + site.domain + one.avatar_mini_url
+ one.avatar_normal_url = 'http://' + site.domain + one.avatar_normal_url
+ one.avatar_large_url = 'http://' + site.domain + one.avatar_large_url
template_values = {}
+ template_values['site'] = site
template_values['one'] = one
path = os.path.join(os.path.dirname(__file__), 'tpl', 'api', 'member.json')
self.response.headers['Content-type'] = 'application/json;charset=UTF-8'
@@ -116,10 +120,12 @@ def get(self, member_username):
class SettingsHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
browser = detect(self.request)
self.session = Session()
template_values = {}
- template_values['page_title'] = u'V2EX › 设置'
+ template_values['site'] = site
+ template_values['page_title'] = site.title + u' › 设置'
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
if (member):
@@ -177,9 +183,10 @@ def get(self):
self.redirect('/signin')
def post(self):
+ site = GetSite()
browser = detect(self.request)
template_values = {}
- template_values['page_title'] = u'V2EX › 设置'
+ template_values['page_title'] = site.title + u' › 设置'
template_values['system_version'] = SYSTEM_VERSION
errors = 0
member = CheckAuth(self)
@@ -371,10 +378,12 @@ def post(self):
class SettingsPasswordHandler(webapp.RequestHandler):
def post(self):
+ site = GetSite()
browser = detect(self.request)
self.session = Session()
template_values = {}
- template_values['page_title'] = u'V2EX › 密码设置'
+ template_values['site'] = site
+ template_values['page_title'] = site.title + u' › 密码设置'
template_values['system_version'] = SYSTEM_VERSION
errors = 0
member = CheckAuth(self)
@@ -426,10 +435,12 @@ def post(self):
class SettingsAvatarHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
self.session = Session()
browser = detect(self.request)
template_values = {}
- template_values['page_title'] = u'V2EX › 头像'
+ template_values['site'] = site
+ template_values['page_title'] = site.title + u' › 头像'
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
if (member):
@@ -447,9 +458,11 @@ def get(self):
self.redirect('/signin')
def post(self):
+ site = GetSite()
self.session = Session()
browser = detect(self.request)
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
if (member):
View
21 notes.py
@@ -22,6 +22,7 @@
from v2ex.babel import Topic
from v2ex.babel import Reply
from v2ex.babel import Note
+from v2ex.babel import Site
from v2ex.babel import SYSTEM_VERSION
@@ -33,10 +34,12 @@
class NotesHomeHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
browser = detect(self.request)
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
- template_values['page_title'] = 'V2EX › 记事本'
+ template_values['page_title'] = site.title + u' › 记事本'
member = CheckAuth(self)
if member:
template_values['member'] = member
@@ -59,9 +62,11 @@ def get(self):
class NotesNewHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
- template_values['page_title'] = 'V2EX › 新建记事'
+ template_values['page_title'] = site.title + u' › 新建记事'
member = CheckAuth(self)
if member:
template_values['member'] = member
@@ -72,9 +77,11 @@ def get(self):
self.redirect('/signin')
def post(self):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
- template_values['page_title'] = 'V2EX › 新建记事'
+ template_values['page_title'] = site.title + u' › 新建记事'
member = CheckAuth(self)
if member:
template_values['member'] = member
@@ -120,8 +127,10 @@ def post(self):
class NotesItemHandler(webapp.RequestHandler):
def get(self, num):
+ site = GetSite()
browser = detect(self.request)
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
member = CheckAuth(self)
if member:
@@ -147,7 +156,9 @@ def get(self, num):
class NotesItemEraseHandler(webapp.RequestHandler):
def get(self, num):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
template_values['page_title'] = 'V2EX › 记事本'
member = CheckAuth(self)
@@ -167,7 +178,9 @@ def get(self, num):
class NotesItemEditHandler(webapp.RequestHandler):
def get(self, num):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
template_values['page_title'] = 'V2EX › 记事本 › 编辑'
member = CheckAuth(self)
@@ -189,7 +202,9 @@ def get(self, num):
self.redirect('/signin')
def post(self, num):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['system_version'] = SYSTEM_VERSION
template_values['page_title'] = 'V2EX › 记事本'
member = CheckAuth(self)
View
21 page.py
@@ -17,6 +17,7 @@
from v2ex.babel import Node
from v2ex.babel import Topic
from v2ex.babel import Reply
+from v2ex.babel import Site
from v2ex.babel.security import *
from v2ex.babel.ua import *
@@ -27,7 +28,9 @@
class AboutHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['rnd'] = random.randrange(1, 100)
note = GetKindByNum('Note', 127)
if note is False:
@@ -36,14 +39,16 @@ def get(self):
member = CheckAuth(self)
if member:
template_values['member'] = member
- template_values['page_title'] = u'V2EX › About'
+ template_values['page_title'] = site.title + u' › About'
path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'about.html')
output = template.render(path, template_values)
self.response.out.write(output)
class FAQHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['rnd'] = random.randrange(1, 100)
note = GetKindByNum('Note', 195)
if note is False:
@@ -52,14 +57,16 @@ def get(self):
member = CheckAuth(self)
if member:
template_values['member'] = member
- template_values['page_title'] = u'V2EX › FAQ'
+ template_values['page_title'] = site.title + u' › FAQ'
path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'faq.html')
output = template.render(path, template_values)
self.response.out.write(output)
class MissionHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['rnd'] = random.randrange(1, 100)
note = GetKindByNum('Note', 240)
if note is False:
@@ -68,31 +75,35 @@ def get(self):
member = CheckAuth(self)
if member:
template_values['member'] = member
- template_values['page_title'] = u'V2EX › Mission'
+ template_values['page_title'] = site.title + u' › Mission'
path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'mission.html')
output = template.render(path, template_values)
self.response.out.write(output)
class AdvertiseHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['rnd'] = random.randrange(1, 100)
member = CheckAuth(self)
if member:
template_values['member'] = member
- template_values['page_title'] = u'V2EX › Advertise'
+ template_values['page_title'] = site.title + u' › Advertise'
path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'advertise.html')
output = template.render(path, template_values)
self.response.out.write(output)
class AdvertisersHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['rnd'] = random.randrange(1, 100)
member = CheckAuth(self)
if member:
template_values['member'] = member
- template_values['page_title'] = u'V2EX › Advertisers'
+ template_values['page_title'] = site.title + u' › Advertisers'
path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'advertisers.html')
output = template.render(path, template_values)
self.response.out.write(output)
View
3  place.py
@@ -36,7 +36,9 @@
class PlaceHandler(webapp.RequestHandler):
def get(self, ip):
+ site = GetSite()
template_values = {}
+ template_values['site'] = site
template_values['rnd'] = random.randrange(1, 100)
member = CheckAuth(self)
if member:
@@ -80,6 +82,7 @@ def get(self, ip):
self.response.out.write(output)
def post(self, ip):
+ site = GetSite()
if 'Referer' in self.request.headers:
go = self.request.headers['Referer']
else:
View
16 t.py
@@ -144,13 +144,15 @@ def get(self):
class TwitterHomeHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
member = CheckAuth(self)
if member:
if member.twitter_oauth == 1:
template_values = {}
+ template_values['site'] = site
template_values['rnd'] = random.randrange(1, 100)
template_values['member'] = member
- template_values['page_title'] = u'V2EX › Twitter › Home'
+ template_values['page_title'] = site.title + u' › Twitter › Home'
access_token = OAuthToken.from_string(member.twitter_oauth_string)
twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
rate_limit = memcache.get(str(member.twitter_id) + '::rate_limit')
@@ -184,13 +186,15 @@ def get(self):
class TwitterMentionsHandler(webapp.RequestHandler):
def get(self):
+ site = GetSite()
member = CheckAuth(self)
if member:
if member.twitter_oauth == 1:
template_values = {}
+ template_values['site'] = site
template_values['rnd'] = random.randrange(1, 100)
template_values['member'] = member
- template_values['page_title'] = u'V2EX › Twitter › Mentions'
+ template_values['page_title'] = site.title + u' › Twitter › Mentions'
access_token = OAuthToken.from_string(member.twitter_oauth_string)
twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
rate_limit = memcache.get(str(member.twitter_id) + '::rate_limit')
@@ -225,12 +229,14 @@ def get(self):
class TwitterDMInboxHandler(webapp.RequestHandler):
def get(self):
member = CheckAuth(self)
+ site = GetSite()
if member:
if member.twitter_oauth == 1:
template_values = {}
+ template_values['site'] = site
template_values['rnd'] = random.randrange(1, 100)
template_values['member'] = member
- template_values['page_title'] = u'V2EX › Twitter › Direct Messages › Inbox'
+ template_values['page_title'] = site.title + u' › Twitter › Direct Messages › Inbox'
access_token = OAuthToken.from_string(member.twitter_oauth_string)
twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
rate_limit = memcache.get(str(member.twitter_id) + '::rate_limit')
@@ -263,13 +269,15 @@ def get(self):
class TwitterUserTimelineHandler(webapp.RequestHandler):
def get(self, screen_name):
+ site = GetSite()
member = CheckAuth(self)
if member:
if member.twitter_oauth == 1:
template_values = {}
+ template_values['site'] = site
template_values['rnd'] = random.randrange(1, 100)
template_values['member'] = member
- template_values['page_title'] = u'V2EX › Twitter › ' + screen_name
+ template_values['page_title'] = site.title + u' › Twitter › ' + screen_name
template_values['screen_name'] = screen_name
access_token = OAuthToken.from_string(member.twitter_oauth_string)
twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, access_token)
View
3  v2ex/babel/__init__.py
@@ -160,5 +160,6 @@ class Checkin(db.Model):
class Site(db.Model):
num = db.IntegerProperty(required=False, indexed=True)
title = db.StringProperty(required=False, indexed=False)
+ slogan = db.StringProperty(required=False, indexed=False)
description = db.TextProperty(required=False)
- url = db.StringProperty(required=False, indexed=False)
+ domain = db.StringProperty(required=False, indexed=False)
View
3  v2ex/babel/da/__init__.py
@@ -129,7 +129,8 @@ def GetSite():
site = Site()
site.num = 1
site.title = 'V2EX'
- site.url = 'v2ex.appspot.com'
+ site.domain = 'v2ex.appspot.com'
+ site.slogan = 'way to explore'
site.description = ''
site.put()
memcache.set('site', site, 86400)
Please sign in to comment.
Something went wrong with that request. Please try again.