def getProfile(request,allowDefault=True): if request.user.is_authenticated(): try: return request.user.profile except ObjectDoesNotExist: profile = Profile(user=request.user) profile.save() return profile elif allowDefault: return defaultProfile
def getProfile(request, allowDefault=True): if request.user.is_authenticated(): try: return request.user.profile except ObjectDoesNotExist: profile = Profile(user=request.user) profile.save() return profile elif allowDefault: return defaultProfile
def getProfile(request, allowDefault=True): if request.user.is_authenticated(): try: return request.user.profile except ObjectDoesNotExist: profile = Profile(user=request.user) try: profile.save(using='default') except IntegrityError: # prevent Duplicate key on insert during race condition while rendering two frames simultaneously pass return profile elif allowDefault: return default_profile()
yield index if not environ.get('READTHEDOCS'): try: defaultUser = User.objects.get(username='******') except User.DoesNotExist: log.info("Default user does not exist, creating it...") randomPassword = User.objects.make_random_password(length=16) defaultUser = User.objects.create_user('default','*****@*****.**',randomPassword) defaultUser.save() try: defaultProfile = Profile.objects.get(user=defaultUser) except Profile.DoesNotExist: log.info("Default profile does not exist, creating it...") defaultProfile = Profile(user=defaultUser) defaultProfile.save() def load_module(module_path, member=None): module_name = splitext(basename(module_path))[0] module_file = open(module_path, 'U') description = ('.py', 'U', imp.PY_SOURCE) module = imp.load_module(module_name, module_file, module_path, description) if member: return getattr(module, member) else: return module def timestamp(datetime): "Convert a datetime object into epoch time"
if not environ.get('READTHEDOCS'): try: defaultUser = User.objects.get(username='******') except User.DoesNotExist: log.info("Default user does not exist, creating it...") randomPassword = User.objects.make_random_password(length=16) defaultUser = User.objects.create_user( 'default', '*****@*****.**', randomPassword) defaultUser.save() try: defaultProfile = Profile.objects.get(user=defaultUser) except Profile.DoesNotExist: log.info("Default profile does not exist, creating it...") defaultProfile = Profile(user=defaultUser) defaultProfile.save() def load_module(module_path, member=None): module_name = splitext(basename(module_path))[0] module_file = open(module_path, 'U') description = ('.py', 'U', imp.PY_SOURCE) module = imp.load_module(module_name, module_file, module_path, description) if member: return getattr(module, member) else: return module