Commits

sammyrulez committed 4e71400

data browser ok

Comments (0)

Files changed (7)

uiforms/templates/admin/tmanager/data_list.html

+{% extends 'admin/base_site.html' %}
+
+{% block content %}
+	<h2> Previw </h2> 
+	
+	
+	
+	{% for obj in objects %}
+	<p>
+		<strong>  {{ obj }} : </strong> <a href="{% url detail obj.id %}">Detail</a>
+	</p>
+	{% endfor %}
+
+{% endblock %}

uiforms/templates/admin/tmanager/preview.html

 {% block content %}
 	<h2> Previw </h2> 
 	
-	{{ form.as_p }}
+	
 	
 	{% for  field in form %}
 	<p>

uiforms/tmanager/admin.py

     model = TemplateField
 	
 	
-def share(obj):
-	return "<a href=\"%s\">Share</a>" % urlresolvers.reverse('share',args=[obj.id])
-	
-share.allow_tags = True
-	
-def preview(obj):
-	return "<a href=\"%s\">Preview</a>" % urlresolvers.reverse('preview',args=[obj.id])
-	
-preview.allow_tags = True
+
 
 class FormTemplateAdmin(admin.ModelAdmin):
 	inlines = [ TemplateFieldInline,]
+	
+	def share(self,obj):
+		return "<a href=\"%s\">Share</a>" % urlresolvers.reverse('share',args=[obj.id])
+	
+	share.allow_tags = True
+	
+	def preview(self,obj):
+		return "<a href=\"%s\">Preview</a>" % urlresolvers.reverse('preview',args=[obj.id])
+	
+	preview.allow_tags = True
+	
 	list_display  = ['name','share','preview']
 
 
 admin.site.register(FormTemplate, FormTemplateAdmin)
+
+admin.site.register(TemplateData)
+admin.site.register(TemplateDataRow)

uiforms/tmanager/fixtures/test_data_fixtures.json

 [
- {
-  "pk": 1, 
-  "model": "tmanager.formtemplate", 
-  "fields": {
-   "owner": 1, 
-   "name": "TestForm"
+  {
+    "pk": 1, 
+    "model": "tmanager.formtemplate", 
+    "fields": {
+      "owner": 1, 
+      "name": "TestForm"
+    }
+  }, 
+  {
+    "pk": 1, 
+    "model": "tmanager.templatefield", 
+    "fields": {
+      "filed_type": "BOOLEAN", 
+      "template": 1, 
+      "label": "is_it_cool?"
+    }
+  }, 
+  {
+    "pk": 2, 
+    "model": "tmanager.templatefield", 
+    "fields": {
+      "filed_type": "INTEGER", 
+      "template": 1, 
+      "label": "How_old_are_U?"
+    }
+  }, 
+  {
+    "pk": 1, 
+    "model": "tmanager.templatedata", 
+    "fields": {
+      "submitted_by": 1, 
+      "template_ref": 1, 
+      "modified": "2011-12-22 08:22:05", 
+      "created": "2011-12-22 08:22:05"
+    }
+  }, 
+  {
+    "pk": 1, 
+    "model": "tmanager.templatedatarow", 
+    "fields": {
+      "template_data": 1, 
+      "template_field": 1, 
+      "payload": "True"
+    }
+  }, 
+  {
+    "pk": 2, 
+    "model": "tmanager.templatedatarow", 
+    "fields": {
+      "template_data": 1, 
+      "template_field": 2, 
+      "payload": "19"
+    }
   }
- }, 
- {
-  "pk": 1, 
-  "model": "tmanager.templatefield", 
-  "fields": {
-   "filed_type": "BOOLEAN", 
-   "template": 1, 
-   "label": "is_it_cool?"
-  }
- }, 
- {
-  "pk": 2, 
-  "model": "tmanager.templatefield", 
-  "fields": {
-   "filed_type": "INTEGER", 
-   "template": 1, 
-   "label": "How_old_are_U?"
-  }
- }
 ]

uiforms/tmanager/tests.py

 		post_response = self.client.post(urlresolvers.reverse('share',args=[1]), { 'email':'your_email@example.com'})
 		self.assertEquals(302,post_response.status_code) #check redirect
 		
-class OwnedDataViewTest(TestCase):
+class AdminTest(TestCase):
+	
+	fixtures = ['user_fixtures.json', 'test_data_fixtures.json']
+	
+	def setUp(self):
+		self.client = Client()
+		self.client.login(username='admin', password='admin')
+	
+	def test_template_from_index(self):
+		response = self.client.get(urlresolvers.reverse("admin:tmanager_formtemplate_changelist"))
+		
+		self.assertEquals(200,response.status_code)
+		self.assertTrue(response.content.count("Share") > 0)
+		self.assertTrue(response.content.count("Preview") > 0)
+		#TODO proper link testing
+		
+		
+class ClassViewTest(TestCase):
 		
 	fixtures = ['user_fixtures.json', 'test_data_fixtures.json']
 		
 		self.client = Client()
 		self.client.login(username='admin', password='admin')
 	
-	def test_get_queryset(self):
-		view = OwnedDataView()
+	def test_detail(self):
+		response = self.client.get(urlresolvers.reverse('detail',args=[1]))
+		self.assertEquals(200,response.status_code)
+		response = self.client.get(urlresolvers.reverse('detail',args=[2])) # not ownig
+		self.assertEquals(404,response.status_code)
+		response = self.client.get(urlresolvers.reverse('detail',args=[1989])) #non existing
+		self.assertEquals(404,response.status_code)
+		
+	def test_owned_data(self):
+		response_ow = self.client.get(urlresolvers.reverse('owned_data'))
+		self.assertEquals(200,response_ow.status_code)
+		#TODO Check not owned
+		
+	def test_submitted_data(self):
+		response = self.client.get(urlresolvers.reverse('submitted_data'))
+		self.assertEquals(200,response.status_code)
+		#TODO Check not owned
+		
+		
+	
+		
 		
 		
 		

uiforms/tmanager/views.py

 from django.http import Http404
 import random
 from django.views.generic import DetailView , ListView
+from django.utils.decorators import method_decorator
+from django.contrib.auth.decorators import login_required
 
 
-
+@login_required
 def uiform(request, template_id):
 
 	template = get_object_or_404(FormTemplate ,pk = template_id)
 		
 	return render_to_response('admin/tmanager/preview.html',{'form':form_instance, 'template_obj':template}) 
 	
+@login_required
 def clone_template(request, template_id):
 	if request.POST:
 		template = get_object_or_404(FormTemplate ,pk = template_id)
 	else:
 		raise Http404
 		
-
+@login_required
 def share_template(request, template_id):
 	if request.POST:
 		email_form = forms.EmailForm(request.POST)
 	return render_to_response('admin/tmanager/share.html',{'form':email_form}) 
 	
 
+#TODO Protectedview mixin
+	
 
 class DataDetailView(DetailView):
 	context_object_name = "template_data"
 	model = TemplateData
 	template_name = "admin/tmanager/data_detail.html"
 	
+	
+	@method_decorator(login_required)
+	def dispatch(self, *args, **kwargs):
+		return super(DataDetailView, self).dispatch(*args, **kwargs)
+	
 	def get_object(self):
 		template_data = super(DataDetailView, self).get_object()
 		if template_data.submitted_by != self.request.user and template_data.template_ref.owner != self.request.user :
 			return template_data
 			
 class OwnedDataView(ListView):
+	model = TemplateData
 	context_object_name = "objects"
 	template_name = "admin/tmanager/data_list.html"
 
+	@method_decorator(login_required)
+	def dispatch(self, *args, **kwargs):
+		return super(OwnedDataView, self).dispatch(*args, **kwargs)
+		
 	def get_queryset(self):
 		return TemplateData.objects.filter(template_ref__owner__id__exact =  self.request.user.id )
 	
 	context_object_name = "objects"
 	template_name = "admin/tmanager/data_list.html"
 
+	@method_decorator(login_required)
+	def dispatch(self, *args, **kwargs):
+		return super(SubmittedDataView, self).dispatch(*args, **kwargs)
+	
 	def get_queryset(self):
 		return TemplateData.objects.filter(submitted_by__id__exact =  self.request.user.id )
 		
 from django.conf.urls.defaults import patterns, include, url
+from uiforms.tmanager.views import DataDetailView ,OwnedDataView , SubmittedDataView
+
+from django.views.generic import DetailView , ListView
+from uiforms.tmanager.models import FormTemplate , TemplateField ,TemplateData 
 
 # Uncomment the next two lines to enable the admin:
 from django.contrib import admin
 
     # Uncomment the next line to enable the admin:
     url(r'^admin/', include(admin.site.urls)),
-	#uiform -get mostra post salva
+	
 	url(r'^admin/uiform/(?P<template_id>\d+)/$','uiforms.tmanager.views.uiform',name='uiform'),
 	url(r'^admin/uiform_preview/(?P<template_id>\d+)/$','uiforms.tmanager.views.uiform_preview',name='preview'),
 	url(r'^admin/uiform_clone/(?P<template_id>\d+)/$','uiforms.tmanager.views.clone_template',name='clone'),
 	url(r'^admin/uiform_share/(?P<template_id>\d+)/$','uiforms.tmanager.views.share_template',name='share'),
-	#uiform-preview - get mostra post clona 
+	url(r'^data_owned/$',OwnedDataView.as_view(),name='owned_data'),
+	url(r'^data_submitted/$',SubmittedDataView.as_view(),name='submitted_data'),
+	url(r'^data_detail/(?P<pk>\d+)/$',DataDetailView.as_view(),name='detail'),
+	
+	
+	
 )