Beispiel #1
0
 def export_to_xls(self):
     """Export data to XLS."""
     if XLWT_INSTALLED:
         return self._export_to_xls()
     else:
         raise ImproperlyConfigured(
             "For XLS export xlwt shall be installed.")
Beispiel #2
0
    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request', None)
        if self.request is None:
            raise ImproperlyConfigured(
                ugettext("The {0} form requires a "
                         "request argument.".format(self.__class__.__name__)))

        super(FormEntryForm, self).__init__(*args, **kwargs)
        theme = get_theme(request=None, as_instance=True)

        self.fields['name'].widget = forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class})

        self.fields['success_page_title'].widget = forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class})

        self.fields['success_page_message'].widget = forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class})

        self.fields['action'].widget = forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class})

        # At the moment this is done for Foundation 5 theme. Remove this once
        # it's possible for a theme to override this form. Alternatively, add
        # the attrs to the theme API.
        self.fields['is_public'].widget = forms.widgets.CheckboxInput(
            attrs={'data-customforms': 'disabled'})
Beispiel #3
0
def validate_submit_value_as(value):
    """Validates the `SUBMIT_AS_VALUE`.

    :param str value:
    """
    if value not in (SUBMIT_VALUE_AS_VAL, SUBMIT_VALUE_AS_REPR,
                     SUBMIT_VALUE_AS_MIX):
        raise ImproperlyConfigured("The `SUBMIT_AS_VALUE` may have one of "
                                   "the following values: {0}, {1} or {2}"
                                   "".format(SUBMIT_VALUE_AS_VAL,
                                             SUBMIT_VALUE_AS_REPR,
                                             SUBMIT_VALUE_AS_MIX))
Beispiel #4
0
    def integration_check(self, instance):
        """
        Perofrms a simple check to identify whether the model instance
        has been implemented according to the expectations.
        """
        expected_fields = (
            ('form_entry', 'models.ForeignKey("fobi.FormEntry)'),
            ('form_template_name', 'models.CharField'),
            ('hide_form_title', 'models.BooleanField'),
            ('form_title', 'models.CharField'),
            ('form_submit_button_text', 'models.CharField'),
            ('success_page_template_name', 'models.CharField'),
            ('hide_success_page_title', 'models.BooleanField'),
            ('success_page_title', 'models.CharField'),
            ('success_page_text', 'models.CharField'),
        )

        for field_name, field_info in expected_fields:
            if not hasattr(instance, field_name):
                raise ImproperlyConfigured(
                    "You should have a field {0} in your {1} model "
                    "({2})".format(field_name, field_info, type(instance)))
    try:
        from django.contrib.auth import get_user_model
    # Fall back to Django 1.5
    except ImportError:
        from django.contrib.auth.models import User
    else:
        User = get_user_model()

    # Sanity checks
    user = User()

    if not hasattr(user, 'username'):
        from fobi.exceptions import ImproperlyConfigured
        raise ImproperlyConfigured("Your custom user model ({0}.{1}) doesn't "
                                   "have ``username`` property, while "
                                   "``django-fobi`` relies on its' presence"
                                   ".".format(user._meta.app_label,
                                              user._meta.object_name))

# ****************************************************************************
# ****************************************************************************
# ****************************************************************************

# ****************************************************************************
# ****************************************************************************
# ******************************* Plugin models ******************************
# ****************************************************************************
# ****************************************************************************


class AbstractPluginModel(models.Model):