Пример #1
0
    def wrapper(*args, **kwargs):
        if hasattr(settings, 'DFORM_PERMISSION_HOOK'):
            fn = dynamic_load(settings.DFORM_PERMISSION_HOOK)
            fn(target.__name__, *args, **kwargs)

        # everything verified, run the view
        return target(*args, **kwargs)
Пример #2
0
    def wrapper(*args, **kwargs):
        if hasattr(settings, 'DFORM_PERMISSION_HOOK'):
            fn = dynamic_load(settings.DFORM_PERMISSION_HOOK)
            fn(target.__name__, *args, **kwargs)

        # everything verified, run the view
        return target(*args, **kwargs)
Пример #3
0
    def setup_databases(self, **kwargs):
        result = super(WRunner, self).setup_databases(**kwargs)

        if self.test_data:
            data_fn = dynamic_load(self.test_data)
            data_fn()

        return result
Пример #4
0
def _survey_with_answers_view(request, survey_version_id, survey_token,
                              answer_group_id, answer_token, is_embedded):
    """General view code for editing answer for a survey.  Called by
    survey_with_answers() and embedded_survey_with_answers()
    """
    version = get_object_or_404(SurveyVersion,
                                id=survey_version_id,
                                survey__token=survey_token)
    answer_group = get_object_or_404(AnswerGroup,
                                     id=answer_group_id,
                                     token=answer_token)

    if request.method == 'POST':
        form = SurveyForm(request.POST,
                          survey_version=version,
                          answer_group=answer_group)
        if form.is_valid():
            form.save()

            name = getattr(settings, 'DFORM_EDIT_HOOK', '')
            if name:
                fn = dynamic_load(name)
                fn(form)

            return HttpResponseRedirect(version.on_success())
    else:
        form = SurveyForm(survey_version=version, answer_group=answer_group)

    try:
        # check for alternate survey edit handler
        template = Template(settings.DFORM_SURVEY_WITH_ANSWERS_SUBMIT)
        context = Context({
            'survey_version': version,
            'answer_group': answer_group
        })
        submit_action = template.render(context)
    except AttributeError:
        # use default survey edit handler
        name = 'dform-survey-with-answers' if is_embedded else \
            'dform-embedded-survey-with-answers'

        submit_action = reverse(name,
                                args=(version.id, version.survey.token,
                                      answer_group.id, answer_group.token))

    data = {
        'title': version.survey.name,
        'survey_version': version,
        'answer_group': answer_group,
        'form': form,
        'is_embedded': is_embedded,
        'submit_action': submit_action,
    }

    return render(request, 'dform/survey.html', data)
Пример #5
0
def _survey_with_answers_view(request, survey_version_id, survey_token, 
        answer_group_id, answer_token, is_embedded):
    """General view code for editing answer for a survey.  Called by
    survey_with_answers() and embedded_survey_with_answers()
    """
    version = get_object_or_404(SurveyVersion, id=survey_version_id, 
        survey__token=survey_token)
    answer_group = get_object_or_404(AnswerGroup, id=answer_group_id,
        token=answer_token)

    if request.method == 'POST':
        form = SurveyForm(request.POST, survey_version=version,
            answer_group=answer_group)
        if form.is_valid():
            form.save()

            name = getattr(settings, 'DFORM_EDIT_HOOK', '')
            if name:
                fn = dynamic_load(name)
                fn(form)

            return HttpResponseRedirect(version.on_success())
    else:
        form = SurveyForm(survey_version=version, answer_group=answer_group)

    try:
        # check for alternate survey edit handler
        template = Template(settings.DFORM_SURVEY_WITH_ANSWERS_SUBMIT)
        context = Context({
            'survey_version':version, 
            'answer_group':answer_group
        })
        submit_action = template.render(context)
    except AttributeError:
        # use default survey edit handler
        name = 'dform-survey-with-answers' if is_embedded else \
            'dform-embedded-survey-with-answers' 

        submit_action = reverse(name, args=(version.id, version.survey.token, 
            answer_group.id, answer_group.token))

    data = {
        'title':version.survey.name,
        'survey_version':version,
        'answer_group':answer_group,
        'form':form,
        'is_embedded':is_embedded,
        'submit_action':submit_action,
    }

    return render(request, 'dform/survey.html', data)
Пример #6
0
    def deploy(self):
        result = self.compiled_string()

        with open(self.full_filename, 'w') as f:
            f.write(result)

        if getattr(settings, 'BSEDITOR_COLLECT_ON_DEPLOY', False):
            # handle static collection on deployment
            hook = getattr(settings, 'BSEDITOR_COLLECT_HOOK', '')
            if hook:
                # use the defined collection hook instead of collectstatic
                fn = dynamic_load(hook)
                fn(self)
            else:
                # use default collectstatic during deploy
                call_command('collectstatic', '--noinput')
Пример #7
0
    def deploy(self):
        result = self.compiled_string()

        with open(self.full_filename, 'w') as f:
            f.write(result)

        if getattr(settings, 'BSEDITOR_COLLECT_ON_DEPLOY', False):
            # handle static collection on deployment
            hook = getattr(settings, 'BSEDITOR_COLLECT_HOOK', '')
            if hook:
                # use the defined collection hook instead of collectstatic
                fn = dynamic_load(hook)
                fn(self)
            else:
                # use default collectstatic during deploy
                call_command('collectstatic', '--noinput')
Пример #8
0
def _survey_view(request, survey_version_id, token, is_embedded):
    """General view code for handling a survey, called by survey() or
    embedded_survey()
    """
    version = get_object_or_404(SurveyVersion,
                                id=survey_version_id,
                                survey__token=token)

    if request.method == 'POST':
        form = SurveyForm(request.POST,
                          survey_version=version,
                          ip_address=request.META['REMOTE_ADDR'])
        if form.is_valid():
            form.save()

            name = getattr(settings, 'DFORM_SUBMIT_HOOK', '')
            if name:
                fn = dynamic_load(name)
                fn(form)

            return HttpResponseRedirect(version.on_success())
    else:
        form = SurveyForm(survey_version=version)

    try:
        # check if we have an alternate submit mechanism defined
        template = Template(settings.DFORM_SURVEY_SUBMIT)
        context = Context({'survey_version': version})
        submit_action = template.render(context)
    except AttributeError:
        # use our default submit url
        name = 'dform-embedded-survey' if is_embedded else 'dform-survey'
        submit_action = reverse(name, args=(version.id, version.survey.token))

    data = {
        'title': version.survey.name,
        'survey_version': version,
        'form': form,
        'is_embedded': is_embedded,
        'submit_action': submit_action,
    }

    return render(request, 'dform/survey.html', data)
Пример #9
0
def _survey_view(request, survey_version_id, token, is_embedded):
    """General view code for handling a survey, called by survey() or
    embedded_survey()
    """
    version = get_object_or_404(SurveyVersion, id=survey_version_id,
        survey__token=token)

    if request.method == 'POST':
        form = SurveyForm(request.POST, survey_version=version, 
            ip_address=request.META['REMOTE_ADDR'])
        if form.is_valid():
            form.save()

            name = getattr(settings, 'DFORM_SUBMIT_HOOK', '')
            if name:
                fn = dynamic_load(name)
                fn(form)

            return HttpResponseRedirect(version.on_success())
    else:
        form = SurveyForm(survey_version=version)

    try:
        # check if we have an alternate submit mechanism defined
        template = Template(settings.DFORM_SURVEY_SUBMIT)
        context = Context({'survey_version':version})
        submit_action = template.render(context)
    except AttributeError:
        # use our default submit url
        name = 'dform-embedded-survey' if is_embedded else 'dform-survey'
        submit_action = reverse(name, args=(version.id, version.survey.token))

    data = {
        'title':version.survey.name,
        'survey_version':version,
        'form':form,
        'is_embedded':is_embedded,
        'submit_action':submit_action,
    }

    return render(request, 'dform/survey.html', data)
Пример #10
0
 def test_dynamic_load(self):
     import os
     fn = dynamic_load('os.path.abspath')
     self.assertEqual(os.path.abspath, fn)
Пример #11
0
    def test_dynamic_load(self):
        import os

        fn = dynamic_load("os.path.abspath")
        self.assertEqual(os.path.abspath, fn)