Changeset 8332 for mauRepo


Ignore:
Timestamp:
11/06/12 10:27:19 (7 years ago)
Author:
mnagni
Message:

Defined a better procedure if the DB connection is lost
Defined a very very basic error page

Location:
mauRepo/MolesManager/trunk/src/MolesManager
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/MolesManager/trunk/src/MolesManager/molesSessionMiddleware.py

    r8326 r8332  
    1212from libs.migration.InfodbEPB import InfodbEPBFactory 
    1313from libs.migration.MigrationEPB import MigrationEPBFactory 
     14from sqlalchemy.exc import SQLAlchemyError 
     15from django.core.context_processors import csrf 
     16from django.shortcuts import render_to_response 
    1417 
    1518 
     
    2629     
    2730    def _doInitialization(self): 
     31 
    2832        infoDB = DbManager(INFO_DB_CONNECTION) 
    2933        MolesSessionMiddleware._infodbEPBFactory = InfodbEPBFactory(infoDB) 
     
    4145            interval = MIGRATION_INTERVAL ) 
    4246        MolesSessionMiddleware._epbInitialized = True       
    43          
     47             
    4448        self._migration() #see the note on  MolesSessionMiddleware._migration       
    4549     
     
    6771     
    6872    def process_request(self, request):   
    69         if not MolesSessionMiddleware._epbInitialized: 
    70             self._doInitialization()      
    71  
    72         ''' 
    73             @deprecated: request.moles_session is going to be removed from all GUI-related instances 
    74         ''' 
    75         request.moles3EPB = MolesSessionMiddleware._moles3EPBFactory.createMoles3EPB() 
    76  
     73        try: 
     74            if not MolesSessionMiddleware._epbInitialized: 
     75                self._doInitialization() 
     76                   
     77            request.moles3EPB = MolesSessionMiddleware._moles3EPBFactory.createMoles3EPB()                    
     78        except SQLAlchemyError as ex: 
     79            MolesSessionMiddleware._epbInitialized = False 
     80            return self.process_exception(request, ex) 
    7781 
    7882    def process_response(self, request, response): 
    79         request.moles3EPB.close() 
     83        if hasattr(request, "moles3EPB"):             
     84            request.moles3EPB.close() 
     85             
    8086        return response 
    8187 
    82  
    8388    def process_exception(self, request, exception): 
    84         pass 
    85         """ 
    8689        try: 
    87             session = request.moles_session             
    88         except AttributeError: 
    89             return 
    90         session.rollback() 
    91         session.close() 
    92         """         
     90            c = {} 
     91            c['exception'] = exception 
     92            c.update(csrf(request)) 
     93            return render_to_response('errorTemplate.html', c) 
     94        except SQLAlchemyError as ex: 
     95            MolesSessionMiddleware._epbInitialized = False             
     96         
Note: See TracChangeset for help on using the changeset viewer.