def add_notification (self, noti) : notifications = GTW.Notification_Collection (self.session) if notifications is not None : if not isinstance (noti, GTW.Notification) : noti = GTW.Notification (noti) notifications.append (noti) self.notifications_added += 1
def _send_notification(self, response, account): response.add_notification \ ( GTW.Notification ( _T ("Activation of account %s successful.") % (account.name, ) ) )
def indicate_notifications (self) : added = self.notifications_added if added : notifications = GTW.Notification_Collection (self.session) if len (notifications) : ### `notifications` got disgorged ### -> this response contains embedded notifications ### -> clear the Etag and the last_modified to prevent caching self.set_etag ("") self.last_modified = datetime.datetime.utcfromtimestamp (0)
def _response_body(self, resource, request, response): req_data = request.req_data top = resource.top self.errors = Errors() username = self.get_username(request, "username") self.get_account \ (resource, username, getattr (top, "DEBUG", False)) if not self.account and not self.errors: self.errors [None].append \ (_T ("Account could not be found")) if self.errors: response.errors = self.errors result = resource.GET ()._response_body \ (resource, request, response) return result else: Auth = top.scope.GTW.OMP.Auth account = self.account host = request.host next = request.referrer or "/" passwd, token = Auth.Account.reset_password(account) link = resource.parent.href_action(account, token, request) top.scope.commit() resource.send_email \ ( resource.email_template , email_to = username , email_subject = ( _T ("Password reset for user %s on website %s") % (username, host) ) , email_from = resource.email_from , new_password = passwd , link = link , NAV = top , page = resource , host = host ) response.add_notification \ ( GTW.Notification (_T ( "The reset password instructions have been " "sent to your email address %s." ) % (username, ) ) ) raise top.Status.See_Other(next)
def _send_notification(self, response, account): response.add_notification \ (GTW.Notification (_T ("The password has been changed."))) try: request = response._request self.send_email \ ( self.new_password_template , NAV = self.top , account_name = account.name , email_from = self.email_from , email_subject = _T \ ("Password change for account %s" % (account.name, )) , email_to = account.name , host = request.host , page = self , request = request ) except Exception as exc: logging.exception("Exception during Change-Password")
def __call__(self, resource, request, response): Status = resource.Status language = resource.language with TFL.I18N.context(language): next = request.req_data.get("next", request.referrer) choice = TFL.I18N.Config.choice if language.startswith(choice[0]): request.use_language(choice) response.set_cookie("language", language, max_age=1 << 31) response.add_notification \ ( GTW.Notification (_T (u"Language %s selected") % language) ) else: logging.error \ ( "%s: request for language %r; " "I18N.context returned %r" % (resource.abs_href, language, choice) ) raise Status.See_Other(next) raise Status.Not_Found()
def _response_body(self, resource, request, response): req_data = request.req_data top = resource.top HTTP_Status = top.Status ETM = top.account_manager account = ETM.pid_query(req_data["p"]) action = top.scope.GTW.OMP.Auth._Account_Token_Action_.query \ (account = account, token = req_data ["t"]).first () if action: try: description = action.description next = action.handle(resource) if description: response.add_notification \ ( GTW.Notification (" ".join (( _T (description), account.name))) ) raise HTTP_Status.See_Other(next) except GTW.OMP.Auth.Action_Expired: action.destroy() top.scope.commit() raise HTTP_Status.Not_Found()
# -*- coding: utf-8 -*- # Copyright (C) 2009 Mag. Christian Tanzer All rights reserved # Glasauergasse 32, A--1130 Wien, Austria. [email protected] # **************************************************************************** # # This module is licensed under the terms of the BSD 3-Clause License # <http://www.c-tanzer.at/license/bsd_3c.html>. # **************************************************************************** # #++ # Name # GTW.OMP.__init__ # # Purpose # Package defining Object Model Parts # # Revision Dates # 30-Dec-2009 (CT) Creation # ««revision-date»»··· #-- from _TFL.Package_Namespace import Package_Namespace from _GTW import GTW OMP = Package_Namespace () GTW._Export ("OMP") del Package_Namespace ### __END__ GTW.OMP.__init__
def _response_body(self, resource, request, response): debug = getattr(resource.top, "DEBUG", False) req_data = request.req_data top = resource.top HTTP_Status = top.Status self.errors = Errors() old_email, _ = self._credentials_validation \ (resource, request, debug = debug) new_email = self.get_email(request) if not self.errors: account = self.account next = req_data.get("next", "/") host = request.host token = account.change_email_prepare(new_email) link = resource.parent.href_action \ (account, token, request) top.scope.commit() subject = \ (_T ( "Confirmation for change of email " "for account %s to %s for website %s" ) % (old_email, new_email, host) ) try: resource.send_email \ ( resource.new_email_template , NAV = top , email_from = resource.email_from , email_subject = subject , email_to = new_email , host = host , link = link , page = resource ) except Exception as exc: self.errors[None].append(str(exc)) else: response.add_notification \ ( GTW.Notification (_T ( "A confirmation email has been sent to " "the new email address %s." ) % (new_email, ) ) ) try: resource.send_email \ ( resource.old_email_template , NAV = top , email_from = resource.email_from , email_subject = subject , email_to = old_email , host = host , new_email = new_email , old_email = old_email , page = resource , request = request ) except Exception as exc: logging.exception("Exception during Change-Email") raise HTTP_Status.See_Other(next) response.errors = self.errors response.account = self.account result = resource.GET ()._response_body \ (resource, request, response) return result
# Copyright (C) 2014 Mag. Christian Tanzer. All rights reserved # Glasauergasse 32, A--1130 Wien, Austria. [email protected] # **************************************************************************** # This package is part of the package GTW. # # This module is licensed under the terms of the BSD 3-Clause License # <http://www.c-tanzer.at/license/bsd_3c.html>. # **************************************************************************** # #++ # Name # GTW.MF3.__init__ # # Purpose # Package providing support for MOM forms, 3rd edition # # Revision Dates # 24-Apr-2014 (CT) Creation # ««revision-date»»··· #-- from _TFL.Package_Namespace import Package_Namespace from _GTW import GTW MF3 = Package_Namespace() GTW._Export("MF3") del Package_Namespace ### __END__ GTW.MF3.__init__
# Copyright (C) 2007-2010 Martin Glück. All rights reserved # Langstrasse 4, A--2244 Spannberg, Austria. [email protected] # **************************************************************************** # # This module is licensed under the terms of the BSD 3-Clause License # <http://www.c-tanzer.at/license/bsd_3c.html>. # **************************************************************************** # #++ # Name # GTW.Werkzeug.__init__ # # Purpose # Some wrappers/extensions to the werkzeug WSGI utilities # (werkzeug.pocoo.org) # # Revision Dates # 20-Mar-2010 (MG) Creation # ««revision-date»»··· #-- from _TFL.Package_Namespace import Package_Namespace from _GTW import GTW Werkzeug = Package_Namespace () GTW._Export ("Werkzeug") del Package_Namespace ### __END__ GTW.Werkzeug.__init__
def cook (self, value, cao = None) : if not value : value = self._default m = GTW._Import_Module ("_" + value) result = getattr (m, value) return result
return getattr(self.__super, name) return self.get(name) # end def __getattr__ def __getitem__(self, key): return self._data[key] # end def __getitem__ def __setattr__(self, name, value): if name in self._non_data_attrs: return self.__super.__setattr__(name, value) else: self._data[name] = value return value # end def __setattr__ def __setitem__(self, key, value): self._data[key] = value # end def __setitem__ # end class Session if __name__ != "__main__": GTW._Export("Session") ### __END__ GTW.Session
# Copyright (C) 2007-2010 Martin Glück. All rights reserved # Langstrasse 4, A--2244 Spannberg, Austria. [email protected] # **************************************************************************** # # This module is licensed under the terms of the BSD 3-Clause License # <http://www.c-tanzer.at/license/bsd_3c.html>. # **************************************************************************** # #++ # Name # GTW.Werkzeug.__init__ # # Purpose # Some wrappers/extensions to the werkzeug WSGI utilities # (werkzeug.pocoo.org) # # Revision Dates # 20-Mar-2010 (MG) Creation # ««revision-date»»··· #-- from _TFL.Package_Namespace import Package_Namespace from _GTW import GTW Werkzeug = Package_Namespace() GTW._Export("Werkzeug") del Package_Namespace ### __END__ GTW.Werkzeug.__init__
# Copyright (C) 2012 Mag. Christian Tanzer. All rights reserved # Glasauergasse 32, A--1130 Wien, Austria. [email protected] # **************************************************************************** # This package is part of the package GTW. # # This module is licensed under the terms of the BSD 3-Clause License # <http://www.c-tanzer.at/license/bsd_3c.html>. # **************************************************************************** # #++ # Name # GTW.RST.__init__ # # Purpose # Framework for RESTful web services # # Revision Dates # 6-Jun-2012 (CT) Creation # ««revision-date»»··· #-- from _TFL.Package_Namespace import Package_Namespace from _GTW import GTW RST = Package_Namespace () GTW._Export ("RST") del Package_Namespace ### __END__ GTW.RST.__init__
def fake_request (** kw) : return Record \ ( req_data = GTW.Request_Data (kw) , req_data_list = GTW.Request_Data_List (kw) )
# Copyright (C) 2012 Mag. Christian Tanzer. All rights reserved # Glasauergasse 32, A--1130 Wien, Austria. [email protected] # **************************************************************************** # This package is part of the package GTW. # # This module is licensed under the terms of the BSD 3-Clause License # <http://www.c-tanzer.at/license/bsd_3c.html>. # **************************************************************************** # #++ # Name # GTW.RST.__init__ # # Purpose # Framework for RESTful web services # # Revision Dates # 6-Jun-2012 (CT) Creation # ««revision-date»»··· #-- from _TFL.Package_Namespace import Package_Namespace from _GTW import GTW RST = Package_Namespace() GTW._Export("RST") del Package_Namespace ### __END__ GTW.RST.__init__
def FO (self) : return GTW.FO (self.obj, self.top.encoding)
, cao = cao , cmd = cao ### backwards compatibility , passive = passive , prefix = prefix , root = pbl.path (root) ) result.selected = getattr (result, atv, atv) result.app_dir = sos.path.normpath \ (pjoin (result.prefix, result.selected, cao.app_dir)) result.py_path = pbl.env ["PYTHONPATH"] = self._python_path (result) result.lib_dirs = result.py_path.split (":") result.python = pbl [cao.py_path] \ [tuple (o for o in cao.py_options if o)] result.dirs = [result.app_dir] + result.lib_dirs return result # end def _P def _python_path (self, P, version = None) : if version is None : version = P.cao.apply_to_version return ":".join (pjoin (P.prefix, version, p) for p in P.cao.lib_dir) # end def _python_path Command = GTWD_Command # end class if __name__ != "__main__" : GTW._Export_Module () if __name__ == "__main__" : Command () () ### __END__ GTW.deploy
def cook(self, value, cao=None): if not value: value = self._default m = GTW._Import_Module("_" + value) result = getattr(m, value) return result
def __init__ (self, obj, parent) : self.obj = obj self.parent = parent self.top = parent.top self.FO = GTW.FO (obj, parent.top.encoding)
try : with Locked_File (self.file_name, "rb") as f : cargo = f.read () except Exception as exc : print \ ( ">>> Exception" , exc , "when trying to load session data from" , self.file_name , file = sys.stderr ) else : try : result = cPickle.loads (cargo) except Exception as exc : print \ ( ">>> Exception" , exc , "when trying to unpickle session data from" , self.file_name , file = sys.stderr ) return result # end def _load # end class File_Session if __name__ != "__main__" : GTW._Export ("*") ### __END__ GTW.File_Session
# Copyright (C) 2014 Mag. Christian Tanzer. All rights reserved # Glasauergasse 32, A--1130 Wien, Austria. [email protected] # **************************************************************************** # This package is part of the package GTW. # # This module is licensed under the terms of the BSD 3-Clause License # <http://www.c-tanzer.at/license/bsd_3c.html>. # **************************************************************************** # #++ # Name # GTW.MF3.__init__ # # Purpose # Package providing support for MOM forms, 3rd edition # # Revision Dates # 24-Apr-2014 (CT) Creation # ««revision-date»»··· #-- from _TFL.Package_Namespace import Package_Namespace from _GTW import GTW MF3 = Package_Namespace () GTW._Export ("MF3") del Package_Namespace ### __END__ GTW.MF3.__init__
>>> session3.get ("name"), session.name (None, 'user1') >>> session3.get ("lang"), session.lang (None, None) """ def exists (self, sid) : return sid in _Store_ # end def exists def remove (self) : try : del _Store_ [self.sid] except KeyError : pass # end def remove def save (self) : _Store_ [self.sid] = self._data # end def save def _load (self) : return _Store_.get (self.sid, {}).copy () # end def _load # end class Memory_Session if __name__ != "__main__" : GTW._Export ("*") ### __END__ GTW.Memory_Session
def req_data_list(self): result = GTW.Request_Data_List(self.values) result.files = self.files return result
def __getattr__ (self, name) : if name.startswith ("__") and name.endswith ("__") : ### Placate inspect.unwrap of Python 3.5, ### which accesses `__wrapped__` and eventually throws `ValueError` return getattr (self.__super, name) return self.get (name) # end def __getattr__ def __getitem__ (self, key) : return self._data [key] # end def __getitem__ def __setattr__ (self, name, value) : if name in self._non_data_attrs : return self.__super.__setattr__ (name, value) else : self._data [name] = value return value # end def __setattr__ def __setitem__ (self, key, value) : self._data [key] = value # end def __setitem__ # end class Session if __name__ != "__main__" : GTW._Export ("Session") ### __END__ GTW.Session