mirror of
				https://github.com/retspen/webvirtcloud
				synced 2025-07-31 12:41:08 +00:00 
			
		
		
		
	Some improvements for appsettings app
This commit is contained in:
		
							parent
							
								
									7eee811e65
								
							
						
					
					
						commit
						bb8f95be14
					
				
					 5 changed files with 43 additions and 3 deletions
				
			
		|  | @ -1,3 +0,0 @@ | |||
| from django.contrib import admin | ||||
| 
 | ||||
| # Register your models here. | ||||
							
								
								
									
										13
									
								
								appsettings/context_processors.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								appsettings/context_processors.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| from .settings import app_settings as settings | ||||
| 
 | ||||
| 
 | ||||
| def app_settings(request): | ||||
|     """ | ||||
|     Simple context processor that puts the config into every\ | ||||
|     RequestContext. Just make sure you have a setting like this:: | ||||
|         TEMPLATE_CONTEXT_PROCESSORS = ( | ||||
|             # ... | ||||
|             'appsettings.context_processors.app_settings', | ||||
|         ) | ||||
|     """ | ||||
|     return {"app_settings": settings} | ||||
							
								
								
									
										10
									
								
								appsettings/middleware.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								appsettings/middleware.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | |||
| from .settings import app_settings, get_settings | ||||
| 
 | ||||
| 
 | ||||
| class AppSettingsMiddleware(object): | ||||
|     def __init__(self, get_response): | ||||
|         self.get_response = get_response | ||||
| 
 | ||||
|     def __call__(self, request): | ||||
|         get_settings() | ||||
|         return self.get_response(request) | ||||
							
								
								
									
										18
									
								
								appsettings/settings.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								appsettings/settings.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,18 @@ | |||
| from .models import AppSettings | ||||
| 
 | ||||
| 
 | ||||
| class Settings(object): | ||||
|     pass | ||||
| 
 | ||||
| 
 | ||||
| app_settings = Settings() | ||||
| 
 | ||||
| 
 | ||||
| def get_settings(): | ||||
|     try: | ||||
|         entries = AppSettings.objects.all() | ||||
|     except: | ||||
|         pass | ||||
| 
 | ||||
|     for entry in entries: | ||||
|         setattr(app_settings, entry.key, entry.val) | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue