Added timezones to user accounts.

This commit is contained in:
Raoul Snyman 2010-03-09 14:18:43 +02:00
parent ea875ca816
commit ea72b9e6e6
5 changed files with 37 additions and 3 deletions

View File

@ -42,6 +42,7 @@ paths.themes = %(here)s/themes
# Security settings # Security settings
security.salt = secretsalt security.salt = secretsalt
# Mail server settings
mail.on = false mail.on = false
mail.manager = immediate mail.manager = immediate
mail.transport = smtp mail.transport = smtp
@ -49,6 +50,9 @@ mail.smtp.server = mail.mydomain.com
mail.smtp.username = mymailusername mail.smtp.username = mymailusername
mail.smtp.password = mymailpassword mail.smtp.password = mymailpassword
# Server-related settings
server.timezone = 'Africa/Johannesburg'
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* # WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
# Debug mode will enable the interactive debugging tool, allowing ANYONE to # Debug mode will enable the interactive debugging tool, allowing ANYONE to
# execute malicious code after an exception is raised. # execute malicious code after an exception is raised.

View File

@ -55,6 +55,25 @@ class AccountController(BaseController):
message=u'You need to supply a valid e-mail address.') message=u'You need to supply a valid e-mail address.')
} }
def index_schema(self):
return {
'account-nick': UnicodeString(not_empty=True,
messages={u'empty': u'You need to type in a nick.'}),
'account-email': Email(not_empty=True,
messages={u'empty': u'You need to supply a valid e-mail address.'})
}
def index_POST(self):
try:
for key, value in c.form_values.iteritems():
setattr(c.current_user, key[8:], value)
Session.add(c.current_user)
Session.commit()
h.flash.set_message(u'Successfully updated your account.', u'success')
except:
h.flash.set_message(u'There was a problem updating your account.', u'error')
h.redirect_to(h.url_for(controller=u'account'))
def register(self): def register(self):
c.page_title = u'Register' c.page_title = u'Register'
return render(u'/account/register.mako') return render(u'/account/register.mako')

View File

@ -25,6 +25,7 @@ from datetime import datetime
from pprint import pformat from pprint import pformat
from sqlalchemy.sql import or_ from sqlalchemy.sql import or_
from pytz import timezone
from scribeengine.lib.base import * from scribeengine.lib.base import *
from scribeengine.lib import utils from scribeengine.lib import utils
@ -170,7 +171,10 @@ class BlogController(BaseController):
def calendar(self, year, month): def calendar(self, year, month):
#c.calendar = Calendar(6) #c.calendar = Calendar(6)
#c.today = datetime.today() #c.today = datetime.today()
c.thismonth = datetime.now().replace(int(year), int(month)) server_tz = timezone(config.get(u'server.timezone', u'UTC'))
user_tz = c.current_user.timezone if c.current_user.timezone else u'UTC'
now = datetime.now(server_tz).astimezone(timezone(user_tz))
c.thismonth = now.replace(int(year), int(month))
c.prev_month = c.thismonth - monthdelta(1) c.prev_month = c.thismonth - monthdelta(1)
c.next_month = c.thismonth + monthdelta(1) c.next_month = c.thismonth + monthdelta(1)
month_start = datetime(c.thismonth.year, c.thismonth.month, 1, 0, 0, 0, 0) month_start = datetime(c.thismonth.year, c.thismonth.month, 1, 0, 0, 0, 0)

View File

@ -39,6 +39,7 @@ from pylons.templating import render_mako
from sqlalchemy.sql.expression import asc, desc from sqlalchemy.sql.expression import asc, desc
from formencode import Schema, Invalid from formencode import Schema, Invalid
from monthdelta import monthdelta from monthdelta import monthdelta
from pytz import timezone
from scribeengine.lib import helpers as h from scribeengine.lib import helpers as h
from scribeengine.lib.validation import jsvalidate from scribeengine.lib.validation import jsvalidate
@ -57,9 +58,11 @@ class BaseController(WSGIController):
c.categories = Session.query(Category).order_by(Category.name.asc()).all() c.categories = Session.query(Category).order_by(Category.name.asc()).all()
c.pages = Session.query(Page).all() c.pages = Session.query(Page).all()
c.calendar = Calendar(6) c.calendar = Calendar(6)
c.today = datetime.today() server_tz = timezone(config.get(u'server.timezone', u'UTC'))
user_tz = c.current_user.timezone if c.current_user.timezone else u'UTC'
c.today = datetime.now(server_tz).astimezone(timezone(user_tz))
if not c.thismonth: if not c.thismonth:
c.thismonth = datetime.now() c.thismonth = c.today #datetime.utcnow().astimezone(timezone(c.current_user.timezone))
c.prev_month = c.thismonth - monthdelta(1) c.prev_month = c.thismonth - monthdelta(1)
c.next_month = c.thismonth + monthdelta(1) c.next_month = c.thismonth + monthdelta(1)
month_start = datetime(c.thismonth.year, c.thismonth.month, 1, 0, 0, 0, 0) month_start = datetime(c.thismonth.year, c.thismonth.month, 1, 0, 0, 0, 0)

View File

@ -30,7 +30,11 @@
<label for="account-timezone">Timezone:</label> <label for="account-timezone">Timezone:</label>
<select name="account-timezone" id="account-timezone" class="form-select"> <select name="account-timezone" id="account-timezone" class="form-select">
% for timezone in c.timezones: % for timezone in c.timezones:
% if c.current_user.timezone == timezone:
<option value="${timezone}" selected="selected">${timezone}</option>
% else:
<option value="${timezone}">${timezone}</option> <option value="${timezone}">${timezone}</option>
% endif
% endfor % endfor
</select> </select>
</div> </div>