예제 #1
0
def survey_add(request):
    if request.method == 'POST':
        form = SurveyForm(request.POST)
        has_errors = False
        try:
            newSurvey = Survey()

            name = request.POST.get('name')
            newSurvey.name = name
            
            title = request.POST.get('title')
            newSurvey.title = title
            
            datastore = request.POST.get('datastore')
            newSurvey.datastore_id = datastore
            
            exists = False
            projects = Project.objects.all()
            for p in projects:
                if name == p.name:
                    exists = True
            
            if name == '':
                message = _(u'You must enter an survey name')
                return render(request, 'survey_add.html', {'message': message, 'form': form})
            
            if _valid_name_regex.search(name) == None:
                message = _(u"Invalid survey name: '{value}'. Identifiers must begin with a letter or an underscore (_). Subsequent characters can be letters, underscores or numbers").format(value=name)
                return render(request, 'survey_add.html', {'message': message, 'form': form})
              
            if not exists:     
                newSurvey.save()
                return redirect('survey_update', survey_id=newSurvey.id)
            else:
                message = _(u'Exists a project with the same name')
                return render(request, 'survey_add.html', {'message': message, 'form': form})
        
       
            #msg = _("Error: fill all the survey fields")
            #form.add_error(None, msg)
            
        except Exception as e:
            try:
                msg = e.get_message()
            except:
                msg = _("Error: survey could not be published")
            form.add_error(None, msg)

    else:
        form = SurveyForm()
        
    return render(request, 'survey_add.html', {'form': form})
예제 #2
0
파일: views.py 프로젝트: ryanyue123/Django
def survey_create(request):
    newSurvey=Survey()
    newSurvey.title=request.POST['survey_title']
    newSurvey.save()
    request.session['current_survey']=newSurvey.id
    return redirect('admin-question-add-view')
예제 #3
0
def survey_create(request):
    newSurvey = Survey()
    newSurvey.title = request.POST['survey_title']
    newSurvey.save()
    request.session['current_survey'] = newSurvey.id
    return redirect('admin-question-add-view')