diff --git a/applyXSL/urls.py b/applyXSL/urls.py index 91e783f..60362f6 100644 --- a/applyXSL/urls.py +++ b/applyXSL/urls.py @@ -1,10 +1,7 @@ -from django.conf.urls import patterns, url, include +from django.conf.urls import url from django.views.generic import TemplateView -urlpatterns = patterns('', - url(r'^$', TemplateView.as_view(template_name='homepage.html'), name="home"), -) - +from . import views from django.conf import settings class CapabilitiesView(TemplateView): @@ -16,10 +13,11 @@ def get_context_data(self, **kwargs): -urlpatterns = patterns('applyXSL.views', - (r'^(?P\w+)/$', 'showForm'), - (r'^(?P\w+)/service$', 'receiveInput'), - (r'^(?P\w+)/result/(?P\w+)$', 'deliverResult'), - (r'^(?P\w+)/availability$', TemplateView.as_view(template_name='availability.xml')), +urlpatterns = [ + url(r'^$', TemplateView.as_view(template_name='index.html'), name="home"), + url(r'^(?P\w+)/$', views.showForm), + url(r'^(?P\w+)/service$', views.receiveInput), + url(r'^(?P\w+)/result/(?P\w+)$', views.deliverResult), + url(r'^(?P\w+)/availability$', TemplateView.as_view(template_name='availability.xml')), url(r'^(?P\w+)/capabilities$', CapabilitiesView.as_view()), - ) +] diff --git a/applyXSL/views.py b/applyXSL/views.py index 322efa2..1b83310 100644 --- a/applyXSL/views.py +++ b/applyXSL/views.py @@ -1,38 +1,29 @@ # -*- coding: utf-8 -*- -from django.shortcuts import render,render_to_response, get_object_or_404 +from django.shortcuts import render,get_object_or_404 from django.template import RequestContext from django.http import HttpResponseRedirect, HttpResponse, HttpResponseNotFound from django.forms import Form,FileField,URLField,TextInput from django.core.exceptions import ValidationError from lxml import etree as e -from urllib2 import urlopen +from urllib.request import urlopen import os import threading from time import sleep +from . import xsl +from . import models from django.conf import settings -STATIC=settings.STATIC_DIR -if hasattr(settings,'DEPLOY_URL'): - APPURL = settings.DEPLOY_URL+'applyXSL/' -else: - APPURL = '/applyXSL/' - - -if hasattr(settings,'SAXON_JAR'): - import xsl - useJAVAxsl = True -else: useJAVAxsl = False -from models import Conversion +STATIC=settings.STATIC_DIR XSL_MIME = {'xsams2sme':'text/plain', 'linespec':'image/svg+xml', 'atomicxsams2html':'text/html', 'molecularxsams2html':'text/html', 'collisions2html':'text/html',} - + XSL_VERSION = {'xsams2sme':1, 'linespec':1, 'atomicxsams2html':1, @@ -42,7 +33,7 @@ class ConversionForm(Form): upload = FileField(label='Input file',required=False) url = URLField(label='Input URL',required=False,widget=TextInput(attrs={'size': 50, 'title': 'Paste here a URL that delivers an XSAMS document.',})) - + def clean(self): upload = self.cleaned_data.get('upload') @@ -56,61 +47,31 @@ def showForm(request,xsl): if xsl not in XSL_MIME: return HttpResponseNotFound() ConvForm = ConversionForm() - return render_to_response('applyXSL.html', - RequestContext(request,dict(conversion=ConvForm))) - -def transformJAVA(conv,err=None): - transformer = xsl.XslTransformerFactory.getXslTransformer(XSL_VERSION[conv.xsl]) - try: - result = transformer.transform(conv) - except: - err = '500 transformation failed\n' - result = None - return err,result - - -def transformLXML(conv,err=None): - xslfile = open(STATIC+'/xsl/%s.xsl'%conv.xsl) - xsl = e.XSLT(e.parse(xslfile)) - try: - if conv.url: - xml = e.parse(urlopen(conv.url)) - elif conv.upload: - xml = e.parse(conv.upload) - else: - err = '400 no data to transform\n' - except: - err = '400 input data seems to be broken XML\n' - - try: - output = str(xsl(xml)) - except: - err = '500 transformation failed\n' - output=None - return err,output + return render(request, 'applyXSL.html',dict(conversion=ConvForm)) class DoWork(threading.Thread): def __init__(self, conv): threading.Thread.__init__(self) self.conv = conv self.outfile = STATIC+'/results/%s'%conv.pk - + self.err = '' + def run(self): - if useJAVAxsl: - err,result = transformJAVA(self.conv) - else: - err,result = transformLXML(self.conv) - - if err: - open(self.outfile+'.err','w').write(err) - else: - open(self.outfile,'w').write(result) - + transformer = xsl.XslTransformerFactory.getXslTransformer(XSL_VERSION[self.conv.xsl]) + result = transformer.transform(self.conv) + + try : + open(self.outfile,'w').write(result) + except Exception as exc: + open(self.outfile,'w').write(str(exc)) + def receiveInput(request,xsl): + print(dir(request)) ConvForm = ConversionForm(request.POST, request.FILES) + if ConvForm.is_valid(): - conv = Conversion(xsl=xsl, + conv = models.Conversion(xsl=xsl, upload=ConvForm.cleaned_data['upload'], url=ConvForm.cleaned_data['url'] ) conv.save(force_insert=True) @@ -121,19 +82,19 @@ def receiveInput(request,xsl): # give it a second, so we might skip the # waiting-page for quick transforms sleep(2) - return HttpResponseRedirect(APPURL+'%s/result/%s'%(xsl,conv.pk)) + return HttpResponseRedirect(settings.DEPLOY_URL+'applyXSL/%s/result/%s'%(xsl,conv.pk)) else: - return HttpResponseRedirect(APPURL+'%s/'%xsl) + return HttpResponseRedirect(settings.DEPLOY_URL+'applyXSL/%s/'%xsl) def deliverResult(request,xsl,rid): - conv = get_object_or_404(Conversion,pk=rid) + conv = get_object_or_404(models.Conversion,pk=rid) outfile = STATIC+'/results/%s'%rid if os.path.exists(outfile+'.err'): - errstring = open(outfile+'.err').readline() - errcode, msg = errstring.split(' ',1) + errcode, msg = open(outfile+'.err').readline().split(' ',1) return HttpResponse(msg,status=errcode,content_type='text/plain') elif os.path.exists(outfile): return HttpResponse(open(outfile),content_type=XSL_MIME.get(xsl,'text/plain')) else: return HttpResponse(render(request,'wait5.html',{}),status=202) + diff --git a/applyXSL/xsl.py b/applyXSL/xsl.py index e0d007e..babfe72 100644 --- a/applyXSL/xsl.py +++ b/applyXSL/xsl.py @@ -2,8 +2,8 @@ from abc import ABCMeta, abstractmethod from lxml import etree as e from django.conf import settings -import commands -from urllib2 import urlopen +import subprocess +from urllib.request import urlopen import tempfile STATIC=settings.STATIC_DIR @@ -32,22 +32,23 @@ def __init__(self): def transform(self, form): xslfile = STATIC+'/xsl/%s.xsl'%form.xsl + import os.path try: if form.url: - command = 'java -jar '+SAXON_JAR+' -s:"%s" -xsl:%s'%(form.url, xslfile) - output = commands.getoutput(command) + command = ['java', '-jar', SAXON_JAR, '-s:"{form.url}"'.format(form.url), '-xsl:{}'.format(xslfile)] + output = subprocess.check_output(' '.join(command), encoding="UTF-8") elif form.upload: - tmpfile = tempfile.NamedTemporaryFile(delete=False) - xml = e.tostring(e.parse(form.upload)) - tmpfile.write(xml) - tmpfile.flush() # be sure that all data have been written - command = 'java -jar '+SAXON_JAR+' -s:"%s" -xsl:%s'%(tmp.name, xslfile) - output = commands.getoutput(command) + with tempfile.NamedTemporaryFile(delete=True) as tmpfile: + xml = e.tostring(e.parse(form.upload)) + tmpfile.write(xml) + tmpfile.flush() # be sure that all data have been written + command = ['java', '-jar', SAXON_JAR, '-s:%s'%(tmpfile.name), '-xsl:{}'.format(xslfile)] + output = subprocess.check_output(command, encoding="UTF-8") else: self.err = '400 no data to transform\n' - except Exception, exc: + except Exception as exc: self.err = '400 input data seems to be broken XML\n' - print exc + print(exc) if self.err: return self.err @@ -71,9 +72,9 @@ def transform(self, form): xml = e.parse(form.upload) else: self.err = '400 no data to transform\n' - except Exception, exc: + except Exception as exc: self.err = '400 input data seems to be broken XML\n' - print exc + print(exc) try: output = str(xsl(xml)) diff --git a/processors/urls.py b/processors/urls.py index 1be89b3..7e85225 100644 --- a/processors/urls.py +++ b/processors/urls.py @@ -1,12 +1,7 @@ -from django.conf.urls import patterns, include, url -#from django.contrib import admin - -urlpatterns = patterns('', - # Examples: - # url(r'^$', 'processors.views.home', name='home'), - # url(r'^blog/', include('blog.urls')), - # url(r'^admin/', include(admin.site.urls)), +from django.conf.urls import url, include +urlpatterns = [ url(r'^applyXSL/', include('applyXSL.urls')), url(r'^specsynth/', include('specsynth.urls')), -) +] + diff --git a/specsynth/urls.py b/specsynth/urls.py index 0827af8..a725d2d 100644 --- a/specsynth/urls.py +++ b/specsynth/urls.py @@ -1,9 +1,13 @@ -from django.conf.urls import patterns, include, url +from django.conf.urls import url, include -urlpatterns = patterns('specsynth.views', - (r'^$', 'showForm'), - (r'service$', 'receiveInput'), - (r'result/spec_(?P\w+).json$', 'deliverResult'), +from specsynth import views + +urlpatterns = [ + url(r'^$', views.showForm), + url(r'service$', views.receiveInput), + url(r'result/spec_(?P\w+).json$', views.deliverResult), #(r'^(?P\w+)/availability$', direct_to_template, {'template':'availability.xml','extra_context':{'deployurl':settings.DEPLOY_URL}}), #(r'^(?P\w+)/capabilities$', direct_to_template, {'template':'capabilities.xml','extra_context':{'deployurl':settings.DEPLOY_URL}}) - ) + +] + diff --git a/specsynth/views.py b/specsynth/views.py index 1135c5c..c3e1204 100644 --- a/specsynth/views.py +++ b/specsynth/views.py @@ -1,18 +1,17 @@ # -*- coding: utf-8 -*- -from django.shortcuts import render,render_to_response, get_object_or_404 -from django.template import RequestContext -from django.http import HttpResponseRedirect, HttpResponse, HttpResponseNotFound +from django.shortcuts import render,get_object_or_404 +from django.http import HttpResponseRedirect, HttpResponse from django.forms import Form,FileField,URLField,TextInput from django.core.exceptions import ValidationError from lxml import etree as e -from urllib2 import urlopen +from urllib.request import urlopen import os import threading from time import sleep import json -from models import Spec +from .models import Spec from django.conf import settings STATIC = settings.STATIC_DIR @@ -49,8 +48,8 @@ def clean(self): def showForm(request): ConvForm = ConversionForm() - return render_to_response('specsynth.html', - RequestContext(request,dict(conversion=ConvForm))) + return render(request, 'specsynth.html', + dict(conversion=ConvForm)) class DoWork(threading.Thread): def __init__(self,conv): @@ -70,8 +69,8 @@ def run(self): self.err += '400 input data seems to be broken XML\n' try: output = prepare_json(xml) - except Exception, E: - print E + except Exception as exc: + print(exc) self.err += '500 transformation failed\n' if self.err: diff --git a/static/vamdc_files/style.css b/static/vamdc_files/style.css index b2d2e1d..b39c033 100644 --- a/static/vamdc_files/style.css +++ b/static/vamdc_files/style.css @@ -145,20 +145,28 @@ a { float: left; } .main-content-1 { - width: 880px; + width: 70%; float: left; position: relative; } .main-content-2 { - width: 732px; + width: 70%; float: left; } .main-content-full { - width: 100%} + width: 100% +} + .sidebar-right { - width: 210px; + width: 20%; float: right; } + +.sidebar-right ul{ + margin-bottom: 1em; + list-style:none; +} + .top-bar { zoom: 1; width: 100%} diff --git a/static/xsl/atomicxsams2html.xsl b/static/xsl/atomicxsams2html.xsl index 2ec95bd..7fad85f 100644 --- a/static/xsl/atomicxsams2html.xsl +++ b/static/xsl/atomicxsams2html.xsl @@ -1,703 +1,327 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - 0 - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - -
-
- Actions - - - -
-
-
-

Sources

- - - - - - - - - - - - - - - - - - - -
IdTitleOriginAuthorsYearLink
-
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ +

+

+ +

+

+ +

+
+ loading Please wait ... +
+
+
	
+	
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + -
-

Results from VAMDC node

-
-
- loading Please wait ... -
-
- -

-                
-
- -
Spec Ion
Mass number
Wavelength(A)
Wavenumber
Energy
Frequency
A
Oscillator Strength
Weighted Oscillator Strength
Lower state description
Lower energy()
Lower ionization()
Lower lifetime
Lower statistical weight
Lower parity
Lower total angular momentum
Lower kappa
Lower hyperfine momentum
Lower magnetic quantum number
Lower mixing coeff
Lower configuration
Lower term
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Spec Ion
Wavelength(A)
Transition reference
Wavenumber
Energy
Frequency
A
Oscillator Strength
Weighted Oscillator Strength
Log10 Weighted Oscillator Strength
Lower state description
Lower state source
Lower energy()
Lower ionization()
Lower lifetime
Lower statistical weight
Lower parity
Lower total angular momentum
Lower kappa
Lower hyperfine momentum
Lower magnetic quantum number
Lower mixing coeff
Lower configuration
Lower term label
Lower coupling
Upper state description
Upper state source
Upper energy()
Upper ionization()
Upper lifetime
Upper statistical weight
Upper parity
Upper total angular momentum
Upper kappa
Upper hyperfine momentum
Upper magnetic quantum number
Upper mixing coeff
Upper configuration
Upper term label
Upper coupling
-
- - - - - - - - + Upper state description
+ Upper energy()
+ Upper ionization()
+ Upper lifetime
+ Upper statistical weight
+ Upper parity
+ Upper total angular momentum
+ Upper kappa
+ Upper hyperfine momentum
+ Upper magnetic quantum number
+ Upper mixing coeff
+ Upper configuration
+ Upper term
- -
- - - - - - - - - - - - - - - - - - : - - - ( Vol : - - , Page Begin : - - - , Page End : - - ) - - - - ; - - - - - - - - - - - - - - - - - - - - -#Source:,, , ,;,, - - - - - - - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- - - - - - + + + + + + - - - - - - + + + + + + - - - - - - - - - - - - - - L= S= - Multiplicity= - Seniority= - - j= - j= - - j= - S2= K= - - L= K= - S2= - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - +
+ diff --git a/static/xsl/molecularxsams2html.xsl b/static/xsl/molecularxsams2html.xsl index 9fcfcfe..1fad049 100644 --- a/static/xsl/molecularxsams2html.xsl +++ b/static/xsl/molecularxsams2html.xsl @@ -6,12 +6,15 @@ - - - - - - + + + + + + + + + @@ -24,13 +27,42 @@ + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -40,15 +72,21 @@
-
- Actions - - - -
+
+ Menu + + + + + +
-
-

Sources

+
+
+ + +
+ Sources @@ -69,213 +107,249 @@
-
-
-

Results from VAMDC node

-
-
- loading - Please wait ... -
-
- -
-        
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - Chemical name -
- -
-
- Ion charge -
- -
-
- Stoichiometric formula -
- -
-
- Ordinary structural formula -
- -
-
- Wavelength(A) -
- -
-
- Transition reference -
- -
-
- Wavenumber -
- -
-
- Energy -
- -
-
- Frequency -
- -
-
- A -
- -
-
- Oscillator Strength -
- -
-
- Weighted Oscillator Strength -
- -
-
- Lower energy() -
- -
-
- Lower total statistical weight -
- -
+ +
+ Results from VAMDC node +
+
+ loading + Please wait ... +
+
+ + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + - Lower nuclear statistical weight -
- -
-
- Lower parity -
- -
-
- Lower QNs -
- -
-
- Upper energy() -
- -
-
- Upper total statistical weight -
- -
-
- Upper nuclear statistical weight -
- -
-
- Upper parity -
- -
-
- Upper QNs -
- -
-
+ Chemical name +
+ +
+
+ Ion charge +
+ +
+
+ Stoichiometric formula +
+ +
+
+ Ordinary structural formula +
+ +
+
+ Wavelength () +
+ +
+
+ Wavelength reference +
+ +
+
+ Transition reference +
+ +
+
+ Wavenumber +
+ +
+
+ Wavenumber reference +
+ +
+
+ Energy +
+ +
+
+ Energy reference +
+ +
+
+ Frequency +
+ +
+
+ Frequency reference +
+ +
+
+ A +
+ +
+
+ Oscillator Strength +
+ +
+
+ Weighted Oscillator Strength +
+ +
+
+ Lower energy() +
+ +
+
+ Lower total statistical weight +
+ +
+
+ Lower nuclear statistical weight +
+ +
+
+ Lower parity +
+ +
+
+ Lower QNs +
+ +
+
+ Upper energy() +
+ +
+
+ Upper total statistical weight +
+ +
+
+ Upper nuclear statistical weight +
+ +
+
+ Upper parity +
+ +
+
+ Upper QNs +
+ +
+
+
+
+ +