[cig-commits] r14032 - in cs/portal/trunk/northridge/SeismoWebPortal: . templates/SeismoWebPortal
leif at geodynamics.org
leif at geodynamics.org
Tue Feb 10 14:23:59 PST 2009
Author: leif
Date: 2009-02-10 14:23:59 -0800 (Tue, 10 Feb 2009)
New Revision: 14032
Added:
cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_link.html
Modified:
cs/portal/trunk/northridge/SeismoWebPortal/fformats.py
cs/portal/trunk/northridge/SeismoWebPortal/forms.py
cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py
cs/portal/trunk/northridge/SeismoWebPortal/models.py
cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/pluggable.html
cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_upload.html
cs/portal/trunk/northridge/SeismoWebPortal/views.py
Log:
Allow the user to submit an URL to a pluggable Earth model, rather
than uploading the Earth model file via POST. Submitting an URL
creates a link in the portal's database; when the daemon attempts to
download the file from the portal, it follows an HTTP redirect and
downloads it from the URL the user submitted. Thus, large Earth model
files can be used.
Modified: cs/portal/trunk/northridge/SeismoWebPortal/fformats.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/fformats.py 2009-02-10 02:28:45 UTC (rev 14031)
+++ cs/portal/trunk/northridge/SeismoWebPortal/fformats.py 2009-02-10 22:23:59 UTC (rev 14032)
@@ -131,8 +131,6 @@
desc = self.extractDescription(tgz)
if desc:
model.description = desc
- else:
- assert False
model.save()
return model
Modified: cs/portal/trunk/northridge/SeismoWebPortal/forms.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/forms.py 2009-02-10 02:28:45 UTC (rev 14031)
+++ cs/portal/trunk/northridge/SeismoWebPortal/forms.py 2009-02-10 22:23:59 UTC (rev 14032)
@@ -565,7 +565,7 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# file upload
+# file upload/link
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -601,6 +601,23 @@
+class LinkManipulator(forms.Manipulator):
+
+ def __init__(self, modelClass):
+ super(LinkManipulator, self).__init__()
+ self.modelClass = modelClass
+ self.fields = [
+ forms.URLField(field_name='url', is_required=True),
+ ]
+
+ def flatten_data(self):
+ return {}
+
+ def save(self, new_data):
+ return self.modelClass.createLink(new_data['url'])
+
+
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# custom form fields
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Modified: cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py 2009-02-10 02:28:45 UTC (rev 14031)
+++ cs/portal/trunk/northridge/SeismoWebPortal/mezzanine.py 2009-02-10 22:23:59 UTC (rev 14032)
@@ -20,6 +20,7 @@
creatable = True
def editable(self, builtIn): return not builtIn
uploadable = False
+ linkable = False
downloadableAsText = False
downloadableAsTarGz = False
downloadableAsKML = False
@@ -410,6 +411,17 @@
})
return t.render(c)
+ @classmethod
+ def link(cls, request, **kwds):
+ from forms import LinkManipulator
+ model = cls.Model
+ template_name = "%s/%s_link.html" % (model._meta.app_label, model._meta.object_name.lower())
+ manipulator = LinkManipulator(model)
+ return cls.create(request,
+ template_name=template_name,
+ manipulator=manipulator,
+ **kwds)
+
id = property(lambda self: self.obj.id)
@classmethod
@@ -797,6 +809,7 @@
creatable = False
uploadable = True
+ linkable = True
duplicatable = False
downloadableAsTarGz = True
@@ -806,10 +819,15 @@
def downloadAsTarGz(self, request):
from shutil import copyfileobj
- response = HttpResponse(mimetype='application/x-tar-gz')
- response['Content-Disposition'] = 'attachment; filename=%s.tgz' % self.obj.name
- stream = open(self.obj.get_pathname_filename(), 'r')
- copyfileobj(stream, response)
+
+ if self.obj.url:
+ response = HttpResponseRedirect(self.obj.url)
+ else:
+ response = HttpResponse(mimetype='application/x-tar-gz')
+ response['Content-Disposition'] = 'attachment; filename=%s.tgz' % self.obj.name
+ stream = open(self.obj.get_pathname_filename(), 'r')
+ copyfileobj(stream, response)
+
return response
Modified: cs/portal/trunk/northridge/SeismoWebPortal/models.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/models.py 2009-02-10 02:28:45 UTC (rev 14031)
+++ cs/portal/trunk/northridge/SeismoWebPortal/models.py 2009-02-10 22:23:59 UTC (rev 14032)
@@ -404,15 +404,21 @@
class Specfem3DGlobeModel(Model, EditableObject):
name = models.CharField(maxlength=100)
- pathname = models.FileField(upload_to="SeismoWebPortal/models/3D")
+ pathname = models.FileField(upload_to="SeismoWebPortal/models/3D", blank=True)
description = models.TextField(blank=True)
+ url = models.URLField(blank=True)
+
def __str__(self): return self.name
def list(self, verbose=True):
+ from django.core.validators import isValidURL
import tarfile, time
from StringIO import StringIO
+ if self.url:
+ return 'link to <a href="%s">%s</a>' % (self.url, self.url)
+
tgz = tarfile.open(self.get_pathname_filename(), 'r:gz')
stream = StringIO()
@@ -440,7 +446,15 @@
return stream.getvalue()
+ def createLink(cls, url):
+ i = url.rindex('/')
+ name = url[i + 1:]
+ if not name:
+ name = url[url.rindex('/', 0, i) + 1:i]
+ return cls.objects.create(name = name, url = url)
+ createLink = classmethod(createLink)
+
class Specfem3DGlobeParameters(Model, EditableObject):
name = models.CharField(maxlength=100)
Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/pluggable.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/pluggable.html 2009-02-10 02:28:45 UTC (rev 14031)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/pluggable.html 2009-02-10 22:23:59 UTC (rev 14032)
@@ -119,6 +119,13 @@
{% endif %}
</td>
<td>
+ {% if linkable %}
+ <a href="{{root}}/?class={{klass}}&action=link">Link</a>
+ {% else %}
+ <span class="disabled">Link</span>
+ {% endif %}
+ </td>
+ <td>
{% if object %}
<a href="{{root}}/?class={{klass}}&object={{object.id}}">View</a>
{% else %}
Added: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_link.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_link.html (rev 0)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_link.html 2009-02-10 22:23:59 UTC (rev 14032)
@@ -0,0 +1,30 @@
+
+<h2><img src="{{root}}/images/s20rts.gif" width=32 height=32> Link to Specfem 3D Globe Model</h2>
+
+{% if form.has_errors %}
+<p><span class=error>Please correct the following error{{ form.error_dict|pluralize }}.</span>
+{% endif %}
+
+<form method="post" action="{{action}}">
+ <input type="hidden" name="class" value="Specfem3DGlobeModel">
+ <input type="hidden" name="action" value="link">
+
+ <div class=tab30ex>
+
+ <p>Use this form to tell the portal about a large Earth model you
+ wish to incorporate into your simulations. The Earth model
+ file must be available via publically accessible URL.</p>
+
+ <div>
+ <label for="id_url" class=before>URL</label>
+ {{ form.url }}
+ {% if form.url.errors %}<span class=error>{{ form.url.errors|join:", " }}</span>{% endif %}
+ </div>
+
+ <div>
+ <input class=submit type="submit" value="Save">
+ </div>
+
+ </div> <!-- tab30ex -->
+
+</form>
Modified: cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_upload.html
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_upload.html 2009-02-10 02:28:45 UTC (rev 14031)
+++ cs/portal/trunk/northridge/SeismoWebPortal/templates/SeismoWebPortal/specfem3dglobemodel_upload.html 2009-02-10 22:23:59 UTC (rev 14032)
@@ -21,6 +21,8 @@
<input class=submit type="submit" value="Upload">
</div>
+ <p><b>Tip:</b> If your model file is too large to upload, use <a href="{{root}}/?class=Specfem3DGlobeModel&action=link">this form</a> instead.</p>
+
</div> <!-- tab30ex -->
</form>
@@ -29,7 +31,7 @@
<p><a href="{{root}}/samples/chino-1.0.1.tar.gz">Download
Chino</a>. Chino is a utility which will help you create and debug an
-earth model plug-in. To run Chino:</p>
+Earth model plug-in. To run Chino:</p>
<blockquote><pre>
tar xzf chino-1.0.1.tar.gz
@@ -45,7 +47,7 @@
<h3>Code for 1D Reference Models</h3>
-<p>You may incorporate any one of these into your earth model.</p>
+<p>You may incorporate any one of these into your Earth model.</p>
<ul>
<li><a href="{{root}}/samples/ref.tgz">ref.tgz</a></li>
Modified: cs/portal/trunk/northridge/SeismoWebPortal/views.py
===================================================================
--- cs/portal/trunk/northridge/SeismoWebPortal/views.py 2009-02-10 02:28:45 UTC (rev 14031)
+++ cs/portal/trunk/northridge/SeismoWebPortal/views.py 2009-02-10 22:23:59 UTC (rev 14032)
@@ -63,6 +63,8 @@
ret = Class.create(request)
elif action == 'upload':
ret = Class.upload(request)
+ elif action == 'link':
+ ret = Class.link(request)
elif action == 'search':
ret = Class.search(request)
@@ -150,6 +152,7 @@
c.update(dict(
creatable = Class.creatable,
uploadable = Class.uploadable,
+ linkable = Class.linkable,
klass = Class.__name__,
))
More information about the CIG-COMMITS
mailing list