Permalink
Browse files

Going to work on site configurator.

  • Loading branch information...
1 parent 1e5945e commit 155091b458ee50f268da4c7800311c46b821add4 @livid committed Aug 24, 2010
Showing with 128 additions and 33 deletions.
  1. +19 −0 backstage.py
  2. +5 −3 feed.py
  3. +1 −1 mail.py
  4. +29 −7 main.py
  5. +21 −8 member.py
  6. +18 −3 notes.py
  7. +16 −5 page.py
  8. +3 −0 place.py
  9. +12 −4 t.py
  10. +2 −1 v2ex/babel/__init__.py
  11. +2 −1 v2ex/babel/da/__init__.py
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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):
Oops, something went wrong.

0 comments on commit 155091b

Please sign in to comment.