コード例 #1
0
def _create_project_post_response(request, manager):
    project_info = json.loads(request.POST['profile_form'])
    try:
        ngo_admin = NGOUserProfile.objects.get(user=request.user)
        is_open_survey_allowed = _is_open_survey_allowed(request, request.POST.get('is_open_survey'))
        questionnaire = create_questionnaire(post=request.POST, manager=manager, name=project_info.get('name'),
                                             language=project_info.get('language', request.LANGUAGE_CODE),
                                             reporter_id=ngo_admin.reporter_id,
                                             is_open_survey=is_open_survey_allowed)
    except (QuestionCodeAlreadyExistsException, QuestionAlreadyExistsException,
            EntityQuestionAlreadyExistsException) as ex:
        return {'success': False, 'error_message': _(ex.message), 'error_in_project_section': False}

    code_has_errors, error_message, name_has_errors = _validate_questionnaire_name_and_code(questionnaire)

    if not code_has_errors and not name_has_errors:
        associate_account_users_to_project(manager, questionnaire)
        questionnaire.update_doc_and_save()
        UserActivityLog().log(request, action=CREATED_QUESTIONNAIRE, project=questionnaire.name,
                              detail=questionnaire.name)
        return {'success': True, 'project_id': questionnaire.id}

    return {'success': False,
            'error_message': error_message,
            'error_in_project_section': False,
            'code_has_errors': code_has_errors,
            'name_has_errors': name_has_errors}
コード例 #2
0
def get_questionnaire_form_model(manager, project_info, post):
    return create_questionnaire(post,
                                manager,
                                entity_type=unicode(
                                    project_info['entity_type']),
                                name=unicode(project_info['name']),
                                language=unicode(project_info['language']))
コード例 #3
0
ファイル: xform_bridge.py プロジェクト: manish211/datawinners
    def create_project(self):
        project_json = {'questionnaire-code': self.questionnaire_code}

        questionnaire = create_questionnaire(
            post=project_json,
            manager=self.manager,
            name=self.name,
            language=self.language,
            reporter_id=self.reporter_id,
            question_set_json=self.json_xform_data,
            xform=self.xform_with_form_code)

        if not questionnaire.is_project_name_unique():
            return None, None

        associate_account_users_to_project(self.manager, questionnaire)
        questionnaire.update_media_field_flag()
        questionnaire.update_doc_and_save()
        if self.xls_form:
            base_name, extension = os.path.splitext(self.xls_form.name)
        else:
            extension = ".xls"
        questionnaire.add_attachments(self.xls_form,
                                      'questionnaire%s' % extension)
        UserActivityLog().log(self.request,
                              action=CREATED_QUESTIONNAIRE,
                              project=questionnaire.name,
                              detail=questionnaire.name)
        return questionnaire.id, questionnaire.form_code
コード例 #4
0
def get_questionnaire_form_model(manager, project_info, post):
    return create_questionnaire(post,
                                manager,
                                name=unicode(project_info.get('name')),
                                language=unicode(project_info.get('language')),
                                reporter_id=None)