##// END OF EJS Templates
Add BASE_URL in settings to work with proxys
jespinoza -
r18:5a8055e18e7b
parent child
Show More
@@ -1,167 +1,168
1
1
2 from django.contrib.auth.decorators import login_required
2 from django.contrib.auth.decorators import login_required
3 from django.shortcuts import render
3 from django.shortcuts import render
4 from apps.updata.forms import UpdataForm, ExpForm
4 from apps.updata.forms import UpdataForm, ExpForm
5 from django.core.files.storage import FileSystemStorage
5 from django.core.files.storage import FileSystemStorage
6 from django.contrib import messages
6 from django.contrib import messages
7 from django.conf import settings
7
8
8 import os
9 import os
9 import glob
10 import glob
10 import datetime
11 import datetime
11
12
12 # madrigal imports
13 # madrigal imports
13 import madrigal.metadata
14 import madrigal.metadata
14 import madrigal.ui.web
15 import madrigal.ui.web
15 import madrigal.admin
16 import madrigal.admin
16
17
17 @login_required(login_url='/madrigal/accounts/login/')
18 @login_required(login_url='/{}/accounts/login/'.format(settings.BASE_URL))
18 def index(request):
19 def index(request):
19 '''
20 '''
20 Uploading experiments data view. Allows user to upload experiment files
21 Uploading experiments data view. Allows user to upload experiment files
21
22
22 '''
23 '''
23 dbAdminObj = madrigal.admin.MadrigalDBAdmin()
24 dbAdminObj = madrigal.admin.MadrigalDBAdmin()
24 madDB = madrigal.metadata.MadrigalDB()
25 madDB = madrigal.metadata.MadrigalDB()
25 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
26 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
26 madMeta = madrigal.metadata.MadrigalInstrument(madDB)
27 madMeta = madrigal.metadata.MadrigalInstrument(madDB)
27 siteName, siteList = madWebObj.getSiteInfo()
28 siteName, siteList = madWebObj.getSiteInfo()
28 err = False
29 err = False
29 if request.method == 'POST':
30 if request.method == 'POST':
30 for root, folders, tmp_files in os.walk('/madrigal/experiments/tmp/'):
31 for root, folders, tmp_files in os.walk('/madrigal/experiments/tmp/'):
31 for f in tmp_files:
32 for f in tmp_files:
32 os.remove(os.path.join(root, f))
33 os.remove(os.path.join(root, f))
33
34
34 form = UpdataForm(request.POST, request.FILES)
35 form = UpdataForm(request.POST, request.FILES)
35 files = request.FILES.getlist('file')
36 files = request.FILES.getlist('file')
36 # files.sort()
37 # files.sort()
37 filenames = []
38 filenames = []
38
39
39 choose = request.POST.get('choose')
40 choose = request.POST.get('choose')
40 if choose == 'new':
41 if choose == 'new':
41 instCode = int(request.POST.get('inst'))
42 instCode = int(request.POST.get('inst'))
42 expTitle = request.POST.get('exp')
43 expTitle = request.POST.get('exp')
43 else:
44 else:
44 instCode = int(request.POST.get('instruments'))
45 instCode = int(request.POST.get('instruments'))
45 expId = request.POST.get('experiments')
46 expId = request.POST.get('experiments')
46 madExp = madrigal.metadata.MadrigalExperiment()
47 madExp = madrigal.metadata.MadrigalExperiment()
47 expTitle = madExp.getExpNameByExpId(expId)
48 expTitle = madExp.getExpNameByExpId(expId)
48
49
49 description = request.POST.get('description')
50 description = request.POST.get('description')
50 perm = int(request.POST.get('permission'))
51 perm = int(request.POST.get('permission'))
51 optchar = request.POST.get('optchar').strip()
52 optchar = request.POST.get('optchar').strip()
52 category = int(request.POST.get('category'))
53 category = int(request.POST.get('category'))
53 first = True
54 first = True
54 if len(files) == 1:
55 if len(files) == 1:
55 fs = FileSystemStorage(location='/madrigal/experiments/tmp')
56 fs = FileSystemStorage(location='/madrigal/experiments/tmp')
56 fs.save(files[0].name, files[0])
57 fs.save(files[0].name, files[0])
57 filename = os.path.join('/madrigal/experiments/tmp', files[0].name)
58 filename = os.path.join('/madrigal/experiments/tmp', files[0].name)
58 fileInfo = madrigal.data.MadrigalFile(filename, madDB)
59 fileInfo = madrigal.data.MadrigalFile(filename, madDB)
59 sTime = fileInfo.getEarliestTime()
60 sTime = fileInfo.getEarliestTime()
60 startTime = datetime.datetime(sTime[0],sTime[1],sTime[2],sTime[3],sTime[4],sTime[5])
61 startTime = datetime.datetime(sTime[0],sTime[1],sTime[2],sTime[3],sTime[4],sTime[5])
61 exp_list = madWebObj.getExpsOnDate(instCode, startTime.year, startTime.month, startTime.day)
62 exp_list = madWebObj.getExpsOnDate(instCode, startTime.year, startTime.month, startTime.day)
62 ext = filename.split('.')[-1]
63 ext = filename.split('.')[-1]
63 if ext not in ('hdf5', 'h5'):
64 if ext not in ('hdf5', 'h5'):
64 convert = True
65 convert = True
65 else:
66 else:
66 convert = False
67 convert = False
67 expDir = os.path.join('/madrigal/experiments/', startTime.strftime('%Y'), madMeta.getInstrumentMnemonic(instCode), startTime.strftime('%d%b%y').lower())
68 expDir = os.path.join('/madrigal/experiments/', startTime.strftime('%Y'), madMeta.getInstrumentMnemonic(instCode), startTime.strftime('%d%b%y').lower())
68 if os.path.exists(expDir):
69 if os.path.exists(expDir):
69 #expDir = exp_list[0][2]
70 #expDir = exp_list[0][2]
70 try:
71 try:
71 if category==1 and os.path.exists(os.path.join(expDir, files[0].name)):
72 if category==1 and os.path.exists(os.path.join(expDir, files[0].name)):
72 dbAdminObj.overwriteMadrigalFile(expDir, filename, notify=True)
73 dbAdminObj.overwriteMadrigalFile(expDir, filename, notify=True)
73 messages.warning(request,
74 messages.warning(request,
74 'Filename {} has been overwritten'.format(files[0].name)
75 'Filename {} has been overwritten'.format(files[0].name)
75 )
76 )
76 else:
77 else:
77 dbAdminObj.addMadrigalFile(expDir, filename, perm, description, category=category, updateToMad3=convert)
78 dbAdminObj.addMadrigalFile(expDir, filename, perm, description, category=category, updateToMad3=convert)
78 messages.warning(request,
79 messages.warning(request,
79 'Filename {} has been added with category={}'.format(files[0].name, category)
80 'Filename {} has been added with category={}'.format(files[0].name, category)
80 )
81 )
81 except Exception as e:
82 except Exception as e:
82 err = True
83 err = True
83 messages.error(request,
84 messages.error(request,
84 'An error occur adding file {}: {}'.format(filename.split('/')[-1], e)
85 'An error occur adding file {}: {}'.format(filename.split('/')[-1], e)
85 )
86 )
86 else:
87 else:
87 if os.path.exists(os.path.join('/madrigal/experiments/tmp', 'overview', files[0].name + '.summary')):
88 if os.path.exists(os.path.join('/madrigal/experiments/tmp', 'overview', files[0].name + '.summary')):
88 os.remove(os.path.join('/madrigal/experiments/tmp', 'overview', files[0].name + '.summary'))
89 os.remove(os.path.join('/madrigal/experiments/tmp', 'overview', files[0].name + '.summary'))
89 try:
90 try:
90 expDir = dbAdminObj.createMadrigalExperiment(filename, expTitle, perm, description,
91 expDir = dbAdminObj.createMadrigalExperiment(filename, expTitle, perm, description,
91 instCode, category=category, optChar=optchar, updateToMad3=convert)
92 instCode, category=category, optChar=optchar, updateToMad3=convert)
92 except Exception as e:
93 except Exception as e:
93 err = True
94 err = True
94 messages.error(request,
95 messages.error(request,
95 'An error occur creating the experiment {}: {}'.format(expTitle, e)
96 'An error occur creating the experiment {}: {}'.format(expTitle, e)
96 )
97 )
97 filenames.append(filename.split('/')[-1])
98 filenames.append(filename.split('/')[-1])
98 else:
99 else:
99 for f in files:
100 for f in files:
100 fs = FileSystemStorage(location='/madrigal/experiments/tmp')
101 fs = FileSystemStorage(location='/madrigal/experiments/tmp')
101 fs.save(f.name, f)
102 fs.save(f.name, f)
102 filename = os.path.join('/madrigal/experiments/tmp', f.name)
103 filename = os.path.join('/madrigal/experiments/tmp', f.name)
103 ext = filename.split('.')[-1]
104 ext = filename.split('.')[-1]
104 if ext not in ('hdf5', 'h5'):
105 if ext not in ('hdf5', 'h5'):
105 convert = True
106 convert = True
106 else:
107 else:
107 convert = False
108 convert = False
108
109
109 if first:
110 if first:
110 first = False
111 first = False
111 try:
112 try:
112 expDir = dbAdminObj.createMadrigalExperiment(filename, expTitle, perm, description,
113 expDir = dbAdminObj.createMadrigalExperiment(filename, expTitle, perm, description,
113 instCode, category=category, optChar=optchar, updateToMad3=convert)
114 instCode, category=category, optChar=optchar, updateToMad3=convert)
114 except Exception as e:
115 except Exception as e:
115 err = True
116 err = True
116 messages.error(request,
117 messages.error(request,
117 'An error occur creating the experiment {}: {}'.format(expTitle, e)
118 'An error occur creating the experiment {}: {}'.format(expTitle, e)
118 )
119 )
119 break
120 break
120 else:
121 else:
121 try:
122 try:
122 dbAdminObj.addMadrigalFile(expDir, filename, perm, description, category=category, updateToMad3=convert)
123 dbAdminObj.addMadrigalFile(expDir, filename, perm, description, category=category, updateToMad3=convert)
123 except Exception as e:
124 except Exception as e:
124 err = True
125 err = True
125 messages.error(request,
126 messages.error(request,
126 'An error occur adding file {}: {}'.format(filename.split('/')[-1], e)
127 'An error occur adding file {}: {}'.format(filename.split('/')[-1], e)
127 )
128 )
128 filenames.append(filename.split('/')[-1])
129 filenames.append(filename.split('/')[-1])
129 os.remove(filename)
130 os.remove(filename)
130
131
131 if not err:
132 if not err:
132 messages.success(request,
133 messages.success(request,
133 'Experiment {} created succesfully with files: {}'.format(expTitle, filenames)
134 'Experiment {} created succesfully with files: {}'.format(expTitle, filenames)
134 )
135 )
135
136
136 madInstParams = madrigal.metadata.MadrigalInstrumentParameters()
137 madInstParams = madrigal.metadata.MadrigalInstrumentParameters()
137 madInstKindats = madrigal.metadata.MadrigalInstrumentKindats()
138 madInstKindats = madrigal.metadata.MadrigalInstrumentKindats()
138
139
139 print('*** Updating local metadata ***')
140 print('*** Updating local metadata ***')
140 dbAdminObj.__updateLocalMetadata__()
141 dbAdminObj.__updateLocalMetadata__()
141 print('*** Rebuilding instParmTab.txt ***')
142 print('*** Rebuilding instParmTab.txt ***')
142 madInstParams.rebuildInstParmTable()
143 madInstParams.rebuildInstParmTable()
143 print('*** Rebuilding instKindatTab.txt ***')
144 print('*** Rebuilding instKindatTab.txt ***')
144 madInstKindats.rebuildInstKindatTable()
145 madInstKindats.rebuildInstKindatTable()
145
146
146 form = UpdataForm()
147 form = UpdataForm()
147
148
148 else:
149 else:
149 form = UpdataForm()
150 form = UpdataForm()
150
151
151 return render(request, 'updata/index.html', {
152 return render(request, 'updata/index.html', {
152 'form': form,
153 'form': form,
153 'site_name': siteName,
154 'site_name': siteName,
154 'site_list': siteList,
155 'site_list': siteList,
155 })
156 })
156
157
157
158
158 def get_experiments(request):
159 def get_experiments(request):
159 """get_experiments is a Ajax call that returns the experiments select html to support the
160 """get_experiments is a Ajax call that returns the experiments select html to support the
160 updata UI. Called when a user modifies the intruments select field.
161 updata UI. Called when a user modifies the intruments select field.
161
162
162 Inputs:
163 Inputs:
163 request
164 request
164 """
165 """
165 form = ExpForm(request.GET)
166 form = ExpForm(request.GET)
166
167
167 return render(request, 'updata/experiments.html', {'form': form})
168 return render(request, 'updata/experiments.html', {'form': form})
@@ -1,139 +1,141
1 """
1 """
2 Django settings for djangoMad project.
2 Django settings for djangoMad project.
3
3
4 For more information on this file, see
4 For more information on this file, see
5 https://docs.djangoproject.com/en/1.7/topics/settings/
5 https://docs.djangoproject.com/en/1.7/topics/settings/
6
6
7 For the full list of settings and their values, see
7 For the full list of settings and their values, see
8 https://docs.djangoproject.com/en/1.7/ref/settings/
8 https://docs.djangoproject.com/en/1.7/ref/settings/
9 """
9 """
10
10
11 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
11 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
12 import os
12 import os
13 BASE_DIR = os.path.dirname(os.path.dirname(__file__))
13 BASE_DIR = os.path.dirname(os.path.dirname(__file__))
14
14
15 # Quick-start development settings - unsuitable for production
15 # Quick-start development settings - unsuitable for production
16 # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
16 # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
17
17
18 # SECURITY WARNING: keep the secret key used in production secret!
18 # SECURITY WARNING: keep the secret key used in production secret!
19 SECRET_KEY = '^c1l3d35+q28^66d2pc1qlu(k$wmw^*gg3rfitz^s)t=9eu1ui'
19 SECRET_KEY = '^c1l3d35+q28^66d2pc1qlu(k$wmw^*gg3rfitz^s)t=9eu1ui'
20
20
21 # SECURITY WARNING: don't run with debug turned on in production!
21 # SECURITY WARNING: don't run with debug turned on in production!
22 DEBUG = True
22 DEBUG = True
23
23
24
24
25 ALLOWED_HOSTS = ['localhost:8000', '127.0.0.1', 'localhost', '10.10.120.60']
25 ALLOWED_HOSTS = ['localhost:8000', '127.0.0.1', 'localhost', '10.10.120.60']
26
26
27 ADMINS = (('Bill Rideout', 'brideout@haystack.mit.edu'),)
27 ADMINS = (('Bill Rideout', 'brideout@haystack.mit.edu'),)
28
28
29 EMAIL_HOST = 'hyperion.haystack.mit.edu'
29 EMAIL_HOST = 'hyperion.haystack.mit.edu'
30
30
31 SEND_BROKEN_LINK_EMAILS = True
31 SEND_BROKEN_LINK_EMAILS = True
32
32
33 MANAGERS = (('Bill Rideout', 'brideout@haystack.mit.edu'),)
33 MANAGERS = (('Bill Rideout', 'brideout@haystack.mit.edu'),)
34
34
35
35
36 # Application definition
36 # Application definition
37
37
38 INSTALLED_APPS = (
38 INSTALLED_APPS = (
39 'django.contrib.admin',
39 'django.contrib.admin',
40 'django.contrib.auth',
40 'django.contrib.auth',
41 'django.contrib.contenttypes',
41 'django.contrib.contenttypes',
42 'django.contrib.sessions',
42 'django.contrib.sessions',
43 'django.contrib.messages',
43 'django.contrib.messages',
44 'django.contrib.staticfiles',
44 'django.contrib.staticfiles',
45 'madweb',
45 'madweb',
46 'django_bootstrap_calendar',
46 'django_bootstrap_calendar',
47 'bootstrap3',
47 'bootstrap3',
48 'apps.login',
48 'apps.login',
49 'apps.updata',
49 'apps.updata',
50 )
50 )
51
51
52 MIDDLEWARE = [
52 MIDDLEWARE = [
53 'django.middleware.security.SecurityMiddleware',
53 'django.middleware.security.SecurityMiddleware',
54 'django.contrib.sessions.middleware.SessionMiddleware',
54 'django.contrib.sessions.middleware.SessionMiddleware',
55 'django.middleware.common.CommonMiddleware',
55 'django.middleware.common.CommonMiddleware',
56 'django.middleware.csrf.CsrfViewMiddleware',
56 'django.middleware.csrf.CsrfViewMiddleware',
57 'django.contrib.auth.middleware.AuthenticationMiddleware',
57 'django.contrib.auth.middleware.AuthenticationMiddleware',
58 'django.contrib.messages.middleware.MessageMiddleware',
58 'django.contrib.messages.middleware.MessageMiddleware',
59 'django.middleware.clickjacking.XFrameOptionsMiddleware',
59 'django.middleware.clickjacking.XFrameOptionsMiddleware',
60 ]
60 ]
61
61
62 ROOT_URLCONF = 'djangoMad.urls'
62 ROOT_URLCONF = 'djangoMad.urls'
63
63
64 WSGI_APPLICATION = 'djangoMad.wsgi.application'
64 WSGI_APPLICATION = 'djangoMad.wsgi.application'
65
65
66
66
67 TEMPLATES = [
67 TEMPLATES = [
68 {
68 {
69 'BACKEND': 'django.template.backends.django.DjangoTemplates',
69 'BACKEND': 'django.template.backends.django.DjangoTemplates',
70 'DIRS': [
70 'DIRS': [
71 os.path.join(BASE_DIR, "templates"),
71 os.path.join(BASE_DIR, "templates"),
72 ],
72 ],
73 'APP_DIRS': True,
73 'APP_DIRS': True,
74 'OPTIONS': {
74 'OPTIONS': {
75 'context_processors': [
75 'context_processors': [
76 'django.contrib.auth.context_processors.auth',
76 'django.contrib.auth.context_processors.auth',
77 'django.template.context_processors.debug',
77 'django.template.context_processors.debug',
78 'django.template.context_processors.i18n',
78 'django.template.context_processors.i18n',
79 'django.template.context_processors.media',
79 'django.template.context_processors.media',
80 'django.template.context_processors.static',
80 'django.template.context_processors.static',
81 'django.template.context_processors.tz',
81 'django.template.context_processors.tz',
82 'django.contrib.messages.context_processors.messages',
82 'django.contrib.messages.context_processors.messages',
83 'django.template.context_processors.request',
83 'django.template.context_processors.request',
84 ],
84 ],
85 },
85 },
86 },
86 },
87 ]
87 ]
88
88
89
89
90 # Database
90 # Database
91 # https://docs.djangoproject.com/en/1.7/ref/settings/#databases
91 # https://docs.djangoproject.com/en/1.7/ref/settings/#databases
92
92
93 DATABASES = {
93 DATABASES = {
94 'default': {
94 'default': {
95 'ENGINE': 'django.db.backends.sqlite3',
95 'ENGINE': 'django.db.backends.sqlite3',
96 'NAME': 'madrigal.sqlite',
96 'NAME': 'madrigal.sqlite',
97 }
97 }
98 }
98 }
99
99
100
100
101 # Internationalization
101 # Internationalization
102 # https://docs.djangoproject.com/en/1.7/topics/i18n/
102 # https://docs.djangoproject.com/en/1.7/topics/i18n/
103
103
104 LANGUAGE_CODE = 'en-us'
104 LANGUAGE_CODE = 'en-us'
105
105
106 TIME_ZONE = 'UTC'
106 TIME_ZONE = 'UTC'
107
107
108 USE_I18N = True
108 USE_I18N = True
109
109
110 USE_L10N = True
110 USE_L10N = True
111
111
112 USE_TZ = True
112 USE_TZ = True
113
113
114
114
115 # Absolute filesystem path to the directory that will hold user-uploaded files.
115 # Absolute filesystem path to the directory that will hold user-uploaded files.
116 # Example: "/home/media/media.lawrence.com/media/"
116 # Example: "/home/media/media.lawrence.com/media/"
117 MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
117 MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
118
118
119 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
119 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
120 # trailing slash.
120 # trailing slash.
121 # Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
121 # Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
122 MEDIA_URL = '/media/'
122 MEDIA_URL = '/media/'
123
123
124 # Absolute path to the directory static files should be collected to.
124 # Absolute path to the directory static files should be collected to.
125 # Don't put anything in this directory yourself; store your static files
125 # Don't put anything in this directory yourself; store your static files
126 # in apps' "static/" subdirectories and in STATICFILES_DIRS.
126 # in apps' "static/" subdirectories and in STATICFILES_DIRS.
127 # Example: "/home/media/media.lawrence.com/static/"
127 # Example: "/home/media/media.lawrence.com/static/"
128 # STATIC_ROOT = os.path.join(BASE_DIR, 'static')
128 # STATIC_ROOT = os.path.join(BASE_DIR, 'static')
129
129
130 # URL prefix for static files.
130 # URL prefix for static files.
131 # Example: "http://media.lawrence.com/static/"
131 # Example: "http://media.lawrence.com/static/"
132 STATIC_URL = '/madrigal/static/'
132 STATIC_URL = '/madrigal/static/'
133 STATIC_ROOT = '/madrigal/source/madpy/djangoMad/static_files/'
133 STATIC_ROOT = '/madrigal/source/madpy/djangoMad/static_files/'
134 BASE_URL = 'madrigal'
135 #BASE_URL = 'observatorios/radio-observatorio-jicamarca/madrigal'
134
136
135 BOOTSTRAP3 = {
137 BOOTSTRAP3 = {
136 # Include jQuery with Bootstrap JavaScript (affects django-bootstrap3 template tags)
138 # Include jQuery with Bootstrap JavaScript (affects django-bootstrap3 template tags)
137 'jquery_url': '/madrigal/static/jquery.min.js',
139 'jquery_url': '/madrigal/static/jquery.min.js',
138 'include_jquery': True,
140 'include_jquery': True,
139 }
141 }
@@ -1,12 +1,18
1 from django.conf.urls import include, url
1 from django.conf.urls import include, url
2 from django.contrib import admin
2 from django.contrib import admin
3 from django.conf import settings
3 import madweb.views
4 import madweb.views
4
5
6 if settings.BASE_URL:
7 base = settings.BASE_URL + '/'
8 else:
9 base = ''
10
5 urlpatterns = [
11 urlpatterns = [
6 url(r'^madrigal/', include('madweb.urls')),
12 url(r'^{}'.format(base), include('madweb.urls')),
7 url(r'^$', madweb.views.index),
13 # url(r'^$', madweb.views.index),
8 url(r'^madrigal/updata/', include('apps.updata.urls', namespace="updata")),
14 url(r'^{}updata/'.format(base), include('apps.updata.urls', namespace="updata")),
9 url(r'^madrigal/accounts/', include('apps.login.urls', namespace="login")),
15 url(r'^{}accounts/'.format(base), include('apps.login.urls', namespace="login")),
10 url(r'^madrigal/admin/', admin.site.urls),
16 url(r'^{}admin/'.format(base), admin.site.urls),
11 # url(r'^madrigal/register/?$', madweb.views.view_registration, name='view_registration'),
17 # url(r'^madrigal/register/?$', madweb.views.view_registration, name='view_registration'),
12 ]
18 ]
General Comments 0
You need to be logged in to leave comments. Login now