Beispiel #1
0
	def testSaveDataForm(self):
		request = rf.post('/form/', TEST_FORM_POST_DATA)
		form = forms.create_form(request, form="personal-information", submission="myForm")
		
		# Make sure there's no submission object yet
		# Removed, now we always expect to be a submission
		# object attached.
		#self.assertRaises(AttributeError, getattr, form, 'submission')
		
		# Validate the form to populate cleaned_data for the save function
		form.is_valid()
		if form.errors:	
			self.fail(form.errors)
		
		# Try saving the form
		form.save()
		
		# Verify the data was input correctly
		self.assertValidSave(data=TEST_FORM_POST_DATA, submission="myForm")
		
		# Test creation of another bound form tied to a existing Submission
		request = rf.get('/')
		form = forms.create_form(request, form="personal-information", submission="myForm")
		
		# Make sure template rendering doesn't throw errors
		x = template.Template("{% for field in form %}{{ field }}{% endfor %}")
		c = template.Context({"form":form})
		x.render(c)
		
		# Ensure Unicode encoding is being returned from models correctly
		answers = Answer.objects.all()
		
		for value in answers:
			try:
				value.__unicode__()
			except UnicodeEncodeError:
				self.fail("UnicodeEncodeError: 'ascii' codec can't encode character... Make sure you are using unicode() in every model's __unicode__() function, NOT str()")
		
		# Test re-submission of form with different data to make sure that edits work.
		# Tests for regression of data integrity bug where a checked checkbox
		# could never be un-checked because it would not exist in the form POST.
		request = rf.post('/form/', TEST_FORM_POST_DATA2)
		form = forms.create_form(request, form="personal-information", submission="myForm")
		
		# Validate the form to populate cleaned_data for the save function
		form.is_valid()
		if form.errors:
			self.fail(form.errors)
		
		# Try saving the form
		form.save()
		
		# Verify the data was input correctly
		self.assertValidSave(data=TEST_FORM_POST_DATA2, submission="myForm")
Beispiel #2
0
def create(request):

	if request.method == 'POST':
		form = create_form(request.POST)

		if form.is_valid():

			
			password=request.POST['password']
			username=request.POST['username']
			user_address=request.POST['email']

			#additional verification for valid email address from google
	
			if not mail.is_email_valid(user_address):
				form=create_form()
		
				return render(request,'create.htl',{'form':form})
			
	
			else:
				sender_address="Friendly-Media.com Support <*****@*****.**>"

				subject="Confirm your registration"

				body = """
Thank you for creating an account! Please confirm your email address by
clicking on the link below:

%s
""" %('https://myproject0922.appspot.com/confirmed?email='+user_address+'&username='******'thanks.html',{'user_address':user_address,'is_active':a.is_active})

	else:
		form = create_form()

	return render(request,'create.html',{'form':form})
Beispiel #3
0
def new():
    name = request.args['name']
    Component = models.components[name]
    Form = forms.create_form(Component)
    form = Form()
    if form.validate_on_submit():
        component = Component()
        form.populate_obj(component)
        component.uuid = str(uuid.uuid4())
        db.session.add(component)
        db.session.commit()
        flash("The new component was created successfully.", "success")
        return redirect(url_for('table', name=name))
    return render_template('edit.html', form=form)
Beispiel #4
0
def edit():
    name = request.args['name']
    id = int(request.args['id'])
    Component = models.components[name]
    Form = forms.create_form(Component)
    form = Form()
    component = Component.query.get(id)
    if form.validate_on_submit():
        form.populate_obj(component)
        db.session.add(component)
        db.session.commit()
        flash("The component was edited successfully.", "success")
        return redirect(url_for('table', name=name))
    form = Form(obj=component)
    return render_template('edit.html', form=form)
Beispiel #5
0
    def __init__(self, name, **kwargs):
        super(BaseCrud, self).__init__()
        self.name=name
        self.pk_type='int'
        self.navigation_hint=name+'.list'
        self.form=[]
        self.label=name.capitalize()
        self.url='/{0}/'.format(name)
        self.parent=None
        self.labels={}
        self.list_columns=[]
        self.form=Form()
        self.collection=None


        if 'pk_type' in kwargs: self.pk_type=kwargs['pk_type'] 
        if 'navigation_hint' in kwargs: self.navigation_hint=kwargs['navigation_hint'] 
        if 'label' in kwargs: self.label=kwargs['label'] 
        if 'url' in kwargs: self.url=kwargs['url'] 
        if 'labels' in kwargs: self.labels=kwargs['labels'] 
        if 'list_columns' in kwargs:
            self.list_columns=create_columns(kwargs['list_columns'])
        if 'form' in kwargs: 
            self.form=create_form(kwargs['form'],self.labels)  
Beispiel #6
0
	def testCreateBountDataForm(self):
		request = rf.post('/form/', TEST_FORM_POST_DATA)
		form = forms.create_form(request, form="personal-information", submission="myForm")
Beispiel #7
0
	def testCreateUnboundDataForm(self):
		request = rf.get('/')
		form = forms.create_form(request, form="personal-information", submission="myForm")
Beispiel #8
0
    def testSaveDataForm(self):
        request = rf.post('/form/', TEST_FORM_POST_DATA)
        form = forms.create_form(request,
                                 form="personal-information",
                                 submission="myForm")

        # Make sure there's no submission object yet
        # Removed, now we always expect to be a submission
        # object attached.
        #self.assertRaises(AttributeError, getattr, form, 'submission')

        # Validate the form to populate cleaned_data for the save function
        form.is_valid()
        if form.errors:
            self.fail(form.errors)

        # Try saving the form
        form.save()

        # Verify the data was input correctly
        self.assertValidSave(data=TEST_FORM_POST_DATA, submission="myForm")

        # Test creation of another bound form tied to a existing Submission
        request = rf.get('/')
        form = forms.create_form(request,
                                 form="personal-information",
                                 submission="myForm")

        # Make sure template rendering doesn't throw errors
        x = template.Template("{% for field in form %}{{ field }}{% endfor %}")
        c = template.Context({"form": form})
        x.render(c)

        # Ensure Unicode encoding is being returned from models correctly
        answers = Answer.objects.all()

        for value in answers:
            try:
                value.__unicode__()
            except UnicodeEncodeError:
                self.fail(
                    "UnicodeEncodeError: 'ascii' codec can't encode character... Make sure you are using unicode() in every model's __unicode__() function, NOT str()"
                )

        # Test re-submission of form with different data to make sure that edits work.
        # Tests for regression of data integrity bug where a checked checkbox
        # could never be un-checked because it would not exist in the form POST.
        request = rf.post('/form/', TEST_FORM_POST_DATA2)
        form = forms.create_form(request,
                                 form="personal-information",
                                 submission="myForm")

        # Validate the form to populate cleaned_data for the save function
        form.is_valid()
        if form.errors:
            self.fail(form.errors)

        # Try saving the form
        form.save()

        # Verify the data was input correctly
        self.assertValidSave(data=TEST_FORM_POST_DATA2, submission="myForm")
Beispiel #9
0
 def testCreateBountDataForm(self):
     request = rf.post('/form/', TEST_FORM_POST_DATA)
     form = forms.create_form(request,
                              form="personal-information",
                              submission="myForm")
Beispiel #10
0
 def testCreateUnboundDataForm(self):
     request = rf.get('/')
     form = forms.create_form(request,
                              form="personal-information",
                              submission="myForm")