コード例 #1
0
ファイル: views.py プロジェクト: Acour83/django-editable
def admin_edit(request, location_name, template_name="admin-edit.html"):
	if not request.user.is_authenticated():
		return HttpResponseRedirect('/login/')
	
	try:
		placeholder = Placeholder.objects.get(location=location_name)
	except Placeholder.DoesNotExist:
		raise Http404
		
	if request.POST:
		placeholder_data = request.POST.copy()
		placeholder_form = EditForm(data=placeholder_data, instance=placeholder)
		
		if placeholder_form.is_valid():
			placeholder_form.save()
			return HttpResponseRedirect('/')
	
	else:
		placeholder_form = EditForm(instance=placeholder)
	
	return render_to_response(template_name, locals(), context_instance=RequestContext(request))
	
	
コード例 #2
0
ファイル: tests.py プロジェクト: Acour83/django-editable
class TestAdminEdit(unittest.TestCase):
	"""Don't know if this is going to be of any help, but setUp() creates a Placeholder model and test_models() checks to see if it was, in fact, created. test_form() proves that you don't need the location field for an EditForm. You will need it however in the Django Admin site (But thats a different story). tearDown() then deletes the model in case you'd like to run the test over and over again.
Make sense??"""

	def setUp(self):
		location="test_block"
		content="<p>Do I exist?</p>"
		self.model = Placeholder.objects.create(location=location, content=content)
    	
	def test_models(self):
		self.assertEqual(self.model.location, "test_block")
		self.assertEqual(self.model.content, "<p>Do I exist?</p>")
    	
	def test_form(self):
		data = {'content':'<p>This is content.</p>'}
		self.form = EditForm(data)

		self.assertEqual(self.form.is_bound, True)
		self.assertEqual(self.form.is_valid(), True)
    
	def tearDown(self):
		self.model.delete()
コード例 #3
0
ファイル: tests.py プロジェクト: Acour83/django-editable
	def test_form(self):
		data = {'content':'<p>This is content.</p>'}
		self.form = EditForm(data)

		self.assertEqual(self.form.is_bound, True)
		self.assertEqual(self.form.is_valid(), True)