Permalink
Browse files

Merge branch 'warehouse'

  • Loading branch information...
xtoddx committed Apr 23, 2012
2 parents bbb2fa1 + 38f5d06 commit d7a4c202d68dd323599ee7a5671097d20a254ac2
@@ -1,5 +1,5 @@
from django import forms
-from models import UpdateFrequency, CoordSystem, UrlType, DataType
+from models import UpdateFrequency, CoordSystem, UrlType, DataType, Resource
class SubmissionForm(forms.Form):
dataset_name = forms.CharField(max_length=255, label="Data set, API or App name")
@@ -26,3 +26,13 @@ class SubmissionForm(forms.Form):
certified = forms.BooleanField(required=False, label="", help_text="I am the copyright holder or have permission to release this data")
terms = forms.BooleanField(label="", help_text="I have read and agree with the site's <a href='/terms/' target='_blank'>terms of use</a>")
+
+class ResourceForm(forms.ModelForm):
+ bucket = forms.CharField(max_length=80, widget=forms.HiddenInput)
+ key = forms.CharField(max_length=255, widget=forms.HiddenInput)
+ url = forms.CharField(max_length=255)
+
+ class Meta:
+ model = Resource
+ fields = ('name', 'is_published', 'description', 'short_description',
+ 'usage')
@@ -0,0 +1,16 @@
+{% extends "template1.html" %}
+{% block title %} - Create Resource from Upload{% endblock %}
+
+{% block center_container %}
+ <div id="form_container" class="resource_form">
+
+ <h1>{{ url }} Uploaded</h1>
+ <h2>Now fill out this form to make a listing for this data</h2>
+
+ <form id="resource_from" action="{{ SITE_ROOT }}/warehouse/finalize/" method="post">
+ {% csrf_token %}
+ {{ form.as_p }}
+ <input type="submit" value="Create Catalog Page">
+ </form>
+ </div>
+{% endblock %}
@@ -3,4 +3,5 @@
urlpatterns = patterns('',
(r'upload/$', 'warehouse.views.upload'),
(r'postback/$', 'warehouse.views.postback'),
+ (r'finalize/$', 'warehouse.views.finalize'),
)
@@ -6,11 +6,15 @@
from django.conf import settings
from django.contrib.auth.decorators import login_required, permission_required
-from django.contrib.auth.models import User
-from django.shortcuts import render_to_response
+from django.contrib.auth.models import User, Group
+from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
#from django.http import HttpResponseRedirect
+from opendata.forms import ResourceForm
+from opendata.models import Url, UrlType
+from models import Warehouse
+
class FormGenerator(object):
def __init__(self, user):
@@ -71,6 +75,7 @@ def _find_warehouse(self):
@permission_required('warehouse.upload')
+@permission_required('opendata.add_resource')
def upload(request):
# TODO(todd): make sure they have upload access warehouse.upload
user = User.objects.get(username=request.user)
@@ -79,5 +84,42 @@ def upload(request):
context_instance=RequestContext(request))
+@permission_required('warehouse.upload')
+@permission_required('opendata.add_resource')
def postback(request):
- pass
+ bucket = request.GET['bucket']
+ key = request.GET['key']
+ url = 'https://%s.s3.amazonaws.com/%s' % (bucket, key)
+ form = ResourceForm(initial={'key': key, 'bucket': bucket, 'url': url})
+ return render_to_response('warehouse/resource.html',
+ {'form': form, 'url': url},
+ context_instance=RequestContext(request))
+
+
+@permission_required('warehouse.upload')
+@permission_required('opendata.add_resource')
+def finalize(request):
+ form = ResourceForm(request.POST)
+ user = User.objects.get(username=request.user)
+ warehouse = Warehouse.objects.get(
+ bucket_name=form.data['bucket'])
+ group = warehouse.group
+ form.instance.organization = group.name
+ form.instance.created_by = user
+ form.instance.last_updated_by = user
+ form.instance.created = datetime.datetime.utcnow()
+ if form.is_valid():
+ resource = form.save()
+ url_type = UrlType.objects.get(url_type='Warehouse')
+ url = Url()
+ url.resource = resource
+ url.url_type = url_type
+ url.url = form.data['url']
+ url.url_label = form.data['url']
+ url.save()
+ return redirect('%s/opendata/resource/%i' % (settings.SITE_ROOT,
+ resource.pk))
+ else:
+ return render_to_response('warehouse/resource.html',
+ {'form': form, 'url': form.data['url']},
+ context_instance=RequestContext(request))

0 comments on commit d7a4c20

Please sign in to comment.