def saveUser(self, serializedFormValues): from tuition.user.models import User from tuition.utils.manager import AppManager from tuition.user.forms import UserRegistrationForm isEdit = False loggedInEmployee = AppManager.getCurrentLoggedInUser() email = loggedInEmployee.email() form = UserRegistrationForm(data=serializedFormValues) if serializedFormValues.get('keyHidden'): isEdit = True loggedInEmployee = AppManager.getUserByEmail( AppManager.getCurrentLoggedInUser().email()) form.loggedInEmployeeKey = str(loggedInEmployee.key()) form.keyHidden = serializedFormValues.get('keyHidden') email = loggedInEmployee.email if form.is_valid(): dictToSave = { 'firstName': form.cleaned_data['firstName'], 'lastName': form.cleaned_data['lastName'], 'email': email, 'alternateEmail': form.cleaned_data['alternateEmail'], 'dob': form.cleaned_data['dob'], 'about': form.cleaned_data['about'] } if not isEdit: savedUser = User(**dictToSave) else: savedUser = User.get(serializedFormValues.get('keyHidden')) for key, value in dictToSave.iteritems(): setattr(savedUser, key, value) return self.respond(isSaved=True, isEdit=isEdit, savedUserKey=str(db.put(savedUser)), savedValues=savedUser.toDict) else: return self.respond(isSaved=False, errors=form.errors)
def saveUser(self, serializedFormValues): from tuition.user.models import User from tuition.utils.manager import AppManager from tuition.user.forms import UserRegistrationForm isEdit = False loggedInEmployee = AppManager.getCurrentLoggedInUser() email = loggedInEmployee.email() form = UserRegistrationForm(data=serializedFormValues) if serializedFormValues.get('keyHidden'): isEdit = True loggedInEmployee = AppManager.getUserByEmail(AppManager.getCurrentLoggedInUser().email()) form.loggedInEmployeeKey = str(loggedInEmployee.key()) form.keyHidden = serializedFormValues.get('keyHidden') email = loggedInEmployee.email if form.is_valid(): dictToSave = { 'firstName' : form.cleaned_data['firstName'], 'lastName' : form.cleaned_data['lastName'], 'email' : email, 'alternateEmail' : form.cleaned_data['alternateEmail'], 'dob' : form.cleaned_data['dob'], 'about' : form.cleaned_data['about'] } if not isEdit: savedUser = User(**dictToSave) else: savedUser = User.get(serializedFormValues.get('keyHidden')) for key, value in dictToSave.iteritems(): setattr(savedUser, key, value) return self.respond( isSaved=True, isEdit=isEdit, savedUserKey=str(db.put(savedUser)), savedValues=savedUser.toDict ) else: return self.respond( isSaved=False, errors=form.errors )
def getUserByEmail(email): from tuition.user.models import User return User.all().filter('email =', email).get()