Skip to content

Commit

Permalink
Added video width
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuluPro committed Dec 30, 2016
1 parent 47e106d commit 034d3be
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 36 deletions.
3 changes: 2 additions & 1 deletion dj_web_rich_object/__init__.py
@@ -1,7 +1,8 @@
"""Reusable app made for handle web rich objects"""
VERSION = (0, 2, 3)
VERSION = (0, 3, 0)
__version__ = '.'.join([str(i) for i in VERSION])
__author__ = 'Anthony Monthe (ZuluPro)'
__email__ = 'anthony.monthe@gmail.com'
__url__ = 'https://github.com/ZuluPro/django-web-rich-object'
__license__ = 'BSD'
__keywords__ = ['web', 'django', 'opengraph', 'web-rich-object', 'facebook']
38 changes: 36 additions & 2 deletions dj_web_rich_object/admin/modeladmins.py
Expand Up @@ -14,7 +14,7 @@ class WebRichObjectAdmin(admin.ModelAdmin):
date_hierarchy = 'updated_at'
ordering = ('-updated_at',)
form = forms.WebRichObjectAdminForm
fieldsets = (
default_fieldsets = (
(None, {
'classes': ('wide',),
'fields': (
Expand All @@ -40,6 +40,38 @@ class WebRichObjectAdmin(admin.ModelAdmin):
)
}),
)
video_fieldsets = (
(None, {
'classes': ('wide',),
'fields': (
('title', 'site_name'),
'author',
'description',
)
}),
(_("Type"), {
'fields': (
('type', 'subtype'),
)
}),
(_("Video"), {
'fields': (
'video',
('video_width', 'video_height'),
)
}),
(_("URLs"), {
'fields': (
('url', 'base_url'),
('image'),
)
}),
(_("Dates"), {
'fields': (
('created_time', 'published_time', 'modified_time'),
)
}),
)

add_form = forms.WebRichObjectAdminAddForm
add_fieldsets = (
Expand All @@ -57,7 +89,9 @@ def get_form(self, request, obj=None, **kwargs):
def get_fieldsets(self, request, obj=None):
if obj is None:
return self.add_fieldsets
return super(WebRichObjectAdmin, self).get_fieldsets(request, obj)
if obj.type.startswith('video'):
return self.video_fieldsets
return self.default_fieldsets

def add_view(self, request, form_url='', extra_context=None):
if request.method == 'GET':
Expand Down
24 changes: 24 additions & 0 deletions dj_web_rich_object/migrations/0008_auto_20161229_0523.py
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dj_web_rich_object', '0007_webrichobject_video'),
]

operations = [
migrations.AddField(
model_name='webrichobject',
name='video_height',
field=models.PositiveIntegerField(null=True, verbose_name='video height', blank=True),
),
migrations.AddField(
model_name='webrichobject',
name='video_width',
field=models.PositiveIntegerField(null=True, verbose_name='video width', blank=True),
),
]
26 changes: 19 additions & 7 deletions dj_web_rich_object/models.py
Expand Up @@ -14,18 +14,25 @@ def create_from_url(self, url=None, **kwargs):
wro = web_rich_object.WebRichObject(url)
wro_attrs = {
'title': wro.title,
'site_name': wro.site_name,
'description': wro.description,

'type': wro.type,
'subtype': wro.subtype,

'image': wro.image,
'video': wro.video,

'url': wro.url,
'base_url': wro.base_url,
'site_name': wro.site_name,
'description': wro.description,
'subtype': wro.subtype,

'author': wro.author,
'created_time': wro.created_time,
'published_time': wro.published_time,
'modified_time': wro.modified_time,

'video': wro.video,
'video_width': wro.video_width,
'video_height': wro.video_height,
}
wro_attrs.update(kwargs)
instance = self.create(**wro_attrs)
Expand All @@ -49,7 +56,10 @@ class WebRichObject(models.Model):
base_url = models.TextField(max_length=500, verbose_name=_("Base URL"))

image = models.URLField(null=True, blank=True, verbose_name=_("image"))

video = models.URLField(null=True, blank=True, verbose_name=_("video"))
video_width = models.PositiveIntegerField(null=True, blank=True, verbose_name=_("video width"))
video_height = models.PositiveIntegerField(null=True, blank=True, verbose_name=_("video height"))

site_name = models.CharField(max_length=200, null=True, blank=True, verbose_name=_("site name"))
description = models.TextField(null=True, blank=True, default='', verbose_name=_("description"))
Expand Down Expand Up @@ -98,10 +108,12 @@ def get_image(self, target='_blank'):
def template_name(self):
return 'wro/widget_%s.html' % self.type

def get_widget(self):
def get_widget(self, **kwargs):
context = kwargs.copy()
context['obj'] = self
try:
if self.type == 'video' and self.video is None:
raise TemplateDoesNotExist("No video provided")
return render_to_response(self.template_name, {'obj': self}).getvalue()
return render_to_response(self.template_name, context).getvalue()
except TemplateDoesNotExist:
return render_to_response('wro/widget_website.html', {'obj': self}).getvalue()
return render_to_response('wro/widget_website.html', context).getvalue()
1 change: 1 addition & 0 deletions dj_web_rich_object/templates/wro/widget_article.html
Expand Up @@ -11,5 +11,6 @@ <h3>{{ obj.title }}</h3>
{% if obj.description %}
<p class="wro-description">{{ obj.description }}</p>
{% endif %}
<p class="wro-site-name">{{ obj.site_name }}</p>
</a>
{% endblock %}
4 changes: 3 additions & 1 deletion dj_web_rich_object/templates/wro/widget_image.html
Expand Up @@ -2,6 +2,8 @@

{% block content %}
<a href="{{ obj.url }}" target="_blank">
<img src="{{ obj.image }}"/>
<div class="wro-image-container">
<img src="{{ obj.image }}"/>
</div>
</a>
{% endblock %}
1 change: 1 addition & 0 deletions dj_web_rich_object/templates/wro/widget_object.html
Expand Up @@ -11,5 +11,6 @@ <h3>{{ obj.title }}</h3>
{% if obj.description %}
<p class="wro-description">{{ obj.description }}</p>
{% endif %}
<p class="wro-site-name">{{ obj.site_name }}</p>
</a>
{% endblock %}
1 change: 1 addition & 0 deletions dj_web_rich_object/templates/wro/widget_photo.html
1 change: 1 addition & 0 deletions dj_web_rich_object/templates/wro/widget_product.html
Expand Up @@ -11,5 +11,6 @@ <h3>{{ obj.title }}</h3>
{% if obj.description %}
<p class="wro-description">{{ obj.description }}</p>
{% endif %}
<p class="wro-site-name">{{ obj.site_name }}</p>
</a>
{% endblock %}
11 changes: 0 additions & 11 deletions dj_web_rich_object/templates/wro/widget_tv_show.html

This file was deleted.

1 change: 1 addition & 0 deletions dj_web_rich_object/templates/wro/widget_tv_show.html
11 changes: 6 additions & 5 deletions dj_web_rich_object/templates/wro/widget_video.html
@@ -1,11 +1,12 @@
{% extends "wro/base.html" %}

{% block content %}
<iframe width="98%" height="315" src="{{ obj.video }}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<div class="wro-iframe-container">
<iframe width="{{ video_width|default:"" }}" height="{{ video_height|default:"" }}" src="{{ obj.video }}{{ url_suffix|default:"" }}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>

<a href="{{ obj.url }}" target="_blank">
<h3>{{ obj.title }}</h3>
{% if obj.description %}
<p class="wro-description">{{ obj.description }}</p>
{% endif %}
<h3>{{ obj.title }}</h3>
{% if obj.description %}<p class="wro-description">{{ obj.description }}</p>{% endif %}
</a>
{% endblock %}
2 changes: 1 addition & 1 deletion dj_web_rich_object/templates/wro/widget_website.html
Expand Up @@ -11,6 +11,6 @@ <h3>{{ obj.title }}</h3>
{% if obj.description %}
<p class="wro-description">{{ obj.description }}</p>
{% endif %}
<p class="wro-site-name">{{ obj.site_name }}</p>
<p class="wro-site-name">{{ obj.site_name }}</p>
</a>
{% endblock %}
Empty file.
8 changes: 8 additions & 0 deletions dj_web_rich_object/templatetags/wro.py
@@ -0,0 +1,8 @@
from django import template

register = template.Library()


@register.simple_tag
def get_widget(wro, **kwargs):
return wro.get_widget(**kwargs)
30 changes: 24 additions & 6 deletions dj_web_rich_object/tests/settings.py
Expand Up @@ -5,7 +5,7 @@
import tempfile
import dj_database_url

DEBUG = False
DEBUG = int(os.environ.get('DEBUG', '1'))

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
TESTAPP_DIR = os.path.join(BASE_DIR, 'testapp/')
Expand All @@ -14,17 +14,25 @@
('ham', 'foo@bar'),
)
ALLOWED_HOSTS = ['*']
MIDDLEWARE_CLASSES = ()
ROOT_URLCONF = 'dbbackup.tests.testapp.urls'
MIDDLEWARE_CLASSES = MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'dj_web_rich_object.tests.urls'
SECRET_KEY = "it's a secret to everyone"
SITE_ID = 1
MEDIA_ROOT = os.environ.get('MEDIA_ROOT') or tempfile.mkdtemp()
INSTALLED_APPS = (
'django.contrib.staticfiles',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.admin',
'dj_web_rich_object',
)

DATABASE = dj_database_url.config(default='sqlite:///%s' %
tempfile.mktemp())
DATABASE = dj_database_url.config(default='sqlite:///test.sqlite')
DATABASES = {'default': DATABASE}

CACHES = {
Expand All @@ -38,5 +46,15 @@
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'OPTIONS': {
'context_processors': (
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
)
}
},
]

STATIC_URL = '/static/'
MEDIA_ROOT = os.environ.get('MEDIA_ROOT') or tempfile.mkdtemp()
13 changes: 13 additions & 0 deletions dj_web_rich_object/tests/urls.py
@@ -0,0 +1,13 @@
from django.contrib import admin

try:
from django.conf.urls import patterns, include, url
urlpatterns = patterns(
'',
url(r'^admin/', include(admin.site.urls)),
)
except ImportError:
from django.conf.urls import include, url
urlpatterns = (
url(r'^admin/', include(admin.site.urls)),
)
3 changes: 1 addition & 2 deletions setup.py
Expand Up @@ -12,11 +12,10 @@ def read(filename):
version=dj_web_rich_object.__version__,
description=dj_web_rich_object.__doc__,
long_description=read('README.rst'),
keywords=['web', 'django', 'opengraph', 'web-rich-object'],
keywords=dj_web_rich_object.__keywords__,
author=dj_web_rich_object.__author__,
author_email=dj_web_rich_object.__email__,
url=dj_web_rich_object.__url__,

packages=find_packages(),
classifiers=[
'Framework :: Django',
Expand Down

0 comments on commit 034d3be

Please sign in to comment.