Example #1
0
        :return iterable:
        """
        widget = get_form_handler_plugin_widget(
            self.uid, request=request, as_instance=True
            )

        if widget:
            view_entries_icon_class = widget.view_entries_icon_class
            export_entries_icon_class = widget.export_entries_icon_class
        else:
            view_entries_icon_class = 'glyphicon glyphicon-list'
            export_entries_icon_class = 'glyphicon glyphicon-export'

        return (
            (
                reverse('fobi.contrib.plugins.form_handlers.db_store.view_saved_form_data_entries',
                        args=[form_entry.pk]),
                _("View entries"),
                view_entries_icon_class
            ),
            (
                reverse('fobi.contrib.plugins.form_handlers.db_store.export_saved_form_data_entries',
                        args=[form_entry.pk]),
                _("Export entries"),
                export_entries_icon_class
            ),
        )


form_handler_plugin_registry.register(DBStoreHandlerPlugin)
                #file_path = settings.PROJECT_DIR('../{0}'.format(file_path))
                file_path = file_path.replace(
                    settings.MEDIA_URL,
                    os.path.join(settings.MEDIA_ROOT, '')
                    )
                files[field_name] = (imf.name, open(file_path, 'rb'))

        for field_name, imf in request.FILES.items():
            try:
                file_path = form.cleaned_data.get(field_name, '')
                process_path(file_path, imf)
            except Exception as e:
                file_path = extract_file_path(imf.name)
                process_path(file_path, imf)

        return files

    def plugin_data_repr(self):
        """
        Human readable representation of plugin data.

        :return string:
        """
        context = {
            'endpoint_url': self.data.endpoint_url,
        }
        return render_to_string('http_repost/plugin_data_repr.html', context)


form_handler_plugin_registry.register(HTTPRepostHandlerPlugin)
Example #3
0
    def custom_actions(self, form_entry, request=None):
        """
        Adding a link to view the saved form enties.

        :return iterable:
        """
        widget = get_form_handler_plugin_widget(self.uid,
                                                request=request,
                                                as_instance=True)

        if widget:
            view_entries_icon_class = widget.view_entries_icon_class
            export_entries_icon_class = widget.export_entries_icon_class
        else:
            view_entries_icon_class = 'glyphicon glyphicon-list'
            export_entries_icon_class = 'glyphicon glyphicon-export'

        return (
            (reverse(
                'fobi.contrib.plugins.form_handlers.db_store.view_saved_form_data_entries',
                args=[form_entry.pk]), _("View entries"),
             view_entries_icon_class),
            (reverse(
                'fobi.contrib.plugins.form_handlers.db_store.export_saved_form_data_entries',
                args=[form_entry.pk]), _("Export entries"),
             export_entries_icon_class),
        )


form_handler_plugin_registry.register(DBStoreHandlerPlugin)
Example #4
0
import json

from django.core.mail import send_mail

from fobi.base import FormHandlerPlugin, form_handler_plugin_registry

from sample_mail.forms import SampleMailForm


class SampleMailHandlerPlugin(FormHandlerPlugin):
    uid = "sample_mail"
    name = _("Sample mail")
    form = SampleMailForm

    def run(self, form_entry, request, form):
        send_mail(self.data.subject,
                  json.dumps(form.cleaned_data),
                  self.data.from_email, [self.data.to_email],
                  fail_silently=True)

    def plugin_data_repr(self):
        """
        Human readable representation of plugin data.

        :return string:
        """
        return self.data.__dict__


form_handler_plugin_registry.register(SampleMailHandlerPlugin)
Example #5
0
                process_path(file_path, imf)

        return files

    def plugin_data_repr(self):
        """Human readable representation of plugin data.

        :return string:
        """
        context = {
            'endpoint_url': self.data.endpoint_url,
        }
        return render_to_string('http_repost/plugin_data_repr.html', context)


form_handler_plugin_registry.register(HTTPRepostHandlerPlugin)

# *****************************************************************************
# ************************ Form wizard handler ********************************
# *****************************************************************************


class HTTPRepostWizardHandlerPlugin(FormWizardHandlerPlugin):
    """HTTP repost wizard handler plugin.

    Makes a HTTP repost to a given endpoint. Should be executed before
    ``db_store`` plugin.
    """

    uid = UID
    name = _("HTTP Repost")
                file_path = extract_file_path(imf.name)
                process_path(file_path, imf)

        return files

    def plugin_data_repr(self):
        """
        Human readable representation of plugin data.

        :return string:
        """
        to_email = None
        # Handling more than one email address
        if isinstance(self.data.to_email, (list, tuple)):
            to_email = '{0} '.format(MULTI_EMAIL_FIELD_VALUE_SPLITTER).join(
                            self.data.to_email
                            )
        else:
            # Assume that it's string
            to_email = self.data.to_email

        context = {
            'to_name': safe_text(self.data.to_name),
            'to_email': to_email,
            'subject': safe_text(self.data.subject),
        }
        return render_to_string('mail/plugin_data_repr.html', context)


form_handler_plugin_registry.register(MailHandlerPlugin)
    def get_element_data(self, form_element):
        element_info = self.get_element_info(form_element)
        saved_data = element_info['saved_data']

        return saved_data

    def get_saved_data(self, plugin_uid, default_value=''):
        try:
            form_element = FormElementEntry.objects.get(
                form_entry_id=self.form_id, plugin_uid=plugin_uid)
        except FormElementEntry.DoesNotExist:
            saved_data = default_value
        else:
            saved_data = self.get_element_data(form_element)
            if (plugin_uid in ['time_start', 'time_stop']) and saved_data:
                saved_data = datetime.combine(
                    self.today, saved_data).replace(tzinfo=self.timezone)

        return saved_data


def plugin_data_repr(self):
    """Human readable representation of plugin data.

    :return string:
    """
    return self.data.__dict__


form_handler_plugin_registry.register(CollectDataPlugin)