Beispiel #1
0
class RegistrationForm(Form):
    name = CharField(label='Your name',
                     required=True,
                     widget=TextInput(attrs={'class': 'input'}))
    username = CharField(
        label='Your username',
        required=True,
        widget=TextInput(attrs={'class': 'input'}),
        help_text="""Your PodMin username if you have one, or your desired
                     username if you are not already registered.""")
    email = EmailField(label='Your email address',
                       required=True,
                       widget=TextInput(attrs={'class': 'input'}))
    podcast_name = CharField(label='The name of your podcast',
                             required=True,
                             widget=TextInput(attrs={'class': 'input'}))
    description = CharField(
        label='A short description of your podcast',
        required=True,
        widget=MarkdownWidget(attrs={
            'class': 'input textarea',
            'type': 'text',
            'rows': 6
        }))
    notes = CharField(label='Is there anything else we should know?',
                      required=False,
                      widget=MarkdownWidget(attrs={
                          'class': 'input textarea',
                          'type': 'text',
                          'rows': 6
                      }))
    def get_form(self, form_class=None):
        if form_class is None:
            form_class = self.get_form_class()
        form = super().get_form(form_class)
        form.fields['description'] = CharField(widget=MarkdownWidget())

        limited_choices = [["", '---------']]
        form.fields['description'] = CharField(widget=MarkdownWidget())
        user_orgs = OrganizationPerson.objects.filter(
            user=self.request.user, role__gte=OrganizationPerson.ADMIN)
        for result in user_orgs:
            organization = result.organization
            limited_choices.append([organization.pk, organization.name])
        form.fields['organization'].choices = limited_choices

        return form
Beispiel #3
0
 class Meta:
     model = UserProfile
     fields = ('url', 'gender', 'birthdate', 'hometown', 'home_state', 'home_country',
             'current_town', 'current_state', 'current_country',
             'bio',)
     widgets = {
         'bio': MarkdownWidget()
     }
Beispiel #4
0
 def __init__(self, *args, **kwargs):
     super(HOP, self).__init__(*args, **kwargs)
     self.fields['parent'].widget = HiddenInput()
     self.fields['description'].widget = MarkdownWidget()
     for field_name in self.fields:
         if isinstance(self.fields[field_name], DateTimeField):
             self.fields[field_name].widget = DateTimeWidget(
                 usel10n=True)
Beispiel #5
0
class PostForm(forms.ModelForm):
    """Docstring for PostForm.Creating AddPost Form so end-user can add
        posts utilizing Django's built in form handling features.
    """
    content = forms.CharField(widget=MarkdownWidget())

    class Meta:
        """Docstring for Meta. """
        model = Post
        fields = ['title', 'body', 'tag', 'image']
Beispiel #6
0
 class Meta:
     model = Observation
     fields = ('content_type', 'object_id', 'date', 'lat', 'lng', 'equipment', 'seeing', 'light_pollution', 'description', 'image', 'featured')
     widgets = {
         'content_type': HiddenInput(),
         'object_id': HiddenInput(),
         'description': MarkdownWidget(),
     }
     labels = {
         'description': 'Describe your observation. Markdown is used for formatting. Click the green "check" for a preview.'
     }
Beispiel #7
0
 class Meta:
     model = Post
     fields = (
         'title',
         'summary',
         'image',
         'caption',
         'drunk',
     )
     content = forms.CharField(widget=MarkdownWidget())
     content2 = MarkdownFormField()
Beispiel #8
0
class ArticleAdminModelForm(ModelForm):
    body = CharField(widget=MarkdownWidget())
    headline = CharField(label=u'Título',
                         widget=TextInput(attrs={'style': 'width:600px'}))
    slug = CharField(
        label='Slug',
        widget=TextInput(attrs={
            'style': 'width:600px',
            'readonly': 'readonly'
        }),
        help_text=u'Se genera automáticamente en base al título.',
    )
    tags = TagField(widget=TagAutocompleteTagIt(max_tags=False),
                    required=False)

    def clean_tags(self):
        """
        This is a hack to bypass the bug that: 1 tag with spaces is considered as many tags by the lib.
        This doesn't ocurr with 2 tags or more.
        With double quotes, the tag with spaces is correctly interpreted.
        """
        tags = self.cleaned_data.get('tags')
        if tags and ',' not in tags:
            # there is just 1 tag
            tags = tags.strip('"')
            tags = '"' + tags + '"'
        return tags

    def clean(self):
        cleaned_data = super(ArticleAdminModelForm, self).clean()
        date_value = (self.cleaned_data.get('date_published')
                      if self.cleaned_data.get('is_published') else
                      self.cleaned_data.get('date_created')) or date.today()
        targets = Article.objects.filter(
            Q(is_published=True) & Q(date_published__year=date_value.year)
            & Q(date_published__month=date_value.month)
            | Q(is_published=False) & Q(date_created__year=date_value.year)
            & Q(date_created__month=date_value.month),
            slug=slugify(
                cleanhtml(ldmarkup(smart_quotes(
                    cleaned_data.get('headline'))))),
        )
        if self.instance.id:
            targets = targets.exclude(id=self.instance.id)
        if targets:
            raise ValidationError(
                u'Ya existe un artículo en ese mes con el mismo título.')

    class Meta:
        model = Article
        fields = "__all__"
Beispiel #9
0
class ArticleAdminModelForm(ModelForm):
    body = CharField(widget=MarkdownWidget())
    headline = CharField(label='Título', widget=TextInput(attrs={'style': 'width:600px'}))
    tags = TagField(widget=TagAutocompleteTagIt(max_tags=False), required=False)

    def clean_tags(self):
        """
        This is a hack to bypass the bug that: 1 tag with spaces is considered as many tags by the lib.
        This doesn't ocurr with 2 tags or more.
        With double quotes, the tag with spaces is correctly interpreted.
        """
        tags = self.cleaned_data.get('tags')
        if tags and ',' not in tags:
            # there is just 1 tag
            tags = tags.strip('"')
            tags = '"' + tags + '"'
        return tags

    class Meta:
        model = Article
Beispiel #10
0
class Discussion(forms.Form):
    message = forms.CharField(widget=MarkdownWidget())
Beispiel #11
0
class ArticleForm(forms.Form):
    content = forms.CharField(widget=MarkdownWidget())
Beispiel #12
0
class EpisodeForm(BetterModelForm):
    title = CharField(
        label='Title',
        widget=TextInput(attrs={
            'class': 'input',
            'type': 'text',
            'placeholder': 'Episode Title'
        }))

    subtitle = CharField(
        label='Subtitle',
        required=False,
        widget=TextInput(attrs={
            'class': 'input',
            'type': 'text',
            'placeholder': 'Episode Subtitle'
        }))

    number = CharField(label='Episode Number',
                       required=False,
                       widget=TextInput(attrs={
                           'class': 'input',
                           'type': 'text'
                       }))

    guid = CharField(label='GUID',
                     widget=TextInput(attrs={
                         'class': 'input',
                         'type': 'text'
                     }))

    description = CharField(
        label='Episode Description',
        required=False,
        widget=MarkdownWidget(attrs={
            'class': 'input textarea',
            'type': 'text',
            'rows': 6
        }))

    buffer_image = FileField(label='Episode Image',
                             required=False,
                             widget=FileInput(attrs={
                                 'class': 'input',
                                 'type': 'file'
                             }))

    pub_date = DateTimeField(label='Publication Date',
                             initial=datetime.datetime.today,
                             widget=TextInput(attrs={
                                 'class': 'input datetimepicker',
                                 'type': 'text'
                             }))
    tags = CharField(label='Tags',
                     required=False,
                     widget=TextInput(attrs={
                         'class': 'input',
                         'type': 'text'
                     }))

    active = ChoiceField(label='Ready to Publish?',
                         widget=Select(attrs={'class': 'input inline'}),
                         choices=BOOLEAN_CHOICES,
                         initial=BOOLEAN_CHOICES[0][0],
                         help_text='Is the episode ready to go live?')

    buffer_audio = FileField(label='Episode Audio',
                             required=False,
                             widget=FileInput(attrs={
                                 'class': 'input',
                                 'type': 'file'
                             }))

    show_notes = CharField(
        label='Show Notes',
        required=False,
        widget=MarkdownWidget(attrs={
            'class': 'input textarea',
            'type': 'text',
            'rows': 8
        }),
        help_text='Notes about this episode')

    credits = CharField(label='Credits',
                        required=False,
                        widget=MarkdownWidget(attrs={
                            'class': 'input textarea',
                            'type': 'text',
                            'rows': 6
                        }),
                        help_text='Art and Music Credits')

    guests = CharField(label='Guests',
                       required=False,
                       widget=MarkdownWidget(attrs={
                           'class': 'input textarea',
                           'type': 'text',
                           'rows': 6
                       }),
                       help_text='Guests appearing in this episode')

    class Meta:
        model = Episode
        fields = [
            'title', 'subtitle', 'number', 'guid', 'description',
            'buffer_image', 'pub_date', 'tags', 'active', 'buffer_audio',
            'show_notes', 'credits', 'guests'
        ]

        exclude = ('podcast', 'size', 'length', 'part', 'mime_type')
Beispiel #13
0
class PodcastForm(BetterModelForm):
    """
    Start with the common fields
    """
    title = CharField(
        label='Title',
        widget=TextInput(attrs={
            'class': 'input',
            'type': 'text',
            'placeholder': 'Podcast Title'
        }))

    slug = CharField(label='Slug',
                     widget=TextInput(attrs={
                         'class': 'input slug',
                         'type': 'text'
                     }),
                     help_text='Only letters, numbers, and -')

    subtitle = CharField(
        label='Subtitle',
        required=False,
        widget=TextInput(attrs={
            'class': 'input',
            'type': 'text',
            'placeholder': 'Podcast Subtitle'
        }))

    description = CharField(
        label='Description',
        required=False,
        widget=MarkdownWidget(attrs={
            'class': 'input textarea',
            'type': 'text',
            'rows': 6
        }))

    language = ChoiceField(label='Language',
                           widget=Select(attrs={'class': 'input inline'}),
                           choices=LANGUAGE_CHOICES)

    explicit = ChoiceField(label='Contains Explicit Material',
                           widget=Select(attrs={'class': 'input inline'}),
                           choices=EXPLICIT_CHOICES,
                           initial=EXPLICIT_CHOICES[1][0])

    tags = CharField(label='Tags',
                     required=False,
                     widget=TextInput(
                         attrs={
                             'class': 'input',
                             'type': 'text',
                             'placeholder': 'Comma-separated list of tags.'
                         }))

    itunes_categories = ModelMultipleChoiceField(
        queryset=Category.objects.annotate(num_cats=Count('category')).filter(
            num_cats__lt=1).order_by('parent'),
        label='iTunes Categories',
        required=False,
        widget=SelectMultiple(attrs={
            'class': 'input taller',
            'size': 10
        }))

    author = CharField(label='Author Name',
                       widget=TextInput(attrs={
                           'class': 'input',
                           'type': 'text'
                       }))

    contact = CharField(label='Author Email',
                        widget=EmailInput(attrs={
                            'class': 'input',
                            'type': 'email'
                        }))

    image = FileField(label='Podcast Image',
                      required=False,
                      widget=FileInput(attrs={
                          'class': 'input',
                          'type': 'file'
                      }),
                      help_text='Minimum 1400x1400 RGB PNG or JPEG')

    website = CharField(label='Podcast Website',
                        required=False,
                        widget=TextInput(attrs={
                            'class': 'input',
                            'type': 'url'
                        }),
                        help_text="URL to this podcast's home page")

    credits = CharField(label='Art and Music Credits',
                        required=False,
                        widget=MarkdownWidget(attrs={
                            'class': 'input textarea',
                            'type': 'text',
                            'rows': 6
                        }),
                        help_text='One contributer per line.')

    frequency = ChoiceField(label='Publishing Frequency',
                            widget=Select(attrs={'class': 'input'}),
                            choices=FREQUENCY_CHOICES)

    license = ChoiceField(label='License',
                          widget=Select(attrs={'class': 'input'}),
                          choices=LICENSE_CHOICES)

    feed_format = ChoiceField(label='Feed Type',
                              widget=Select(attrs={'class': 'input'}),
                              choices=FEED_TYPE_CHOICES,
                              initial=FEED_TYPE_CHOICES[1][0],
                              help_text='Type of feed to publish.')

    organization = CharField(label='Organization',
                             required=False,
                             widget=TextInput(attrs={
                                 'class': 'input',
                                 'type': 'text'
                             }))

    station = CharField(label='Radio Station',
                        required=False,
                        widget=TextInput(attrs={
                            'class': 'input',
                            'type': 'text'
                        }))

    copyright = CharField(label='Copyright',
                          required=False,
                          widget=TextInput(attrs={'class': 'input'}))

    ttl = IntegerField(label='Minutes this feed can be cached',
                       initial=1440,
                       widget=TextInput(attrs={'class': 'input'}))

    max_age = IntegerField(
        label='Days to keep an episode (set to 0 to keep forever)',
        initial=0,
        widget=TextInput(attrs={'class': 'input'}))

    editor_name = CharField(label='Editor Name',
                            required=False,
                            widget=TextInput(attrs={'class': 'input'}))

    editor_email = CharField(label='Editor Email',
                             required=False,
                             widget=TextInput(attrs={'class': 'input'}))

    webmaster_name = CharField(label='Webmaster name',
                               required=False,
                               widget=TextInput(attrs={'class': 'input'}))

    webmaster_email = CharField(label='Webmaster Email',
                                required=False,
                                widget=TextInput(attrs={'class': 'input'}))

    block = ChoiceField(label='Block',
                        widget=Select(attrs={'class': 'input inline'}),
                        choices=BOOLEAN_CHOICES,
                        initial=BOOLEAN_CHOICES[0][0],
                        help_text='Disable this podcast in iTunes.')

    rename_files = ChoiceField(
        label='Rename Files',
        widget=Select(attrs={'class': 'input inline'}),
        choices=BOOLEAN_CHOICES,
        initial=BOOLEAN_CHOICES[0][0],
        help_text='Rename audio files with slug and date.')

    tag_audio = ChoiceField(
        label='Tag Audio',
        widget=Select(attrs={'class': 'input inline'}),
        choices=BOOLEAN_CHOICES,
        initial=BOOLEAN_CHOICES[1][0],
        help_text='Tag audio file with podcast/episode details.')

    pub_url = CharField(label='Publication (rss) URL',
                        required=False,
                        widget=TextInput(attrs={'class': 'input'}))

    storage_url = CharField(label='File Storage URL',
                            required=False,
                            widget=TextInput(attrs={'class': 'input'}))

    itunes_url = CharField(label='iTunes URL',
                           required=False,
                           widget=TextInput(attrs={'class': 'input'}))

    feedburner_url = CharField(label='FeedBurner URL',
                               required=False,
                               widget=TextInput(attrs={'class': 'input'}))

    tmp_dir = CharField(label='Temporary Directory',
                        initial='/tmp',
                        widget=TextInput(attrs={'class': 'input'}))

    up_dir = CharField(label='Upload Directory',
                       required=False,
                       widget=TextInput(attrs={'class': 'input'}))

    cleaner = CharField(label='Cleaner',
                        required=False,
                        widget=TextInput(attrs={'class': 'input'}))

    combine_segments = ChoiceField(
        label='Combine Segments',
        widget=Select(attrs={'class': 'input inline'}),
        choices=BOOLEAN_CHOICES,
        initial=BOOLEAN_CHOICES[0][0])

    publish_segments = ChoiceField(
        label='Publish Segments',
        widget=Select(attrs={'class': 'input inline'}),
        choices=BOOLEAN_CHOICES,
        initial=BOOLEAN_CHOICES[0][0])

    def __init__(self, *args, **kwargs):
        super(PodcastForm, self).__init__(*args, **kwargs)

        category_choices = []

        for category in Category.objects.all():
            new_category = []
            sub_categories = []

            if not category.parent:
                if len(category.category_set.all()) > 0:
                    for sub_category in category.category_set.all():
                        sub_categories.append(
                            [sub_category.id, sub_category.name])
                    new_category = [category.name, sub_categories]
                else:
                    new_category = [category.id, category.name]
                category_choices.append(new_category)

        self.fields['itunes_categories'].choices = category_choices

    class Meta:
        model = Podcast

        fieldsets = [('main', {
            'fields': [
                'title', 'slug', 'subtitle', 'description', 'author',
                'contact', 'image', 'frequency', 'language', 'explicit',
                'itunes_categories', 'tags', 'copyright', 'license'
            ],
            'legend':
            'Required Settings',
            'classes': ['required', 'drawer', 'active']
        }),
                     ('Optional', {
                         'fields': [
                             'editor_name', 'editor_email', 'organization',
                             'website', 'station', 'credits', 'feedburner_url',
                             'webmaster_name', 'webmaster_email', 'block',
                             'rename_files', 'tag_audio', 'itunes_url'
                         ],
                         'legend':
                         'Optional Settings',
                         'classes': ['optional', 'collapse']
                     }),
                     ('Advanced', {
                         'fields': [
                             'feed_format', 'ttl', 'max_age', 'pub_url',
                             'storage_url', 'tmp_dir', 'combine_segments',
                             'publish_segments', 'up_dir', 'cleaner'
                         ],
                         'legend':
                         'Advanced Settings',
                         'description':
                         """Don't change these unless you know
                                   what you are doing.""",
                         'classes': ['advanced', 'collapse']
                     })]
Beispiel #14
0
	class Meta:
		model = Note
		fields = ('subject', 'content', 'notebook', 'tags')
		content = forms.CharField( widget=MarkdownWidget() )
 def get_form(self, form_class=None):
     if form_class is None:
         form_class = self.get_form_class()
     form = super().get_form(form_class)
     form.fields['description'] = CharField(widget=MarkdownWidget())
     return form
Beispiel #16
0
class PostForm(forms.Form):
    title = forms.CharField()
    content = forms.CharField(widget=MarkdownWidget())
Beispiel #17
0
class PostForm(forms.ModelForm):
    text = forms.CharField(widget=MarkdownWidget(), required=False)

    class Meta:
        model = Post
        fields = ('title', 'link', 'text')
Beispiel #18
0
class BlogPostForm(forms.ModelForm):
    text = forms.CharField(widget=MarkdownWidget())

    class Meta:
        model = BlogPost
Beispiel #19
0
class ThreadedCommentForm(CommentForm, Html5Mixin):
    name = forms.CharField(label=_("Name"),
                           help_text=_("required"),
                           max_length=50)
    email = forms.EmailField(label=_("Email"),
                             help_text=_("required (not published)"))
    url = forms.URLField(label=_("Website"),
                         help_text=_("optional"),
                         required=False)

    comment = forms.CharField(label=_('Comment'),
                              widget=MarkdownWidget(),
                              max_length=300)

    # These are used to get/set prepopulated fields via cookies.
    cookie_fields = ("name", "email", "url")
    cookie_prefix = "mezzanine-comment-"

    class Meta:
        model = ThreadedComment
        fields = ('comment', )

    def __init__(self, request, *args, **kwargs):
        """
        Set some initial field values from cookies or the logged in
        user, and apply some HTML5 attributes to the fields if the
        ``FORMS_USE_HTML5`` setting is ``True``.
        """
        kwargs.setdefault("initial", {})
        user = request.user
        for field in ThreadedCommentForm.cookie_fields:
            cookie_name = ThreadedCommentForm.cookie_prefix + field
            value = request.COOKIES.get(cookie_name, "")
            if not value and user.is_authenticated():
                if field == "name":
                    value = user.get_full_name()
                    if not value and user.username != user.email:
                        value = user.username
                elif field == "email":
                    value = user.email
            kwargs["initial"][field] = value
        super(ThreadedCommentForm, self).__init__(*args, **kwargs)

    def get_comment_model(self):
        """
        Use the custom comment model instead of the built-in one.
        """
        return ThreadedComment

    def save(self, request):
        """
        Saves a new comment and sends any notification emails.
        """
        comment = self.get_comment_object()
        obj = comment.content_object
        if request.user.is_authenticated():
            comment.user = request.user
        comment.by_author = request.user == getattr(obj, "user", None)
        comment.ip_address = ip_for_request(request)
        comment.replied_to_id = self.data.get("replied_to")
        comment.save()
        comment_was_posted.send(sender=comment.__class__,
                                comment=comment,
                                request=request)
        notify_emails = split_addresses(settings.COMMENTS_NOTIFICATION_EMAILS)
        if notify_emails:
            subject = ugettext("New comment for: ") + str(obj)
            context = {
                "comment": comment,
                "comment_url": add_cache_bypass(comment.get_absolute_url()),
                "request": request,
                "obj": obj,
            }
            send_mail_template(subject, "email/comment_notification",
                               settings.DEFAULT_FROM_EMAIL, notify_emails,
                               context)
        return comment
Beispiel #20
0
class MyMarkdownForm(forms.Form):
    content = forms.CharField(widget=MarkdownWidget())
    content2 = MarkdownFormField()
class CustomForm(forms.Form):

    content = forms.CharField(widget=MarkdownWidget())