[cig-commits] r11354 - in cs/portal/trunk/seismo/SeismoWebPortal: . templates/SeismoWebPortal

leif at geodynamics.org leif at geodynamics.org
Thu Mar 6 15:47:25 PST 2008


Author: leif
Date: 2008-03-06 15:47:25 -0800 (Thu, 06 Mar 2008)
New Revision: 11354

Modified:
   cs/portal/trunk/seismo/SeismoWebPortal/templates/SeismoWebPortal/mineosmodecatalog_form.html
   cs/portal/trunk/seismo/SeismoWebPortal/templates/SeismoWebPortal/mineosparameters_form.html
   cs/portal/trunk/seismo/SeismoWebPortal/templates/SeismoWebPortal/object_lists.html
   cs/portal/trunk/seismo/SeismoWebPortal/urls.py
   cs/portal/trunk/seismo/SeismoWebPortal/views.py
Log:
Abandoned Django's yucky 'urlpatterns' in favor of my own URL
resolution scheme.


Modified: cs/portal/trunk/seismo/SeismoWebPortal/templates/SeismoWebPortal/mineosmodecatalog_form.html
===================================================================
--- cs/portal/trunk/seismo/SeismoWebPortal/templates/SeismoWebPortal/mineosmodecatalog_form.html	2008-03-06 23:25:31 UTC (rev 11353)
+++ cs/portal/trunk/seismo/SeismoWebPortal/templates/SeismoWebPortal/mineosmodecatalog_form.html	2008-03-06 23:47:25 UTC (rev 11354)
@@ -16,7 +16,7 @@
     </form>
 
     {% if object %}
-    <form action="../delete/" method="get"><input type="submit" value="Delete" /></form>
+    <form action="delete/" method="get"><input type="submit" value="Delete" /></form>
     {% endif %}
 
 </div>

Modified: cs/portal/trunk/seismo/SeismoWebPortal/templates/SeismoWebPortal/mineosparameters_form.html
===================================================================
--- cs/portal/trunk/seismo/SeismoWebPortal/templates/SeismoWebPortal/mineosparameters_form.html	2008-03-06 23:25:31 UTC (rev 11353)
+++ cs/portal/trunk/seismo/SeismoWebPortal/templates/SeismoWebPortal/mineosparameters_form.html	2008-03-06 23:47:25 UTC (rev 11354)
@@ -16,7 +16,7 @@
     </form>
 
     {% if object %}
-    <form action="../delete/" method="get"><input type="submit" value="Delete" /></form>
+    <form action="delete/" method="get"><input type="submit" value="Delete" /></form>
     {% endif %}
 
 </div>

Modified: cs/portal/trunk/seismo/SeismoWebPortal/templates/SeismoWebPortal/object_lists.html
===================================================================
--- cs/portal/trunk/seismo/SeismoWebPortal/templates/SeismoWebPortal/object_lists.html	2008-03-06 23:25:31 UTC (rev 11353)
+++ cs/portal/trunk/seismo/SeismoWebPortal/templates/SeismoWebPortal/object_lists.html	2008-03-06 23:47:25 UTC (rev 11354)
@@ -18,7 +18,7 @@
         </select>
         <input type="submit" value="New Mesh..." />
     </form>
-    <form action="../models/create/" method="get"><input type="submit" value="New Model..." /></form>
+    <form action="specfem3dglobe/models/create/" method="get"><input type="submit" value="New Model..." /></form>
 </div>
 
 <p>
@@ -38,7 +38,7 @@
             <th><a href="/specfem3dglobe/simulations/{{ sim.id }}/">{{ sim.name }}</a></th>
             <td><a href="/specfem3dglobe/meshes/{{ sim.mesh.id }}/">{{ sim.mesh }}</a><br>
                 <span class=inlineInfo>shortest period &cong; {{ sim.mesh.shortestPeriod|stringformat:".0f" }}s</span></td>
-            <td><a href="/specfem3dglobe/models/{{ sim.model.id }}/">{{ sim.model }}</a></td>
+            <td><a href="specfem3dglobe/models/{{ sim.model.id }}/">{{ sim.model }}</a></td>
             <td><a href="/specfem3dglobe/stations/{{ sim.stations.id }}/">{{ sim.stations }}</a></td>
             <td>{{ sim.record_length }} minutes</td>
         </tr>
@@ -152,7 +152,7 @@
         <tbody>
         {% for object in model_list %}
         <tr>
-            <th><a href="../models/{{ object.id }}/">{{ object.name }}</a></th>
+            <th><a href="specfem3dglobe/models/{{ object.id }}/">{{ object.name }}</a></th>
             <td>{{ object.get_type_display }}</td>
             <td><span class={{ object.oceans }}>{{ object.oceans }}</span></td>
             <td><span class={{ object.gravity }}>{{ object.gravity }}</span></td>

Modified: cs/portal/trunk/seismo/SeismoWebPortal/urls.py
===================================================================
--- cs/portal/trunk/seismo/SeismoWebPortal/urls.py	2008-03-06 23:25:31 UTC (rev 11353)
+++ cs/portal/trunk/seismo/SeismoWebPortal/urls.py	2008-03-06 23:47:25 UTC (rev 11354)
@@ -1,213 +1,12 @@
 
-import os
 
-from django.conf.urls.defaults import *
-from models import Mesh, Model, Specfem3DGlobeParameters, UserInfo
-from models import MineosModeCatalog, MineosParameters
-from models import Event, Source
-from models import Station, StationList, StationNetwork
-from models import Run, Job, OutputFile
+class Resolver(object):
+    def __init__(self):
+        import re
+        self.regex = re.compile('^(.*)$')
+    def resolve(self, pathname):
+        import views
+        return views.root, (pathname, ), {}
+        
 
-# Static Paths
-static_media_root = os.environ.get("WEBPORTAL_MEDIA_ROOT")+'/static'
-
-
-
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# Meshes, Models, Simulations
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-
-# Mesh
-
-
-mesh_delete_args = {
-    'model': Mesh,
-    'post_delete_redirect': '/specfem3dglobe/objects/',
-}
-
-
-
-# Model
-
-model_delete_args = {
-    'model': Model,
-    'post_delete_redirect': '/specfem3dglobe/objects/',
-}
-
-
-
-# Simulation
-
-simulation_delete_args = {
-    'model': Specfem3DGlobeParameters,
-    'post_delete_redirect': '/specfem3dglobe/objects/',
-}
-
-
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# Registration
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-
-password_change_args = {
-    'template_name': 'SeismoWebPortal/password_change_form.html',
-}
-
-
-
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# Events
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-
-event_list_detail_args = {
-    'queryset': Event.user_objects.all(),
-    'allow_empty': True,
-}
-
-event_detail_args = {
-    'queryset': Event.user_objects.all(),
-    'extra_context': { 'object_list': Event.user_objects.all() },
-}
-
-event_delete_args = {
-    'model': Event,
-    'post_delete_redirect': '/specfem3dglobe/events/',
-    }
-
-source_detail_args = {
-    'queryset': Source.objects.all(),
-}
-
-source_create_update_args = {
-    'model': Source,
-    'post_save_redirect': '/specfem3dglobe/events/',
-    }
-
-source_delete_args = {
-    'model': Source,
-    'post_delete_redirect': '/specfem3dglobe/events/',
-    }
-
-
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# Stations
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-
-stationlist_delete_args = {
-    'model': StationList,
-    'post_delete_redirect': '/specfem3dglobe/stations/',
-    }
-
-
-stationlist_create_update_args = {
-    'model': StationList,
-    'post_save_redirect': '/specfem3dglobe/stations/',
-    'follow': { 'user': False },
-    }
-
-
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# Runs, Jobs, Output
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-
-run_list_detail_args = {
-    'queryset': Run.objects.all(),
-    'allow_empty': True,
-}
-
-
-
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# URLs
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-urlpatterns = patterns('',
-    (r'^$', 'SeismoWebPortal.views.home'),
-
-    (r'^login/$', 'SeismoWebPortal.views.login_view'),
-    (r'^logout/$', 'SeismoWebPortal.views.logout_view'),
-    (r'^pwreset/$', 'SeismoWebPortal.views.password_reset'),
-    (r'^pwreset/done/$', 'django.views.generic.simple.direct_to_template', { 'template': 'registration/pwreset_done.html'}),
-    
-    (r'^registration/$', 'SeismoWebPortal.views.registration'),
-    (r'^registration/password/$', 'SeismoWebPortal.views.password_change', password_change_args),
-
-    (r'^objects/$', 'SeismoWebPortal.views.object_list'),
-    (r'^objects/mineos/modes/create/$', 'SeismoWebPortal.views.create', dict(ModelClass = MineosModeCatalog)),
-    (r'^objects/mineos/modes/(?P<object_id>\d+)/$', 'SeismoWebPortal.views.update', dict(ModelClass = MineosModeCatalog)),
-    (r'^objects/mineos/parameters/create/$', 'SeismoWebPortal.views.create', dict(ModelClass = MineosParameters)),
-    (r'^objects/mineos/parameters/(?P<object_id>\d+)/$', 'SeismoWebPortal.views.update', dict(ModelClass = MineosParameters)),
-
-    (r'^meshes/create/$', 'SeismoWebPortal.views.create_mesh'),
-    (r'^meshes/create/(?P<nchunks>\d+)/$', 'SeismoWebPortal.views.manipulate_mesh', dict(action='create')),
-    (r'^meshes/(?P<object_id>\d+)/$', 'SeismoWebPortal.views.manipulate_mesh', dict(action='edit')),
-    (r'^meshes/(?P<object_id>\d+)/delete/$', 'django.views.generic.create_update.delete_object', mesh_delete_args),
-
-    (r'^models/create/$', 'SeismoWebPortal.views.create', dict(ModelClass = Model)),
-    (r'^models/(?P<object_id>\d+)/$', 'SeismoWebPortal.views.update', dict(ModelClass = Model)),
-    (r'^models/(?P<object_id>\d+)/delete/$', 'django.views.generic.create_update.delete_object', model_delete_args),
-
-    (r'^simulations/create/$', 'SeismoWebPortal.views.create_simulation'),
-    (r'^simulations/(?P<object_id>\d+)/$', 'SeismoWebPortal.views.simulation_detail'),
-    (r'^simulations/(?P<object_id>\d+)/edit/$', 'SeismoWebPortal.views.update_simulation'),
-    (r'^simulations/(?P<object_id>\d+)/delete/$', 'django.views.generic.create_update.delete_object', simulation_delete_args),
-    (r'^simulations/(?P<object_id>\d+)/run/$', 'SeismoWebPortal.views.run_simulation'),
-    (r'^simulations/(?P<sim_id>\d+)/par_file\.txt$', 'SeismoWebPortal.views.par_file'),
-    (r'^simulations/(?P<sim_id>\d+)/parameters\.pml$', 'SeismoWebPortal.views.parameters_pml'),
-    (r'^simulations/(?P<sim_id>\d+)/stations\.txt$', 'SeismoWebPortal.views.stations_txt'),
-    (r'^simulations/(?P<sim_id>\d+)/events\.txt$', 'SeismoWebPortal.views.events_txt'),
-    (r'^simulations/(?P<sim_id>\d+)/mineos/parameters\.pml$', 'SeismoWebPortal.views.mineos_parameters_pml'),
-    (r'^simulations/(?P<sim_id>\d+)/mineos/event\.txt$', 'SeismoWebPortal.views.mineos_event_txt'),
-    (r'^simulations/(?P<sim_id>\d+)/mineos/stations\.site$', 'SeismoWebPortal.views.mineos_stations_site'),
-    (r'^simulations/(?P<sim_id>\d+)/mineos/stations\.sitechan$', 'SeismoWebPortal.views.mineos_stations_sitechan'),
-
-    # events
-    (r'^events/$', 'django.views.generic.list_detail.object_list', event_list_detail_args),
-    (r'^events/search/$', 'SeismoWebPortal.views.event_search'),
-    (r'^events/create/$', 'SeismoWebPortal.views.manipulate_event', dict(action='create')),
-    (r'^events/upload/$', 'SeismoWebPortal.views.upload_event'),
-    (r'^events/sources/(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', source_detail_args),
-    (r'^events/sources/(?P<object_id>\d+)/edit/$', 'django.views.generic.create_update.update_object', source_create_update_args),
-    (r'^events/sources/(?P<object_id>\d+)/delete/$', 'django.views.generic.create_update.delete_object', source_delete_args),
-    (r'^events/sources/(?P<object_id>\d+)/CMTSOLUTION\.txt$', 'SeismoWebPortal.views.cmtsolution_txt'),
-    (r'^events/sources/(?P<source_id>\d+)/beachball\.gif$', 'SeismoWebPortal.views.beachball_gif'),
-    (r'^events/(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', event_detail_args),
-    (r'^events/(?P<object_id>\d+)/edit/$', 'SeismoWebPortal.views.manipulate_event', dict(action='edit')),
-    (r'^events/(?P<object_id>\d+)/delete/$', 'django.views.generic.create_update.delete_object', event_delete_args),
-    (r'^events/(?P<object_id>\d+)/CMTSOLUTION\.txt$','SeismoWebPortal.views.event_detail_cmtsolution_txt'),
-    (r'^events/(?P<event_id>\d+)/beachball\.gif$', 'SeismoWebPortal.views.beachball_gif'),
-    (r'^events/(?P<object_id>\d+)/gearth\.kml$','SeismoWebPortal.views.event_detail_gearth'),
-
-    # stations
-    (r'^stations/upload/$', 'SeismoWebPortal.views.upload_station_list'),
-    (r'^stations/(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', {'queryset': StationList.user_objects.all()}),
-    (r'^stations/(?P<object_id>\d+)/edit/$', 'django.views.generic.create_update.update_object', stationlist_create_update_args),
-    (r'^stations/(?P<object_id>\d+)/delete/$', 'django.views.generic.create_update.delete_object', stationlist_delete_args),
-    (r'^stations/(?P<object_id>\d+)/stations\.txt$','SeismoWebPortal.views.stationlist_detail_txt'),
-    (r'^stations/(?P<object_id>\d+)/gearth\.kml$','SeismoWebPortal.views.stationlist_detail_gearth'),
-
-    # runs
-    (r'^runs/list\.py$', 'django.views.generic.list_detail.object_list', dict(run_list_detail_args,
-                                                                             template_name='SeismoWebPortal/run_list.py',
-                                                                             mimetype='text/plain')),
-    (r'^runs/(?P<object_id>\d+)/status/$', 'SeismoWebPortal.views.update_run_status'),
-
-    # jobs
-    (r'^jobs/create/$', 'SeismoWebPortal.views.daemon_post', dict(modelName='Job', action='create')),
-    (r'^jobs/(?P<object_id>\d+)/update/$', 'SeismoWebPortal.views.daemon_post', dict(modelName='Job', action='update')),
-
-    # output files
-    (r'^output/create/$', 'SeismoWebPortal.views.daemon_post', dict(modelName='OutputFile', action='create')),
-
-    # help
-    (r'^help/toggle/$', 'SeismoWebPortal.views.help_toggle'),
-
-    (r'^(.*)', 'django.views.static.serve', {'document_root':static_media_root}),
-)
-
-
-# end of file
+urlpatterns = [Resolver()]

Modified: cs/portal/trunk/seismo/SeismoWebPortal/views.py
===================================================================
--- cs/portal/trunk/seismo/SeismoWebPortal/views.py	2008-03-06 23:25:31 UTC (rev 11353)
+++ cs/portal/trunk/seismo/SeismoWebPortal/views.py	2008-03-06 23:47:25 UTC (rev 11354)
@@ -2,7 +2,6 @@
 
 from django import forms
 from django.conf import settings
-from django.contrib.auth import login, logout
 from django.contrib.auth.decorators import user_passes_test
 from django.core import validators
 from django.http import HttpResponse, HttpResponseRedirect, Http404
@@ -19,10 +18,90 @@
 from HTMLParser import HTMLParser
 
 
-from models import Specfem3DGlobeParameters as Simulation # NYI
+from models import Specfem3DGlobeParameters
+Simulation = Specfem3DGlobeParameters # NYI
 
+static_media_root = os.environ.get("WEBPORTAL_MEDIA_ROOT")+'/static'
 
+
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# resolving paths
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+class Index(dict):
+    def __getitem__(self, key):
+        try:
+            return dict.__getitem__(self, key)
+        except KeyError:
+            raise Http404
+
+
+def intOr404(name):
+    try:
+        ret = int(name)
+    except ValueError:
+        raise Http404
+    return ret
+
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# root
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+def root(request, pathname):
+    from django.views.static import serve as staticServe
+    
+    path = pathname.split('/')
+    if path[-1] == "":
+        path.pop()
+
+    if not path:
+        return home(request)
+
+    name = path.pop(0)
+
+    static = lambda request, path: staticServe(request, pathname, document_root = static_media_root)
+
+    index = Index({
+        "login": login,
+        "pwreset": pwreset,
+        "registration": registration,
+        "runs": runs, # accessed by daemon
+        "jobs": jobs, # accessed by daemon
+        "output": output, # accessed by daemon
+        "css": static,
+        "doc": static,
+        "pics": static,
+        "samples": static,
+        })
+
+    publicView = index.get(name)
+    if publicView:
+        return publicView(request, path)
+
+    # Login is required for everything beyond this point.
+    if request.user.is_anonymous():
+        from opal.contrib.auth import REDIRECT_FIELD_NAME
+        from urllib import quote
+        return HttpResponseRedirect('/specfem3dglobe/login?%s=%s' %
+                                    (REDIRECT_FIELD_NAME, quote(request.get_full_path())))
+
+    index = Index({
+        "objects": objects,
+        "meshes": meshes,
+        "simulations": simulations,
+        "events": events,
+        "stations": stations,
+        "logout": logout,
+        "help": help,
+        })
+
+    return index[name](request, path)
+
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # Meshes, Models, Simulations
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -31,10 +110,6 @@
 disapproval = "You cannot run simulations until you are approved by a site administrator."
 
 
-# Create our own version of 'login_required' which redirects to our login page.
-login_required = user_passes_test(lambda u: not u.is_anonymous(), "/specfem3dglobe/login")
-
-
 def home(request):
     if request.user.is_anonymous():
         return render_to_response('SeismoWebPortal/splash.html', {},
@@ -44,7 +119,34 @@
                               RequestContext(request, {}))
 
 
-def object_list(request):
+def objects(request, path):
+    from django.views.generic.create_update import delete_object
+
+    if path:
+        name = path.pop(0)
+        index = Index({
+            "specfem3dglobe": {"models": Model},
+            "mineos": {"modes": MineosModeCatalog, "parameters": MineosParameters},
+            })
+        index = index[name]
+        name = path.pop(0)
+        ModelClass = index[name]
+        name = path.pop(0)
+        if name == "create":
+            if path: raise Http404
+            return create(request, ModelClass = ModelClass)
+        objId = intOr404(name)
+        if not path:
+            return update(request, object_id = objId, ModelClass = ModelClass)
+        name = path.pop(0)
+        if name == "delete":
+            if path: raise Http404
+            return delete_object(request,
+                                 object_id = objId,
+                                 model = ModelClass,
+                                 post_delete_redirect = "/specfem3dglobe/objects/")
+        raise Http404
+
     return render_to_response('SeismoWebPortal/object_lists.html',
                               {'simulation_list': Simulation.objects.filter(user=request.user),
                                'mesh_list': Mesh.user_objects.all(),
@@ -54,9 +156,49 @@
                                'station_lists': StationList.objects.filter(user__exact=request.user),
                                },
                               RequestContext(request, {}))
-object_list = login_required(object_list)
 
 
+def simulations(request, path):
+    from django.views.generic.create_update import delete_object
+    
+    name = path.pop(0)
+    if name == "create":
+        return create_simulation(request)
+    
+    objId = intOr404(name)
+    if not path:
+        return simulation_detail(request, object_id = objId)
+    
+    name = path.pop(0)
+            
+    if name == "mineos":
+        name = path.pop(0)
+        index = Index({
+            "parameters.pml": mineos_parameters_pml,
+            "event.txt": mineos_event_txt,
+            "stations.site": mineos_stations_site,
+            "stations.sitechan": mineos_stations_sitechan,
+            })
+        return index[name](request, sim_id = objId)
+    
+    if path: raise Http404
+    
+    index = Index({
+        "edit": (update_simulation, (), dict(object_id = objId)),
+        "delete": (delete_object, (), dict(object_id = objId,
+                                           model = Specfem3DGlobeParameters,
+                                           post_delete_redirect = "/specfem3dglobe/objects/")),
+        "run": (run_simulation, (), dict(object_id = objId)),
+        "par_file.txt": (par_file, (), dict(sim_id = objId)),
+        "parameters.pml": (parameters_pml, (), dict(sim_id = objId)),
+        "stations.txt": (stations_txt, (), dict(sim_id = objId)),
+        "events.txt": (events_txt, (), dict(sim_id = objId)),
+        })
+    view, args, kwds = index[name]
+    return view(request, *args, **kwds)
+
+
+
 def create_simulation(request):
     def post_save(object):
         user = request.user
@@ -72,7 +214,6 @@
                          follow = { 'user': False },
                          post_save_hook=post_save,
                          )
-create_simulation = login_required(create_simulation)
 
 
 def update_simulation(request, object_id):
@@ -91,7 +232,6 @@
                          follow = { 'user': False },
                          post_save_hook=post_save,
                          )
-update_simulation = login_required(update_simulation)
 
 
 def run_simulation(request, object_id):
@@ -113,13 +253,11 @@
 
     raise Http404
 
-run_simulation = login_required(run_simulation)
 
 
 def simulation_detail(request, object_id):
     from django.views.generic.list_detail import object_detail
     return object_detail(request, Simulation.user_objects.all(), object_id)
-simulation_detail = login_required(simulation_detail)
 
 
 def par_file(request, sim_id):
@@ -152,11 +290,15 @@
     response.write(t.render(c))
     return response
 
-def login_view(request, template_name='registration/login.html'):
+def login(request, path, template_name='registration/login.html'):
+    from django.contrib.auth import login as loginUser
     "Displays the login form and handles the login action."
     from django.contrib.auth.forms import AuthenticationForm
     from django.contrib.auth import LOGIN_URL, REDIRECT_FIELD_NAME
     from django.contrib.sites.models import Site
+    
+    if path: raise Http404
+    
     manipulator = AuthenticationForm(request)
     redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
     if request.POST:
@@ -167,7 +309,7 @@
                 redirect_to = '/accounts/profile/'
             from django.contrib.auth import login
             user = manipulator.get_user()
-            login(request, user)
+            loginUser(request, user)
             request.session.delete_test_cookie()
             help_login_hook(request, user)
             return HttpResponseRedirect(redirect_to)
@@ -180,12 +322,25 @@
         'site_name': Site.objects.get_current().name,
     }, context_instance=RequestContext(request))
 
-def logout_view(request):
-    logout(request)
+def logout(request, path):
+    from django.contrib.auth import logout as logoutUser
+    
+    if path: raise Http404
+    
+    logoutUser(request)
     return HttpResponseRedirect('/specfem3dglobe/login/')
 
-def password_reset(request):
+def pwreset(request, path):
+    from django.views.generic.simple import direct_to_template
     from django.contrib.auth.forms import PasswordResetForm
+    
+    if path:
+        name = path.pop(0)
+        if path: raise Http404
+        if name == "done":
+            return direct_to_template(request, template = "registration/pwreset_done.html")
+        raise Http404
+
     new_data, errors = {}, {}
     form = PasswordResetForm()
     if request.POST:
@@ -254,6 +409,29 @@
     return response
 
 
+def runs(request, path):
+    from django.views.generic.list_detail import object_list
+    
+    if not path:
+        raise Http404
+    
+    name = path.pop(0)
+    
+    if name == "list.py":
+        if path: raise Http404
+        return object_list(request,
+                           queryset = Run.objects.all(),
+                           allow_empty = True,
+                           template_name = "SeismoWebPortal/run_list.py",
+                           mimetype = "text/plain")
+    
+    objId = intOr404(name)
+    if not path: raise Http404
+    name = path.pop(0)
+    if path or name != "status": raise Http404
+    return update_run_status(request, object_id = objId)
+
+
 def update_run_status(request, object_id):
     from forms import RunStatusManipulator
     import datetime
@@ -342,24 +520,23 @@
     return
 
 
-def daemon_post(request, modelName=None, action=None, object_id=None):
+def jobs(request, path):
+    return daemon_post(request, path, Job, "SeismoWebPortal/job_form.html")
 
-    if modelName == "Job":
-        Model = Job
-        template = 'SeismoWebPortal/job_form.html'
-    elif modelName == "OutputFile":
-        Model = OutputFile
-        template = 'SeismoWebPortal/outputfile_form.html'
+def output(request, path):
+    return daemon_post(request, path, OutputFile, "SeismoWebPortal/outputfile_form.html")
+
+def daemon_post(request, path, Model, template):
+    if not path: raise Http404
+    name = path.pop(0)
+    if name == "create":
+        if path: raise Http404
+        manipulator = Model.AddManipulator()
     else:
-        raise Http404
+        object_id = intOr404(name)
+        if len(path) != 1 or path[0] != "update": raise Http404
+        manipulator = Model.ChangeManipulator(object_id)
     
-    if action == "create":
-        manipulator = Model.AddManipulator()
-    elif action == "update":
-        manipulator = Model.ChangeManipulator(object_id)
-    else:
-        raise Http404
-
     if request.method == 'POST':
         response = HttpResponse(mimetype='text/plain')
         new_data = request.POST.copy()
@@ -382,7 +559,14 @@
                               {'form': form, 'action': request.path},
                               RequestContext(request, {}))
 
-def registration(request):
+def registration(request, path):
+    if path:
+        name = path.pop(0)
+        if path: raise Http404
+        if name == "password":
+            return password_change(request, template_name = "SeismoWebPortal/password_change_form.html")
+        raise Http404
+
     isNewUser = request.user.is_anonymous()
     if isNewUser:
         manipulator = RegistrationAddManipulator(request)
@@ -504,18 +688,45 @@
     return render_to_response(template_name, {'form': forms.FormWrapper(form, new_data, errors)},
         context_instance=RequestContext(request))
 
-password_change = login_required(password_change)
 
+def meshes(request, path):
+    from django.views.generic.create_update import delete_object
+    
+    if not path:
+        raise Http404
+    
+    name = path.pop(0)
+    
+    if name == "create":
+        if not path:
+            return create_mesh(request)
+        name = path.pop(0)
+        nchunks = intOr404(name)
+        if path: raise Http404
+        return manipulate_mesh(request, nchunks = nchunks, action='create')
+    
+    objId = intOr404(name)
+    if not path:
+        return manipulate_mesh(request, object_id = objId, action='edit')
+    name = path.pop(0)
+    if name == "delete":
+        if path: raise Http404
+        return delete_object(request,
+                             object_id = objId,
+                             model = Mesh,
+                             post_delete_redirect = "/specfem3dglobe/objects/")
 
+    raise Http404
+
+
 def create_mesh(request):
 
     if request.method != 'POST':
-        return HttpResponseRedirect('/specfem3dglobe/objects/')
+        return HttpResponseRedirect('/specfem3dglobe/meshes/')
         
     nchunks = int(request.POST['nchunks'])
-    return HttpResponseRedirect('/specfem3dglobe/objects/create/%d/' % nchunks)
+    return HttpResponseRedirect('/specfem3dglobe/meshes/create/%d/' % nchunks)
 
-create_mesh = login_required(create_mesh)
 
 
 
@@ -582,7 +793,6 @@
                                 },
                               RequestContext(request, {}))
 
-manipulate_mesh = login_required(manipulate_mesh)
 
 
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -596,7 +806,6 @@
                          post_save_redirect = '/specfem3dglobe/objects/',
                          follow = { 'user': False },
                          )
-create = login_required(create)
 
 
 def update(request, object_id, ModelClass):
@@ -606,7 +815,6 @@
                          post_save_redirect = '/specfem3dglobe/objects/',
                          follow = { 'user': False },
                          )
-update = login_required(update)
 
 
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -614,9 +822,97 @@
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 
-def event_search(request):
+def events(request, path):
+    from models import Event
+    from django.views.generic.list_detail import object_list, object_detail
+    from django.views.generic.create_update import delete_object
+    
+    if not path:
+        return object_list(request, queryset = Event.user_objects.all(), allow_empty = True)
+
+    name = path.pop(0)
+    index = Index({
+        "search": event_search,
+        "create": lambda request, path: manipulate_event(request, path, action='create'),
+        "upload": upload_event,
+        "sources": sources,
+        })
+    view = index.get(name)
+    if view:
+        return view(request, path)
+
+    objId = intOr404(name)
+    if not path:
+        return object_detail(
+            request,
+            object_id = objId,
+            queryset = Event.user_objects.all(),
+            extra_context = { 'object_list': Event.user_objects.all() },
+            )
+
+    name = path.pop(0)
+    if name == "edit":
+        return manipulate_event(request, path, object_id = objId, action = 'edit')
+    if name == "delete":
+        return delete_object(request,
+                             object_id = objId,
+                             model =  Event,
+                             post_delete_redirect = "/specfem3dglobe/events/",
+                             )
+    index = Index({
+        "CMTSOLUTION.txt": (event_detail_cmtsolution_txt, (), dict(object_id = objId)),
+        "beachball.gif": (beachball_gif, (), dict(event_id = objId)),
+        "gearth.kml": (event_detail_gearth, (), dict(object_id = objId)),
+        })
+    view, args, kwds = index[name]
+    return view(request, *args, **kwds)
+
+
+def sources(request, path):
+    from models import Source
+    from django.views.generic.list_detail import object_detail
+    from django.views.generic.create_update import update_object, delete_object
+
+    if not path:
+        raise Http404
+
+    name = path.pop(0)
+    objId = intOr404(name)
+
+    if not path:
+        return object_detail(request, object_id = objId, queryset = Source.objects.all())
+
+    name = path.pop(0)
+    if path: raise Http404
+
+    if name == "edit":
+        return update_object(
+            request,
+            object_id = objId,
+            model = Source,
+            post_save_redirect = "/specfem3dglobe/events/",
+            )
+    if name == "delete":
+        return delete_object(
+            request,
+            object_id = objId,
+            model = Source,
+            post_delete_redirect = "/specfem3dglobe/events/",
+            )
+
+    index = Index({
+        "CMTSOLUTION.txt": (cmtsolution_txt, (), dict(object_id = objId)),
+        "beachball.gif": (beachball_gif, (), dict(source_id = objId)),
+        })
+    view, args, kwds = index[name]
+    return view(request, *args, **kwds)
+    
+
+def event_search(request, path):
     import urllib2
 
+    if path: raise Http404
+
     if not request.GET:
         return render_to_response('SeismoWebPortal/event_search.html',
                                   {},
@@ -655,10 +951,12 @@
                               RequestContext(request, {})) 
 
 
-def manipulate_event(request, action=None, object_id=None):
+def manipulate_event(request, path, action=None, object_id=None):
     from models import Event
     from forms import SingleSourceEventAddManipulator, SingleSourceEventChangeManipulator
 
+    if path: raise Http404
+    
     if action == "create":
         manipulator = SingleSourceEventAddManipulator()
         event = None
@@ -696,13 +994,14 @@
                                },
                               RequestContext(request, {}))
 
-manipulate_event = login_required(manipulate_event)
 
 
-def upload_event(request):
+def upload_event(request, path):
     from forms import UploadEventManipulator
     from os.path import dirname
-    
+
+    if path: raise Http404
+
     manipulator = UploadEventManipulator()
     help_visible = get_help_visible(request)
     
@@ -822,6 +1121,46 @@
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 
+def stations(request, path):
+    from django.views.generic.list_detail import object_detail
+    from django.views.generic.create_update import update_object, delete_object
+    
+    if not path: raise Http404
+    name = path.pop(0)
+
+    if name == "upload":
+        if path: raise Http404
+        return upload_station_list(request)
+    
+    objId = intOr404(name)
+    if not path:
+        return object_detail(request, object_id = objId, queryset = StationList.user_objects.all())
+        
+    name = path.pop(0)
+    if path: raise Http404
+
+    if name == "edit":
+        return update_object(request,
+                             StationList,
+                             object_id = objId,
+                             post_save_redirect = "/specfem3dglobe/stations/%(id)d/",
+                             follow = { 'user': False },
+                             )
+    if name == "delete":
+        return delete_object(request,
+                             StationList,
+                             object_id = objId,
+                             post_delete_redirect = "/specfem3dglobe/objects/",
+                             )
+
+    index = Index({
+        "stations.txt": stationlist_detail_txt,
+        "gearth.kml": stationlist_detail_gearth,
+        })
+    view = index[name]
+    return view(request, object_id = objId)
+
+
 def upload_station_list(request):
     from os.path import dirname
     
@@ -852,7 +1191,6 @@
     return render_to_response('SeismoWebPortal/stationlist_upload.html',
                               {'form': form, 'help_visible': help_visible},
                               RequestContext(request, {}))
-upload_station_list = login_required(upload_station_list)
 
 
 def stationlist_detail_gearth(request, object_id):
@@ -954,8 +1292,8 @@
 
 from models import UserInfo
 
-def help_toggle(request):
-    if request.method != 'POST':
+def help(request, path):
+    if path != ["toggle"] or request.method != 'POST':
         raise Http404
     
     data = request.POST



More information about the cig-commits mailing list