def import_obj(self, obj, data, dry_run): guardian_email = data.get('guardian_email') obj.first_name = data.get('first_name') obj.last_name = data.get('last_name') obj.birthday = datetime.strptime(data.get('birthday', ''), '%m/%d/%Y') obj.gender = data.get('gender', '') obj.school_name = data.get('school_name', '') obj.school_type = data.get('school_type', '') obj.photo_release = str_to_bool(data.get('photo_release', '')) obj.consent = str_to_bool(data.get('consent', '')) obj.is_active = True try: obj.guardian = Guardian.objects.get(user__email=guardian_email) except Guardian.DoesNotExist: raise ImportError( f'guardian with email {guardian_email} not found') if not dry_run: obj.save()
def import_obj(self, obj, data, dry_run): guardian_email = data.get('guardian_email') obj.first_name = data.get('first_name') obj.last_name = data.get('last_name') obj.birthday = datetime.strptime(data.get('birthday', ''), '%m/%d/%Y') obj.gender = data.get('gender', '') obj.school_name = data.get('school_name', '') obj.school_type = data.get('school_type', '') obj.photo_release = str_to_bool(data.get('photo_release', '')) obj.consent = str_to_bool(data.get('consent', '')) obj.is_active = True try: obj.guardian = Guardian.objects.get(user__email=guardian_email) except Guardian.DoesNotExist: raise ImportError( u'guardian with email {} not found'.format(guardian_email) ) if not dry_run: obj.save()
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os from coderdojochi.util import str_to_bool BASE_DIR = os.path.dirname(os.path.dirname(__file__)) PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'e^u3u$pukt$s=6#&9oi9&jj5ow6563fuka%y9t7i*2laalk^l$' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = str_to_bool(os.environ.get('DEBUG')) or False DEBUG_EMAIL = str_to_bool(os.environ.get('DEBUG_EMAIL')) or False ALLOWED_HOSTS = ['*'] SITE_URL = os.environ.get('SITE_URL') or 'http://coderdojochi.local' SITE_ID = 1 # Application definition INSTALLED_APPS = [ # django contrib 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes',
os.path.join( os.path.dirname(__file__), os.pardir ) ) PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'e^u3u$pukt$s=6#&9oi9&jj5ow6563fuka%y9t7i*2laalk^l$' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = str_to_bool( os.environ.get('DEBUG') ) and 'test' not in sys.argv or False DEBUG_EMAIL = str_to_bool(os.environ.get('DEBUG_EMAIL')) or False ALLOWED_HOSTS = ['*'] SITE_URL = os.environ.get('SITE_URL') or 'http://coderdojochi.local' SITE_ID = 1 # Application definition INSTALLED_APPS = [ # django contrib 'django.contrib.admin', 'django.contrib.auth',
import os import sys from coderdojochi.util import str_to_bool BASE_DIR = os.path.dirname(os.path.dirname(__file__)) PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = os.environ.get("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = str_to_bool(os.environ.get("DEBUG")) and "test" not in sys.argv or False DEBUG_EMAIL = str_to_bool(os.environ.get("DEBUG_EMAIL")) or False ALLOWED_HOSTS = ["*"] SITE_URL = os.environ.get("SITE_URL") or "http://coderdojochi.local" SITE_NAME = "CoderDojoChi" SITE_ID = 1 USE_TZ = True TIME_ZONE = "America/Chicago" # Application definition INSTALLED_APPS = [ # django contrib
import sys from coderdojochi.util import str_to_bool BASE_DIR = os.path.dirname(os.path.dirname(__file__)) PROJECT_ROOT = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir)) PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = os.environ.get('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = str_to_bool( os.environ.get('DEBUG')) and 'test' not in sys.argv or False DEBUG_EMAIL = str_to_bool(os.environ.get('DEBUG_EMAIL')) or False ALLOWED_HOSTS = ['*'] SITE_URL = os.environ.get('SITE_URL') or 'http://coderdojochi.local' SITE_NAME = 'CoderDojoChi' SITE_ID = 1 USE_TZ = True TIME_ZONE = 'America/Chicago' # Application definition INSTALLED_APPS = [