mirror of
https://github.com/Hopiu/django-embed-video.git
synced 2026-05-01 01:44:42 +00:00
Example project
This commit is contained in:
parent
5cb9019b31
commit
55eaef7301
19 changed files with 280 additions and 0 deletions
1
example_project/.gitignore
vendored
Normal file
1
example_project/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
*.sqlite3
|
||||
16
example_project/README.rst
Normal file
16
example_project/README.rst
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
How to run it?
|
||||
**************
|
||||
|
||||
#. Install Django::
|
||||
|
||||
pip install Django
|
||||
|
||||
#. Create database (you can create admin account)::
|
||||
|
||||
python manage.py syncdb
|
||||
|
||||
#. Run testing server::
|
||||
|
||||
python manage.py runserver
|
||||
|
||||
#. Take a look at http://localhost:8000
|
||||
1
example_project/embed_video
Symbolic link
1
example_project/embed_video
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../embed_video
|
||||
0
example_project/example_project/__init__.py
Normal file
0
example_project/example_project/__init__.py
Normal file
44
example_project/example_project/settings.py
Normal file
44
example_project/example_project/settings.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# Django settings for example_project project.
|
||||
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': 'example_project.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
SECRET_KEY = 'u%38dln@$1!7w#cxi4np504^sa3_skv5aekad)jy_u0v2mc+nr'
|
||||
|
||||
TEMPLATE_LOADERS = (
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
)
|
||||
|
||||
|
||||
ROOT_URLCONF = 'example_project.urls'
|
||||
|
||||
|
||||
DJANGO_APPS = (
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.sites',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.admin',
|
||||
)
|
||||
|
||||
THIRD_PARTY_APPS = (
|
||||
'embed_video',
|
||||
)
|
||||
|
||||
LOCAL_APPS = (
|
||||
'example_project',
|
||||
'posts',
|
||||
)
|
||||
|
||||
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
|
||||
30
example_project/example_project/templates/base.html
Normal file
30
example_project/example_project/templates/base.html
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<!doctype HTML>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<title>django-embed-video example project</title>
|
||||
|
||||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
|
||||
<style>
|
||||
body {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 64px;
|
||||
margin: 20px 5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
9
example_project/example_project/urls.py
Normal file
9
example_project/example_project/urls.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from django.conf.urls import patterns, include, url
|
||||
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^', include('posts.urls', namespace='posts')),
|
||||
)
|
||||
32
example_project/example_project/wsgi.py
Normal file
32
example_project/example_project/wsgi.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
"""
|
||||
WSGI config for example_project project.
|
||||
|
||||
This module contains the WSGI application used by Django's development server
|
||||
and any production WSGI deployments. It should expose a module-level variable
|
||||
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
|
||||
this application via the ``WSGI_APPLICATION`` setting.
|
||||
|
||||
Usually you will have the standard Django WSGI application here, but it also
|
||||
might make sense to replace the whole Django WSGI application with a custom one
|
||||
that later delegates to the Django one. For example, you could introduce WSGI
|
||||
middleware here, or combine a Django application with an application of another
|
||||
framework.
|
||||
|
||||
"""
|
||||
import os
|
||||
|
||||
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
|
||||
# if running multiple sites in the same mod_wsgi process. To fix this, use
|
||||
# mod_wsgi daemon mode with each site in its own daemon process, or use
|
||||
# os.environ["DJANGO_SETTINGS_MODULE"] = "example_project.settings"
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_project.settings")
|
||||
|
||||
# This application object is used by any WSGI server configured to use this
|
||||
# file. This includes Django's development server, if the WSGI_APPLICATION
|
||||
# setting points here.
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
application = get_wsgi_application()
|
||||
|
||||
# Apply WSGI middleware here.
|
||||
# from helloworld.wsgi import HelloWorldApplication
|
||||
# application = HelloWorldApplication(application)
|
||||
10
example_project/manage.py
Executable file
10
example_project/manage.py
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_project.settings")
|
||||
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
execute_from_command_line(sys.argv)
|
||||
0
example_project/posts/__init__.py
Normal file
0
example_project/posts/__init__.py
Normal file
6
example_project/posts/admin.py
Normal file
6
example_project/posts/admin.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Post
|
||||
|
||||
|
||||
admin.site.register(Post)
|
||||
39
example_project/posts/fixtures/initial_data.yaml
Normal file
39
example_project/posts/fixtures/initial_data.yaml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
- fields: {title: I will wait, video: 'http://www.youtube.com/watch?v=rGKfrgqWcv0'}
|
||||
model: posts.post
|
||||
pk: 1
|
||||
- fields: {title: Cinematographer, video: 'http://vimeo.com/59626663'}
|
||||
model: posts.post
|
||||
pk: 2
|
||||
- fields: {title: Come Healing, video: 'http://www.youtube.com/watch?v=ueHqPGk_ybc'}
|
||||
model: posts.post
|
||||
pk: 3
|
||||
- fields: {title: Mountain Sound, video: 'http://www.youtube.com/watch?v=vT3HrrrHzII'}
|
||||
model: posts.post
|
||||
pk: 4
|
||||
- fields: {title: Lost in the echo, video: 'https://soundcloud.com/linkin_park/linkin-park-lost-in-the-echo'}
|
||||
model: posts.post
|
||||
pk: 5
|
||||
- fields: {title: Moonlight Sonata, video: 'https://soundcloud.com/glennmorrison/beethoven-moonlight-sonata'}
|
||||
model: posts.post
|
||||
pk: 6
|
||||
- fields: {title: 5th Symphony, video: 'https://soundcloud.com/vahe-ghukasyan/beethoven-5th-symphony'}
|
||||
model: posts.post
|
||||
pk: 7
|
||||
- fields: {title: Stubborn love, video: 'http://youtu.be/UJWk_KNbDHo'}
|
||||
model: posts.post
|
||||
pk: 8
|
||||
- fields: {title: Timelapse, video: 'http://vimeo.com/14352658'}
|
||||
model: posts.post
|
||||
pk: 9
|
||||
- fields: {title: Slovakia, video: 'https://vimeo.com/72304002'}
|
||||
model: posts.post
|
||||
pk: 10
|
||||
- fields: {title: Zodiac, video: 'http://www.youtube.com/watch?feature=player_embedded&v=Ox6d0OsyfPw'}
|
||||
model: posts.post
|
||||
pk: 11
|
||||
- fields: {title: The Book Thief, video: 'http://www.youtube.com/watch?v=DIqAQNYIVDU&feature=share'}
|
||||
model: posts.post
|
||||
pk: 12
|
||||
- fields: {title: See You At The Bottom, video: 'https://vimeo.com/71338160'}
|
||||
model: posts.post
|
||||
pk: 13
|
||||
15
example_project/posts/models.py
Normal file
15
example_project/posts/models.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from django.db import models
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from embed_video.fields import EmbedVideoField
|
||||
|
||||
|
||||
class Post(models.Model):
|
||||
title = models.CharField(max_length=50)
|
||||
video = EmbedVideoField()
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('posts:detail', kwargs={'pk': self.pk})
|
||||
13
example_project/posts/templates/posts/post_detail.html
Normal file
13
example_project/posts/templates/posts/post_detail.html
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% load embed_video_tags %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>
|
||||
{{ object.title }}
|
||||
<a href="{% url "posts:list" %}" class="pull-right"><small>Back to list</small></a>
|
||||
</h1>
|
||||
|
||||
{{ object.video|embed:"large" }}
|
||||
{% endblock %}
|
||||
27
example_project/posts/templates/posts/post_list.html
Normal file
27
example_project/posts/templates/posts/post_list.html
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% load embed_video_tags %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Posts</h1>
|
||||
|
||||
<table class="table">
|
||||
{% for post in object_list %}
|
||||
<tr>
|
||||
{% video post.video as video %}
|
||||
<td><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></td>
|
||||
<td><img src="{{ video.thumbnail }}" width=60 height=45 class="img-rounded"></td>
|
||||
{% endvideo %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
<ul class="pager">
|
||||
{% if page_obj.has_previous %}
|
||||
<li class="previous"><a href="?page={{ page_obj.previous_page_number }}">← Older</a></li>
|
||||
{% endif %}
|
||||
{% if page_obj.has_next %}
|
||||
<li class="next"><a href="?page={{ page_obj.next_page_number }}">Newer →</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
16
example_project/posts/tests.py
Normal file
16
example_project/posts/tests.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
||||
8
example_project/posts/urls.py
Normal file
8
example_project/posts/urls.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from django.conf.urls import patterns, url
|
||||
|
||||
from .views import PostListView, PostDetailView
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'(?P<pk>\d+)/$', PostDetailView.as_view(), name='detail'),
|
||||
url(r'$', PostListView.as_view(), name='list'),
|
||||
)
|
||||
12
example_project/posts/views.py
Normal file
12
example_project/posts/views.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from django.views.generic import ListView, DetailView
|
||||
|
||||
from .models import Post
|
||||
|
||||
|
||||
class PostListView(ListView):
|
||||
model = Post
|
||||
paginate_by = 10
|
||||
|
||||
|
||||
class PostDetailView(DetailView):
|
||||
model = Post
|
||||
1
example_project/requirements.txt
Normal file
1
example_project/requirements.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
Django>=1.5
|
||||
Loading…
Reference in a new issue