Moves get_object_from_name into util.
This commit is contained in:
		
							parent
							
								
									6e4d2fab16
								
							
						
					
					
						commit
						6611546a35
					
				
					 2 changed files with 20 additions and 9 deletions
				
			
		|  | @ -1,4 +1,5 @@ | |||
| import string | ||||
| import sys | ||||
| 
 | ||||
| from django.utils.crypto import get_random_string | ||||
| 
 | ||||
|  | @ -55,3 +56,19 @@ def lazy(function, *args, **kwargs): | |||
|         return retval[0] | ||||
| 
 | ||||
|     return evaluate | ||||
| 
 | ||||
| 
 | ||||
| def get_object_from_name(name): | ||||
|     ''' Returns the named object. | ||||
| 
 | ||||
|     Arguments: | ||||
|         name (str): A string of form `package.subpackage.etc.module.property`. | ||||
|             This function will import `package.subpackage.etc.module` and | ||||
|             return `property` from that module. | ||||
| 
 | ||||
|     ''' | ||||
| 
 | ||||
|     dot = name.rindex(".") | ||||
|     mod_name, property_name = name[:dot], name[dot + 1:] | ||||
|     __import__(mod_name) | ||||
|     return getattr(sys.modules[mod_name], property_name) | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| import sys | ||||
| import util | ||||
| 
 | ||||
| from registrasion import forms | ||||
| from registrasion import util | ||||
|  | @ -60,13 +61,6 @@ class GuidedRegistrationSection(_GuidedRegistrationSection): | |||
|     pass | ||||
| 
 | ||||
| 
 | ||||
| def get_object(name): | ||||
|     dot = name.rindex(".") | ||||
|     mod_name, form_name = name[:dot], name[dot + 1:] | ||||
|     __import__(mod_name) | ||||
|     return getattr(sys.modules[mod_name], form_name) | ||||
| 
 | ||||
| 
 | ||||
| @login_required | ||||
| def guided_registration(request): | ||||
|     ''' Goes through the registration process in order, making sure user sees | ||||
|  | @ -277,11 +271,11 @@ def edit_profile(request): | |||
| 
 | ||||
| # Define the attendee profile form, or get a default. | ||||
| try: | ||||
|     ProfileForm = get_object(settings.ATTENDEE_PROFILE_FORM) | ||||
|     ProfileForm = util.get_object_from_name(settings.ATTENDEE_PROFILE_FORM) | ||||
| except: | ||||
|     class ProfileForm(django_forms.ModelForm): | ||||
|         class Meta: | ||||
|             model = get_object(settings.ATTENDEE_PROFILE_MODEL) | ||||
|             model = util.get_object_from_name(settings.ATTENDEE_PROFILE_MODEL) | ||||
|             exclude = ["attendee"] | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Christopher Neugebauer
						Christopher Neugebauer