# Path: video/forms.py
# class VideoForm(forms.ModelForm):
#     class Meta:
#         model = Video
#         fields = ['title', 'summary', 'url', 'video_at_top', 'hide_info',]
# 
#     def __init__(self, *args, **kwargs):
#         super(VideoForm, self).__init__(*args, **kwargs)
#         self.fields['title'].help_text = "We'll attempt to fill this in from the video service."
#         self.fields['title'].required = False
#         self.fields['summary'].help_text = "We'll attempt to fill this in from the video service."
#         self.fields['summary'].required = False
# 
# Path: video/models.py
# class Video(BaseContentModel):
#     video_at_top = models.BooleanField(
#         "Put video at top",
#         default=False,
#         help_text="""
#             If checked, the video will appear preceding the body
#             of any related content instead of following.
#             """
#     )
#     url = models.CharField(
#         max_length=200,
#         blank=True,
#         help_text=""""
#             Acceptable sources are Youtube, Vimeo and Ustream.
#             Please give the link URL, not the embed code.
#             """
#     )
#     hide_info = models.BooleanField(
#         "Hide title and description",
#         default=False,
#         help_text="""
#             If checked, the video title and description will not be shown.
#             Left unchecked, the video will attempt to display the title and description
#             from the video source.
#             """
#     )
# 
#     content_type = models.ForeignKey(
#         ContentType,
#         on_delete=models.CASCADE,
#         blank=True,
#         null=True
#     )
#     object_id = models.PositiveIntegerField(blank=True, null=True)
#     content_object = GenericForeignKey()
# 
#     key = models.CharField(max_length=20, blank=True, editable=False)
#     source = models.CharField(max_length=20, blank=True, editable=False)
#     embed_src = models.CharField(max_length=200, blank=True, editable=False)
#     thumb_url = models.CharField(max_length=200, blank=True, editable=False)
# 
#     # Managers
#     objects = VideoManager()
#     pub_objects = PublishedVideoManager()
# 
#     def __str__(self):
#         return '{}: {}'.format(self.source, self.title)
# 
#     def get_absolute_url(self):
#         return reverse('video_detail', args=(self.slug,))
# 
#     def save(self, *args, **kwargs):
#         if self.title and not self.slug:
#             self.slug = slugify(self.title)
#         if not self.embed_src:
#             if 'youtube.com/watch' in self.url or 'youtu.be/' in self.url:
#                 self = get_youtube_data(self)
# 
#             if 'vimeo.com/' in self.url:
#                 self = get_vimeo_data(self)
# 
#             if 'ustream.tv/' in self.url:
#                 self = get_ustream_data(self)
# 
#         if self.key and self.embed_src:
#             self.embed_src = """
#                 <iframe src="{}{}" height="360" width="100%%"></iframe>
#                 """.format(self.embed_src, self.key)
#         super(Video, self).save()
# 
#     def get_image(self):
#         return self.thumb_url
# 
# class VideoGallery(models.Model):
#     title = models.CharField(max_length=200)
#     slug = models.SlugField(
#         max_length=200,
#         help_text="Used for URLs. Will auto-fill, but can be edited with caution."
#     )
#     gallery_credit = models.CharField(max_length=200, blank=True)
#     summary = models.TextField(blank=True)
#     featured = models.BooleanField(default=False)
#     created = models.DateTimeField(auto_now_add=True)
#     published = models.BooleanField(default=True)
#     video_collection = models.ManyToManyField(Video)
# 
#     class Meta:
#         verbose_name_plural = "video galleries"
# 
#     def __str__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         return reverse('video_gallery_detail', args=(self.slug,))


from django.contrib import admin
from django.contrib.contenttypes.admin import GenericTabularInline
from .forms import VideoForm
from video.models import Video, VideoGallery
class VideoInline(GenericTabularInline):
    """
    Consistent inlined video for other content admin.
    """
    model = Video
    max_num = 2
    extra = 1
    fields = ('url', 'video_at_top', 'hide_info')


class VideoGalleryAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',)}
    filter_horizontal = ['video_collection']


class VideoAdmin(admin.ModelAdmin):
    form = VideoForm

    prepopulated_fields = {'slug': ('title',)}
    list_display = ('title', 'source')
    fieldsets = (
        ('', {'fields': ('url', 'title', 'summary',)}),
        ('Admin fields', {
            'description': 'These should be filled in for you, but you can edit them.',
            'fields': ('slug', ),
            'classes': ['collapse']
        }),
    )



# Path: video/forms.py
# class VideoForm(forms.ModelForm):
#     class Meta:
#         model = Video
#         fields = ['title', 'summary', 'url', 'video_at_top', 'hide_info',]
# 
#     def __init__(self, *args, **kwargs):
#         super(VideoForm, self).__init__(*args, **kwargs)
#         self.fields['title'].help_text = "We'll attempt to fill this in from the video service."
#         self.fields['title'].required = False
#         self.fields['summary'].help_text = "We'll attempt to fill this in from the video service."
#         self.fields['summary'].required = False
# 
# Path: video/models.py
# class Video(BaseContentModel):
#     video_at_top = models.BooleanField(
#         "Put video at top",
#         default=False,
#         help_text="""
#             If checked, the video will appear preceding the body
#             of any related content instead of following.
#             """
#     )
#     url = models.CharField(
#         max_length=200,
#         blank=True,
#         help_text=""""
#             Acceptable sources are Youtube, Vimeo and Ustream.
#             Please give the link URL, not the embed code.
#             """
#     )
#     hide_info = models.BooleanField(
#         "Hide title and description",
#         default=False,
#         help_text="""
#             If checked, the video title and description will not be shown.
#             Left unchecked, the video will attempt to display the title and description
#             from the video source.
#             """
#     )
# 
#     content_type = models.ForeignKey(
#         ContentType,
#         on_delete=models.CASCADE,
#         blank=True,
#         null=True
#     )
#     object_id = models.PositiveIntegerField(blank=True, null=True)
#     content_object = GenericForeignKey()
# 
#     key = models.CharField(max_length=20, blank=True, editable=False)
#     source = models.CharField(max_length=20, blank=True, editable=False)
#     embed_src = models.CharField(max_length=200, blank=True, editable=False)
#     thumb_url = models.CharField(max_length=200, blank=True, editable=False)
# 
#     # Managers
#     objects = VideoManager()
#     pub_objects = PublishedVideoManager()
# 
#     def __str__(self):
#         return '{}: {}'.format(self.source, self.title)
# 
#     def get_absolute_url(self):
#         return reverse('video_detail', args=(self.slug,))
# 
#     def save(self, *args, **kwargs):
#         if self.title and not self.slug:
#             self.slug = slugify(self.title)
#         if not self.embed_src:
#             if 'youtube.com/watch' in self.url or 'youtu.be/' in self.url:
#                 self = get_youtube_data(self)
# 
#             if 'vimeo.com/' in self.url:
#                 self = get_vimeo_data(self)
# 
#             if 'ustream.tv/' in self.url:
#                 self = get_ustream_data(self)
# 
#         if self.key and self.embed_src:
#             self.embed_src = """
#                 <iframe src="{}{}" height="360" width="100%%"></iframe>
#                 """.format(self.embed_src, self.key)
#         super(Video, self).save()
# 
#     def get_image(self):
#         return self.thumb_url
# 
# class VideoGallery(models.Model):
#     title = models.CharField(max_length=200)
#     slug = models.SlugField(
#         max_length=200,
#         help_text="Used for URLs. Will auto-fill, but can be edited with caution."
#     )
#     gallery_credit = models.CharField(max_length=200, blank=True)
#     summary = models.TextField(blank=True)
#     featured = models.BooleanField(default=False)
#     created = models.DateTimeField(auto_now_add=True)
#     published = models.BooleanField(default=True)
#     video_collection = models.ManyToManyField(Video)
# 
#     class Meta:
#         verbose_name_plural = "video galleries"
# 
#     def __str__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         return reverse('video_gallery_detail', args=(self.slug,))


# Path: video/admin.py
from django.contrib import admin
from django.contrib.contenttypes.admin import GenericTabularInline
from .forms import VideoForm
from video.models import Video, VideoGallery

class VideoInline(GenericTabularInline):
    """
    Consistent inlined video for other content admin.
    """
    model = Video
    max_num = 2
    extra = 1
    fields = ('url', 'video_at_top', 'hide_info')


class VideoGalleryAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',)}
    filter_horizontal = ['video_collection']


class VideoAdmin(admin.ModelAdmin):
    form = VideoForm

    prepopulated_fields = {'slug': ('title',)}
    list_display = ('title', 'source')
    fieldsets = (
        ('', {'fields': ('url', 'title', 'summary',)}),
        ('Admin fields', {
            'description': 'These should be filled in for you, but you can edit them.',
            'fields': ('slug', ),
            'classes': ['collapse']
        }),
    )



admin.site.register(Video, VideoAdmin)