Esempio n. 1
0
class ShowAdmin(TranslationAdmin):
    form = AdminShowForm

    list_display = ("title", "slug", "show_site", "published_flag",
                    "admin_thumbnail")
    list_filter = ("title", "published", "site")
    admin_thumbnail = AdminThumbnail(image_field="admin_thumb_sm")

    formfield_overrides = {
        models.TextField: {
            'widget': TinyMCE
        },
    }

    if can_tweet():
        fields.append("tweet_text")

    def published_flag(self, obj):
        return bool(obj.published)

    published_flag.short_description = _("Published")
    published_flag.boolean = True

    def show_site(self, obj):
        return obj.site.name

    show_site.short_description = "Site"
Esempio n. 2
0
    def save(self):
        instance = super(BaseEpisodeForm, self).save()

        if can_tweet() and self.cleaned_data["tweet"]:
            instance.tweet()

        return instance
Esempio n. 3
0
class EpisodeAdmin(TranslationAdmin):
    form = AdminEpisodeForm

    list_display = ("title", "show", "slug", "episode_site", "published_flag",
                    "admin_thumbnail")
    list_filter = ("show", "published")
    admin_thumbnail = AdminThumbnail(image_field="admin_thumb_sm")

    formfield_overrides = {
        models.TextField: {
            'widget': TinyMCE
        },
    }

    if can_tweet():
        readonly_fields = ("tweet_text", )

    def published_flag(self, obj):
        return bool(obj.published)

    published_flag.short_description = _("Published")
    published_flag.boolean = True

    def episode_site(self, obj):
        return obj.show.site.name

    episode_site.short_description = "Site"

    def save_form(self, request, form, change):
        # this is done for explicitness that we want form.save to commit
        # form.save doesn't take a commit kwarg for this reason
        return form.save()
Esempio n. 4
0
    def save(self):
        instance = super(BaseEpisodeForm, self).save()

        if can_tweet() and self.cleaned_data["tweet"]:
            instance.tweet()

        return instance
Esempio n. 5
0
class EpisodeAdmin(admin.ModelAdmin):
    form = AdminEpisodeForm

    list_display = ["title", "episode_shows", "slug", "episode_sites", "published_flag"]
    list_filter = ["shows", "published"]
    if AdminThumbnail:
        list_display.append("admin_thumbnail")
        admin_thumbnail = AdminThumbnail(image_field="admin_thumb_sm")

    if can_tweet():
        readonly_fields = ("tweet_text",)

    def published_flag(self, obj):
        return bool(obj.published)
    published_flag.short_description = _("Published")
    published_flag.boolean = True

    def episode_shows(self, obj):
        return ', '.join([show.title for show in obj.shows.all()])
    episode_shows.short_description = "Shows"

    def episode_sites(self, obj):
        sites = list()
        for show in obj.shows.all():
            for site in show.sites.all():
                if site not in sites:
                    sites.append(site)
        return ', '.join([site.name for site in sites])
    episode_sites.short_description = "Sites"

    def save_form(self, request, form, change):
        # this is done for explicitness that we want form.save to commit
        # form.save doesn't take a commit kwarg for this reason
        return form.save()
Esempio n. 6
0
class BaseEpisodeForm(forms.ModelForm):

    if imagekit:
        original_image = forms.ImageField(
            widget=CustomAdminThumbnailWidget,
            help_text=Episode._meta.get_field("original_image").help_text)

    publish = forms.BooleanField(
        required=False,
        help_text=
        _("Checking this will publish this episode on the site, no turning back."
          ),
    )

    if can_tweet():
        tweet = forms.BooleanField(
            required=False,
            help_text=_(
                "Checking this will send out a tweet announcing the episode."),
        )

    class Meta:
        model = Episode
        fields = [
            "original_image",
            "author_text",
            "title",
            "subtitle",
            "description",
            "keywords",
            "tracklist",
            "hours",
            "minutes",
            "seconds",
            "explicit",
            "block",
            "publish",
        ]
        if "taggit" in settings.INSTALLED_APPS:
            fields.append("tags")

    def save(self):
        instance = super(BaseEpisodeForm, self).save()

        if can_tweet() and self.cleaned_data["tweet"]:
            instance.tweet()

        return instance

    def validate_published(self):
        if not self.instance.enclosure_set.all():
            raise forms.ValidationError(
                _("An episode must have at least one enclosure before publishing.\n \
                                          Uncheck, save this episode, and add an encoslure before publishing."
                  ))
        elif not self.instance.show.published:
            raise forms.ValidationError(
                _("The show for this episode is not yet published"))
        self.instance.published = datetime.now()
Esempio n. 7
0
 def tweet(self):
     if can_tweet():
         account = twitter.Api(username=settings.TWITTER_USERNAME, password=settings.TWITTER_PASSWORD)
         account.PostUpdate(self.as_tweet())
     else:
         raise ImproperlyConfigured(
             "Unable to send tweet due to either " "missing python-twitter or required settings."
         )
Esempio n. 8
0
    def save(self):
        episode = super(AdminEpisodeForm, self).save(commit=False)

        episode.save()

        if can_tweet() and self.cleaned_data["tweet"]:
            episode.tweet()

        return episode
Esempio n. 9
0
 def tweet(self):
     if can_tweet():
         account = twitter.Api(username=settings.TWITTER_USERNAME,
                               password=settings.TWITTER_PASSWORD)
         account.PostUpdate(self.as_tweet())
     else:
         raise ImproperlyConfigured(
             "Unable to send tweet due to either "
             "missing python-twitter or required settings.")
Esempio n. 10
0
    def save(self):
        episode = super(AdminEpisodeForm, self).save(commit=False)

        episode.save()

        if can_tweet() and self.cleaned_data["tweet"]:
            episode.tweet()

        return episode
Esempio n. 11
0
class AdminEpisodeForm(forms.ModelForm):

    publish = forms.BooleanField(
        required=False,
        help_text=
        _("Checking this will publish this episode on the site, no turning back."
          ),
    )

    if can_tweet():
        tweet = forms.BooleanField(
            required=False,
            help_text=_(
                "Checking this will send out a tweet announcing the episode."),
        )

    class Meta:
        model = Episode

    def __init__(self, *args, **kwargs):
        super(AdminEpisodeForm, self).__init__(*args, **kwargs)
        self.fields["publish"].initial = bool(self.instance.published)

    def validate_published(self):
        if not self.instance.enclosure_set.all():
            raise forms.ValidationError(
                _("An episode must have at least one enclosure before publishing.\n \
                                          Uncheck, save this episode, and add an encoslure before publishing."
                  ))
        elif not self.instance.show.published:
            raise forms.ValidationError(
                _("The show for this episode is not yet published"))
        self.instance.published = datetime.now()

    def clean_publish(self):
        # clean_publish is called twice, skip the first time when instance is unset
        if not self.instance.pk:
            return
        # do nothing if already published
        if self.instance.published:
            return
        if self.cleaned_data["publish"]:
            self.validate_published()

    def save(self):
        episode = super(AdminEpisodeForm, self).save(commit=False)

        episode.save()

        if can_tweet() and self.cleaned_data["tweet"]:
            episode.tweet()

        return episode
Esempio n. 12
0
    def save(self):
        episode = super(AdminEpisodeForm, self).save(commit=False)

        if episode.pk is None:
            if self.cleaned_data["publish"]:
                episode.published = datetime.now()
        else:
            if Episode.objects.filter(pk=episode.pk, published=None).count():
                if self.cleaned_data["publish"]:
                    episode.published = datetime.now()

        episode.updated = datetime.now()
        episode.save()

        if can_tweet() and self.cleaned_data["tweet"]:
            episode.tweet()

        return episode
Esempio n. 13
0
class ShowAdmin(admin.ModelAdmin):
    form = AdminShowForm

    list_display = ["title", "slug", "show_sites", "published_flag"]
    list_filter = ["title", "published", "sites"]
    if AdminThumbnail:
        list_display.append("admin_thumbnail")
        admin_thumbnail = AdminThumbnail(image_field="admin_thumb_sm")

    if can_tweet():
        fields.append("tweet_text")  # noqa

    def published_flag(self, obj):
        return bool(obj.published)
    published_flag.short_description = _("Published")
    published_flag.boolean = True

    def show_sites(self, obj):
        return ', '.join([site.name for site in obj.sites.all()])
    show_sites.short_description = "Sites"
Esempio n. 14
0
class AdminEpisodeForm(forms.ModelForm):

    publish = forms.BooleanField(
        label=_("publish"),
        required=False,
        help_text=_("Checking this will publish this episode on the site, no turning back."))

    if can_tweet():
        tweet = forms.BooleanField(
            required=False,
            help_text=_("Checking this will send out a tweet announcing the episode."))

    class Meta:
        model = Episode
        fields = [
            "shows",
            "original_image",
            "youtube_url",
            "author_text",
            "title", "subtitle",
            "description",
            "tracklist",
            "hours", "minutes", "seconds",
            "published",
            "publish",
            "keywords",
            "explicit",
            "block",
        ]
        if "taggit" in settings.INSTALLED_APPS:
            fields.append("tags")

    def __init__(self, *args, **kwargs):
        super(AdminEpisodeForm, self).__init__(*args, **kwargs)
        self.fields["publish"].initial = bool(self.instance.published)

    def validate_published(self):
        if not self.instance.enclosure_set.count() and not self.instance.embedmedia_set.count():
            raise forms.ValidationError(
                _("An episode must have at least one enclosure or media file before publishing.\n "
                  "Uncheck, save this episode, and add an encoslure before publishing."))
        elif not self.instance.is_show_published:
            raise forms.ValidationError(_("The show for this episode is not yet published"))
        if not self.instance.published:
            self.instance.published = now()

    def clean_publish(self):
        # clean_publish is called twice, skip the first time when instance is unset
        if not self.instance.pk:
            return
        # do nothing if already published
        # CHANGED, because `instance.published` is now editable
        # if self.instance.published:
        #     return
        if self.cleaned_data["publish"]:
            self.validate_published()
        return self.cleaned_data["publish"]

    def save(self):
        episode = super(AdminEpisodeForm, self).save(commit=False)

        episode.save()

        if can_tweet() and self.cleaned_data["tweet"]:
            episode.tweet()

        return episode