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