Commits

sammyrulez committed 4f997b7

data preview ok

Comments (0)

Files changed (9)

uiforms/settings.py

     # Uncomment the next line to enable admin documentation:
     # 'django.contrib.admindocs',
 	'django_coverage',
-	'django_extensions',
 	'tmanager',
 )
 

uiforms/templates/admin/base_site.html

+{% extends "admin/base.html" %}
+{% load i18n %}
+
+{% block title %}{{ title }} | {% trans 'UIForms site admin' %}{% endblock %}
+
+{% block branding %}
+<h1 id="site-name">{% trans 'UIForms Manager' %}</h1>
+{% endblock %}
+
+{% block nav-global %}{% endblock %}

uiforms/templates/admin/index.html

+{% extends "admin/base_site.html" %}
+{% load i18n %}
+
+{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% load adminmedia %}{% admin_media_prefix %}css/dashboard.css" />{% endblock %}
+
+{% block coltype %}colMS{% endblock %}
+
+{% block bodyclass %}dashboard{% endblock %}
+
+{% block breadcrumbs %}{% endblock %}
+
+{% block content %}
+<div id="content-main">
+
+{% if app_list %}
+    {% for app in app_list %}
+        <div class="module">
+        <table summary="{% blocktrans with app.name as name %}Models available in the {{ name }} application.{% endblocktrans %}">
+        <caption><a href="{{ app.app_url }}" class="section">{% blocktrans with app.name as name %}{{ name }}{% endblocktrans %}</a></caption>
+        {% for model in app.models %}
+            <tr>
+            {% if model.perms.change %}
+                <th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
+            {% else %}
+                <th scope="row">{{ model.name }}</th>
+            {% endif %}
+
+            {% if model.perms.add %}
+                <td><a href="{{ model.admin_url }}add/" class="addlink">{% trans 'Add' %}</a></td>
+            {% else %}
+                <td>&nbsp;</td>
+            {% endif %}
+
+            {% if model.perms.change %}
+                <td><a href="{{ model.admin_url }}" class="changelink">{% trans 'Change' %}</a></td>
+            {% else %}
+                <td>&nbsp;</td>
+            {% endif %}
+            </tr>
+        {% endfor %}
+        </table>
+        </div>
+    {% endfor %}
+{% else %}
+    <p>{% trans "You don't have permission to edit anything." %}</p>
+{% endif %}
+</div>
+{% endblock %}
+
+{% block sidebar %}
+<div id="content-related">
+    <div class="module" id="custom-module">
+        <h2>{% trans 'Quick Data' %}</h2>
+        <h3>{% trans 'My collected data' %}</h3>
+        <p>
+            <a href="{% url owned_data %}">View</a>
+        </p>
+        <h3>{% trans 'My submitted data' %}</h3>
+        <p>
+            <a href="{% url submitted_data %}">View</a>
+        </p>
+    </div>
+    <div class="module" id="recent-actions-module">
+        <h2>{% trans 'Recent Actions' %}</h2>
+        <h3>{% trans 'My Actions' %}</h3>
+            {% load log %}
+            {% get_admin_log 10 as admin_log for_user user %}
+            {% if not admin_log %}
+            <p>{% trans 'None available' %}</p>
+            {% else %}
+            <ul class="actionlist">
+            {% for entry in admin_log %}
+            <li class="{% if entry.is_addition %}addlink{% endif %}{% if entry.is_change %}changelink{% endif %}{% if entry.is_deletion %}deletelink{% endif %}">
+                {% if entry.is_deletion or not entry.get_admin_url %}
+                    {{ entry.object_repr }}
+                {% else %}
+                    <a href="{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
+                {% endif %}
+                <br/>
+                {% if entry.content_type %}
+                    <span class="mini quiet">{% filter capfirst %}{% trans entry.content_type.name %}{% endfilter %}</span>
+                {% else %}
+                    <span class="mini quiet">{% trans 'Unknown content' %}</span>
+                {% endif %}
+            </li>
+            {% endfor %}
+            </ul>
+            {% endif %}
+    </div>
+</div>
+{% endblock %}

uiforms/templates/admin/tmanager/confirm_delete.html

+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+        "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+    <title></title>
+</head>
+<body>
+<h1>Not implemented yet</h1>
+</body>
+</html>

uiforms/templates/admin/tmanager/data_detail.html

+{% extends 'admin/base_site.html' %}
+
+{% block content %}
+    <h1> Detail </h1>
+
+ {{ template_data }}
+
+    {% for  data_row in template_data.templatedatarow_set.all %}
+        <p>
+            <strong>  {{ data_row.template_field.label }} : </strong> {{ data_row.payload }}
+        </p>
+    {% endfor %}
+
+{% endblock %}

uiforms/templates/admin/tmanager/data_list.html

 {% extends 'admin/base_site.html' %}
 
 {% block content %}
-	<h2> Previw </h2> 
-	
-	
+
 	
+<h1>
+    {{ title|default:'Collected Data' }}
+</h1>
+	<div class="content-main">
 	{% for obj in objects %}
 	<p>
 		<strong>  {{ obj }} : </strong> <a href="{% url detail obj.id %}">Detail</a>
 	</p>
+        {% empty %}
+        <h2>No data yet!</h2>
 	{% endfor %}
+    </div>
 
 {% endblock %}

uiforms/tmanager/admin.py

 from django.contrib import admin
-from models import FormTemplate , TemplateField ,TemplateData ,TemplateDataRow
+from models import FormTemplate, TemplateField, TemplateData, TemplateDataRow
 from django.core import urlresolvers
 
 class TemplateFieldInline(admin.TabularInline):
     model = TemplateField
-	
-	
 
 
 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']
+    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
+
+
+    def direct_link(self, obj):
+        return "<a href=\"%s\">Direct Link</a>" % urlresolvers.reverse('uiform', args=[obj.id])
+
+    direct_link.allow_tags = True
+
+
+
+    list_display = ['name', 'share', 'preview','direct_link']
 
 
 admin.site.register(FormTemplate, FormTemplateAdmin)

uiforms/tmanager/tests.py

 """
 
 from django.test import TestCase
-from models import FormTemplate , TemplateField ,TemplateData
+from models import FormTemplate, TemplateField, TemplateData
 from django.contrib.auth.models import User
 import forms
 from django.test.client import Client
 from views import OwnedDataView
 
 
-
 class FormTemplateTest(TestCase):
     def test_unicode(self):
-		ft = FormTemplate()
-		ft.name = "test"
-		self.assertEquals(ft.name,str(ft) )
-        
+        ft = FormTemplate()
+        ft.name = "test"
+        self.assertEquals(ft.name, str(ft))
+
 
 class TemplateFieldTest(TestCase):
-	def test_unicode(self):
-		tf = TemplateField()
-		tf.label = "test"
-		self.assertEquals(tf.label,str(tf) )
-		
+    def test_unicode(self):
+        tf = TemplateField()
+        tf.label = "test"
+        self.assertEquals(tf.label, str(tf))
+
+
 class TemplateDataTest(TestCase):
-	
-	fixtures = ['user_fixtures.json' , 'test_data_fixtures.json']
-
-	def test_last_m(self):
-		td = TemplateData()
-		ft = FormTemplate.objects.get(pk=1)
-		td.template_ref = ft
-		td.submitted_by = User.objects.get(pk=2)
-		td.save()
-		self.assertTrue(td.modified)
-		self.assertTrue(td.created)
-		
+    fixtures = ['user_fixtures.json', 'test_data_fixtures.json']
+
+    def test_last_m(self):
+        td = TemplateData()
+        ft = FormTemplate.objects.get(pk=1)
+        td.template_ref = ft
+        td.submitted_by = User.objects.get(pk=2)
+        td.save()
+        self.assertTrue(td.modified)
+        self.assertTrue(td.created)
+
+
 class FormBuilderTest(TestCase):
-	
-	fixtures = ['user_fixtures.json', 'test_data_fixtures.json']
-	
-	def test_class_creation(self):
-		ft =  FormTemplate.objects.get(pk=1)
-		UIForm = forms.build_UIForm(ft)
-		instance = UIForm()
-		self.assertTrue(instance.as_p())
-		
+    fixtures = ['user_fixtures.json', 'test_data_fixtures.json']
+
+    def test_class_creation(self):
+        ft = FormTemplate.objects.get(pk=1)
+        UIForm = forms.build_UIForm(ft)
+        instance = UIForm()
+        self.assertTrue(instance.as_p())
+
+
 class CloneTest(TestCase):
-	fixtures = ['user_fixtures.json', 'test_data_fixtures.json']
-	
-	def test_clone_obj(self):
-		pass #TODO
-		
+    fixtures = ['user_fixtures.json', 'test_data_fixtures.json']
+
+    def test_clone_obj(self):
+        pass #TODO
+
+
 class ViewTest(TestCase):
+    fixtures = ['user_fixtures.json', 'test_data_fixtures.json']
 
-	fixtures = ['user_fixtures.json', 'test_data_fixtures.json']
-	
-	def setUp(self):
-		self.client = Client()
-		self.client.login(username='admin', password='admin')
-		
-	def params(self,ft):
-		ok_params = {}
-		for f in ft.templatefield_set.all():
-			if f.filed_type == 'BOOLEAN':
-				ok_params[f.label] = 'True'
-			else:
-				ok_params[f.label] = 1
-		return ok_params
-		
-	def check_fieds_in_output(self, ft, content):
-		for f in ft.templatefield_set.all():
-			self.assertTrue(content.count(f.label) > 0 )
+    def setUp(self):
+        self.client = Client()
+        self.client.login(username='admin', password='admin')
+
+    def params(self, ft):
+        ok_params = {}
+        for f in ft.templatefield_set.all():
+            if f.filed_type == 'BOOLEAN':
+                ok_params[f.label] = 'True'
+            else:
+                ok_params[f.label] = 1
+        return ok_params
+
+    def check_fieds_in_output(self, ft, content):
+        for f in ft.templatefield_set.all():
+            self.assertTrue(content.count(f.label) > 0)
+
+
+    def test_uiform(self):
+        ft = FormTemplate.objects.get(pk=1)
+        original_data = ft.templatedata_set.count()
+        response = self.client.get(urlresolvers.reverse('uiform', args=[1]))
+        self.assertEquals(200, response.status_code)
+        self.check_fieds_in_output(ft, response.content)
+
+        ok_params = self.params(ft)
+        post_response = self.client.post(urlresolvers.reverse('uiform', args=[1]), ok_params)
+        self.assertEquals(200, post_response.status_code)
+        #check output
+        self.assertTrue(post_response.content.count('Thank you') > 0)
+        #check db
+        ft_after = FormTemplate.objects.get(pk=1)
+        self.assertTrue(ft.templatedata_set.count() > original_data)
+
+    def test_uiform_post_previw(self):
+        ft = FormTemplate.objects.get(pk=1)
+        ok_params = self.params(ft)
+        response = self.client.post(urlresolvers.reverse('preview', args=[1]), ok_params)
+        self.assertEquals(200, response.status_code)
+        self.check_fieds_in_output(ft, response.content)
+
+
+    def test_uiform_get_previw(self):
+        ft = FormTemplate.objects.get(pk=1)
+        response = self.client.get(urlresolvers.reverse('preview', args=[1]))
+        self.assertEquals(200, response.status_code)
+        #check output
+        self.check_fieds_in_output(ft, response.content)
+
+    def test_clone(self):
+        original_data = FormTemplate.objects.count()
+        response = self.client.get(urlresolvers.reverse('clone', args=[1]))
+        self.assertEquals(404, response.status_code)
+        post_response = self.client.post(urlresolvers.reverse('clone', args=[1]), {'honeypot': 'dammy'})
+        self.assertEquals(302, post_response.status_code) #check redirect
+        self.assertTrue(FormTemplate.objects.count() > original_data) #check db
+
+    def test_share(self):
+        response = self.client.get(urlresolvers.reverse('share', args=[1]))
+        self.assertEquals(200, response.status_code)
+        self.assertTrue(response.content.count("email") > 0)
+        #FAIL email validation
+        post_response = self.client.post(urlresolvers.reverse('share', args=[1]), {'email': 'dammy'})
+        self.assertEquals(200, response.status_code)
+        self.assertTrue(post_response.content.count("error") > 0)
+
+        post_response = self.client.post(urlresolvers.reverse('share', args=[1]), {'email': 'your_email@example.com'})
+        self.assertEquals(302, post_response.status_code) #check redirect
 
-		
-	def test_uiform(self):
-		ft =  FormTemplate.objects.get(pk=1)
-		original_data = ft.templatedata_set.count()
-		response = self.client.get(urlresolvers.reverse('uiform',args=[1]))
-		self.assertEquals(200,response.status_code)
-		self.check_fieds_in_output(ft,response.content)
-		
-		ok_params = self.params(ft)
-		post_response = self.client.post(urlresolvers.reverse('uiform',args=[1]),ok_params)
-		self.assertEquals(200,post_response.status_code)
-		#check output
-		self.assertTrue(post_response.content.count('Thank you') > 0 )
-		#check db
-		ft_after =  FormTemplate.objects.get(pk=1)
-		self.assertTrue( ft.templatedata_set.count() > original_data)
-		
-	def test_uiform_post_previw(self):
-		ft =  FormTemplate.objects.get(pk=1)
-		ok_params = self.params(ft)
-		response = self.client.post(urlresolvers.reverse('preview',args=[1]),ok_params)
-		self.assertEquals(200,response.status_code)
-		self.check_fieds_in_output(ft,response.content)
-		
-		
-	def test_uiform_get_previw(self):
-		ft =  FormTemplate.objects.get(pk=1)
-		response = self.client.get(urlresolvers.reverse('preview',args=[1]))
-		self.assertEquals(200,response.status_code)
-		#check output
-		self.check_fieds_in_output(ft,response.content)
-		
-	def test_clone(self):
-		original_data = FormTemplate.objects.count()
-		response = self.client.get(urlresolvers.reverse('clone',args=[1]))
-		self.assertEquals(404,response.status_code)
-		post_response = self.client.post(urlresolvers.reverse('clone',args=[1]), { 'honeypot':'dammy'})
-		self.assertEquals(302,post_response.status_code) #check redirect
-		self.assertTrue(FormTemplate.objects.count() > original_data) #check db
-		
-	def test_share(self):
-		response = self.client.get(urlresolvers.reverse('share',args=[1]))
-		self.assertEquals(200,response.status_code)
-		self.assertTrue(response.content.count("email") > 0 )
-		#FAIL email validation
-		post_response = self.client.post(urlresolvers.reverse('share',args=[1]), { 'email':'dammy'})
-		self.assertEquals(200,response.status_code)
-		self.assertTrue(post_response.content.count("error") > 0 )
 
-		
-		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 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
-		
-		
+    fixtures = ['user_fixtures.json', 'test_data_fixtures.json']
+
+    def setUp(self):
+        self.client = Client()
+        self.client.login(username='admin', password='admin')
+
+    def test_template_form_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)
+
+    def test_admin_index(self):
+        response = self.client.get(urlresolvers.reverse("admin:index"))
+        self.assertEquals(200, response.status_code)
+        self.assertTrue(response.content.count("custom-module") > 0)
+
+
 class ClassViewTest(TestCase):
-		
-	fixtures = ['user_fixtures.json', 'test_data_fixtures.json']
-		
-	def setUp(self):
-		self.client = Client()
-		self.client.login(username='admin', password='admin')
-	
-	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
+    fixtures = ['user_fixtures.json', 'test_data_fixtures.json']
+
+    def setUp(self):
+        self.client = Client()
+        self.client.login(username='admin', password='admin')
+
+    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.template.context import RequestContext
+from django.views.generic.edit import DeleteView
 from models import FormTemplate , TemplateField ,TemplateData ,TemplateDataRow ,copy_model_instance
 from django.contrib.auth.models import User
 import forms
 from django.views.generic import DetailView , ListView
 from django.utils.decorators import method_decorator
 from django.contrib.auth.decorators import login_required
+from django.core import urlresolvers
 
 
 @login_required
 				data_row.template_field = f
 				data_row.payload = form_instance.cleaned_data[f.label]
 				data_row.save()
-			return render_to_response('admin/tmanager/thanks.html',{'form':form_instance, 'template_obj':template}) 
+			return render_to_response('admin/tmanager/thanks.html',{'form':form_instance, 'template_obj':template},context_instance=RequestContext(request))
 			
 	else:
 		form_instance = UIForm()
 		
-	return render_to_response('admin/tmanager/uiform.html',{'form':form_instance, 'template_obj':template})
+	return render_to_response('admin/tmanager/uiform.html',{'form':form_instance, 'template_obj':template},context_instance=RequestContext(request))
 	
 def uiform_preview(request, template_id):
 	template = get_object_or_404(FormTemplate ,pk = template_id)
 	
 	def get_queryset(self):
 		return TemplateData.objects.filter(submitted_by__id__exact =  self.request.user.id )
+
+class DeleteDataView(DeleteView):
+
+    template_name = "admin/tmanager/confirm_delete.html"
+    model = TemplateData
+
+    def get_success_url(self,obj):
+        if obj.submitted_by == self.request.user:
+            return urlresolvers.resolve('submitted_data')
+        else:
+            return urlresolvers.resolve('owned_data')
+
+    @method_decorator(login_required)
+    def dispatch(self, *args, **kwargs):
+        return super(SubmittedDataView, self).dispatch(*args, **kwargs)