def __init__(self): # Grid initialization super(EditPollsGrid, self).__init__( Poll, Poll.all(joined_attrs=["choices"])) #@UndefinedVariable # Creation of customized date fields to edit the poll dates self.append( create_date_field("formatted_start_dt", "start_dt", DT_FORMAT, today_by_default=True)) self.append( create_date_field("formatted_end_dt", "end_dt", DT_FORMAT, today_by_default=False)) self.append( Field(name="formatted_possible_dates", value=lambda model: "[%s]" % ",".join([ formatting.format_date(dt, DT_FORMAT) for dt in model.possible_dates ]))) # Grid configuration inc = [ TITLE(self.title), FORMATTED_START_DT(self.formatted_start_dt), FORMATTED_END_DT(self.formatted_end_dt), FORMATTED_POSSIBLE_DATES_READONLY(self.formatted_possible_dates) ] self.configure(include=inc)
def POST(self): # Reads the email in the HTTP request parameters email = web.input(email=None).email # Check if the user exists and is active user = User.get_user(email) if user is None or not user.active: raise http.Forbidden("Utilisateur inconnu") # Checks if there is already an active password token matching this email current_password_token = PasswordToken.get_password_token(email) if current_password_token is not None: formatted_creation_dt = formatting.format_date(dates.change_timezone(current_password_token.creation_dt), "%d/%m/%y %H:%M") raise http.Forbidden(u"Demande similaire déjà effectuée le %s" % formatted_creation_dt) # Creates a new password token valid for 2 days password_token = PasswordToken(validity=2, user=user, token=PasswordToken.generate_random_token(16)) config.orm.add(password_token) # Registers an email notification http.register_hook(lambda: notify_via_email(password_token, Events.NEW)) return u"Instructions en cours d'envoi à %s" % email
def POST(self): # Reads the email in the HTTP request parameters email = web.input(email=None).email # Check if the user exists and is active user = User.get_user(email) if user is None or not user.active: raise http.Forbidden("Utilisateur inconnu") # Checks if there is already an active password token matching this email current_password_token = PasswordToken.get_password_token(email) if current_password_token is not None: formatted_creation_dt = formatting.format_date( dates.change_timezone(current_password_token.creation_dt), "%d/%m/%y %H:%M") raise http.Forbidden(u"Demande similaire déjà effectuée le %s" % formatted_creation_dt) # Creates a new password token valid for 2 days password_token = PasswordToken( validity=2, user=user, token=PasswordToken.generate_random_token(16)) config.orm.add(password_token) # Registers an email notification http.register_hook( lambda: notify_via_email(password_token, Events.NEW)) return u"Instructions en cours d'envoi à %s" % email
def test_format_date(self): # Enforces the locale (*nix systems only - we no longer support Windows) locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8") # Testing parameters DATE_FORMAT = "%A %d %B %Y" JULY_15 = datetime.date(2011, 7, 15) AUGUST_15 = datetime.date(2011, 8, 15) DECEMBER_15 = datetime.date(2011, 12, 15) # Checks that French dates are properly formatted formatted_dt = format_date(JULY_15, DATE_FORMAT) self.assertIsInstance(formatted_dt, unicode) self.assertEqual(formatted_dt, u"vendredi 15 juillet 2011") formatted_dt = format_date(AUGUST_15, DATE_FORMAT) self.assertIsInstance(formatted_dt, unicode) self.assertEqual(formatted_dt, u"lundi 15 août 2011") formatted_dt = format_date(DECEMBER_15, DATE_FORMAT) self.assertIsInstance(formatted_dt, unicode) self.assertEqual(formatted_dt, u"jeudi 15 décembre 2011")
def __init__(self): # Grid initialization super(EditPollsGrid, self).__init__(Poll, Poll.all(joined_attrs=["choices"])) #@UndefinedVariable # Creation of customized date fields to edit the poll dates self.append(create_date_field("formatted_start_dt", "start_dt", DT_FORMAT, today_by_default=True)) self.append(create_date_field("formatted_end_dt", "end_dt", DT_FORMAT, today_by_default=False)) self.append( Field( name="formatted_possible_dates", value=lambda model: "[%s]" % ",".join([formatting.format_date(dt, DT_FORMAT) for dt in model.possible_dates]) ) ) # Grid configuration inc = [ TITLE(self.title), FORMATTED_START_DT(self.formatted_start_dt), FORMATTED_END_DT(self.formatted_end_dt), FORMATTED_POSSIBLE_DATES_READONLY(self.formatted_possible_dates) ] self.configure(include=inc)
def value(model): """ Returns the model date or today's date """ default_date = datetime.date.today() if today_by_default else None dt = model and attr_getter(model) or default_date return dt and formatting.format_date(dt, dt_format)