示例#1
0
 def post(self, request, *args, **kwargs):
     form = AddProjectForm(request.POST)
     # Let add crawl model work normally if it is not dealing with an xmlhttprequest.
     if request.is_ajax():
         if form.is_valid():
             self.object = form.save()
             return HttpResponse(
                 json.dumps({
                     "url": self.object.get_absolute_url(),
                     "id": self.object.id,
                     "name": self.object.name,
                     "slug": self.object.slug,
                     "description": self.object.description,
                 }),
                 status=200,
                 content_type="application/json"
             )
         else:
             return HttpResponse(
                 json.dumps({
                     "form_errors": form.errors,
                 }),
                 status=500,
                 content_type="application/json",
             )
     else:
         return super(AddProjectView, self).post(request, *args, **kwargs)
示例#2
0
 def post(self, request, *args, **kwargs):
     form = AddProjectForm(request.POST)
     # Let add crawl model work normally if it is not dealing with an xmlhttprequest.
     if request.is_ajax():
         if form.is_valid():
             self.object = form.save()
             return HttpResponse(json.dumps({
                 "url":
                 self.object.get_absolute_url(),
                 "id":
                 self.object.id,
                 "name":
                 self.object.name,
                 "slug":
                 self.object.slug,
                 "description":
                 self.object.description,
             }),
                                 status=200,
                                 content_type="application/json")
         else:
             return HttpResponse(
                 json.dumps({
                     "form_errors": form.errors,
                 }),
                 status=500,
                 content_type="application/json",
             )
     else:
         return super(AddProjectView, self).post(request, *args, **kwargs)
示例#3
0
 def test_existing_project_error(self):
     form_data = {
         'name': 'Bicycles for sale',
         'description': 'cats cats cats'}
     form = AddProjectForm(data=form_data)
     assert form.is_valid() is False
     assert 'Project with this Name already exists.' in form.errors['name']
示例#4
0
 def test_existing_project_error(self):
     form_data = {
         'name': 'Bicycles for sale',
         'description': 'cats cats cats'}
     form = AddProjectForm(data=form_data)
     assert form.is_valid() is False
     assert 'Project with this Name already exists.' in form.errors['name']
示例#5
0
 def test_project_form_no_name(self):
     form_data = {'description': 'cats cats cats'}
     form = AddProjectForm(data=form_data)
     assert form.is_valid() is False
     assert 'This field is required.' in form.errors['name']
示例#6
0
 def test_project_form(self):
     form_data = {'name': 'CATS', 'description': 'cats cats cats'}
     form = AddProjectForm(data=form_data)
     assert form.is_valid()
示例#7
0
 def test_project_form_no_name(self):
     form_data = {
         'description': 'cats cats cats'}
     form = AddProjectForm(data=form_data)
     assert form.is_valid() is False
     assert 'This field is required.' in form.errors['name']
示例#8
0
 def test_project_form(self):
     form_data = {
         'name': 'CATS',
         'description': 'cats cats cats'}
     form = AddProjectForm(data=form_data)
     assert form.is_valid()