Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

created

  • Loading branch information...
commit 5e9356c4bd892ef98039c3d0248a915e9b361499 0 parents
Alexander Razzhivin authored February 29, 2012
20  .hgignore
... ...
@@ -0,0 +1,20 @@
  1
+syntax: regexp
  2
+
  3
+^.+\.db$
  4
+^.+\.sqlite$
  5
+^.+\.pyc$
  6
+^.+\.log$
  7
+^.+\$py\.class$
  8
+^.+overrides.py$
  9
+^.coverage$
  10
+^.+\.egg-info$
  11
+
  12
+# ignore project dirs
  13
+
  14
+media/
  15
+cover/
  16
+build/
  17
+src/
  18
+.idea/
  19
+build/
  20
+dist/
0  __init__.py
No changes.
0  demo_project/__init__.py
No changes.
14  demo_project/manage.py
... ...
@@ -0,0 +1,14 @@
  1
+#!/usr/bin/env python
  2
+from django.core.management import execute_manager
  3
+import imp
  4
+try:
  5
+    imp.find_module('settings') # Assumed to be in the same directory.
  6
+except ImportError:
  7
+    import sys
  8
+    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
  9
+    sys.exit(1)
  10
+
  11
+import settings
  12
+
  13
+if __name__ == "__main__":
  14
+    execute_manager(settings)
182  demo_project/settings.py
... ...
@@ -0,0 +1,182 @@
  1
+# Django settings for demo_project project.
  2
+import sys
  3
+import os
  4
+
  5
+PROJECT_DIR, PROJECT_MODULE_NAME = os.path.split(
  6
+    os.path.dirname(os.path.realpath(__file__))
  7
+)
  8
+sys.path.append(os.path.join(PROJECT_DIR))
  9
+
  10
+DEBUG = True
  11
+TEMPLATE_DEBUG = DEBUG
  12
+TEST_RECORDER = False
  13
+
  14
+ADMINS = (
  15
+    # ('Your Name', 'your_email@example.com'),
  16
+)
  17
+
  18
+MANAGERS = ADMINS
  19
+
  20
+DATABASES = {
  21
+    'default': {
  22
+        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
  23
+        'NAME': 'demo_project.db',                      # Or path to database file if using sqlite3.
  24
+        'USER': '',                      # Not used with sqlite3.
  25
+        'PASSWORD': '',                  # Not used with sqlite3.
  26
+        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
  27
+        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
  28
+    }
  29
+}
  30
+
  31
+# Local time zone for this installation. Choices can be found here:
  32
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  33
+# although not all choices may be available on all operating systems.
  34
+# On Unix systems, a value of None will cause Django to use the same
  35
+# timezone as the operating system.
  36
+# If running in a Windows environment this must be set to the same as your
  37
+# system time zone.
  38
+TIME_ZONE = 'America/Chicago'
  39
+
  40
+# Language code for this installation. All choices can be found here:
  41
+# http://www.i18nguy.com/unicode/language-identifiers.html
  42
+LANGUAGE_CODE = 'en-us'
  43
+
  44
+SITE_ID = 1
  45
+
  46
+# If you set this to False, Django will make some optimizations so as not
  47
+# to load the internationalization machinery.
  48
+USE_I18N = True
  49
+
  50
+# If you set this to False, Django will not format dates, numbers and
  51
+# calendars according to the current locale
  52
+USE_L10N = True
  53
+
  54
+# Absolute filesystem path to the directory that will hold user-uploaded files.
  55
+# Example: "/home/media/media.lawrence.com/media/"
  56
+MEDIA_ROOT = ''
  57
+
  58
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
  59
+# trailing slash.
  60
+# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
  61
+MEDIA_URL = ''
  62
+
  63
+# Absolute path to the directory static files should be collected to.
  64
+# Don't put anything in this directory yourself; store your static files
  65
+# in apps' "static/" subdirectories and in STATICFILES_DIRS.
  66
+# Example: "/home/media/media.lawrence.com/static/"
  67
+STATIC_ROOT = ''
  68
+
  69
+# URL prefix for static files.
  70
+# Example: "http://media.lawrence.com/static/"
  71
+STATIC_URL = '/static/'
  72
+
  73
+# URL prefix for admin static files -- CSS, JavaScript and images.
  74
+# Make sure to use a trailing slash.
  75
+# Examples: "http://foo.com/static/admin/", "/static/admin/".
  76
+ADMIN_MEDIA_PREFIX = '/static/admin/'
  77
+
  78
+# Additional locations of static files
  79
+STATICFILES_DIRS = (
  80
+    # Put strings here, like "/home/html/static" or "C:/www/django/static".
  81
+    # Always use forward slashes, even on Windows.
  82
+    # Don't forget to use absolute paths, not relative paths.
  83
+)
  84
+
  85
+# List of finder classes that know how to find static files in
  86
+# various locations.
  87
+STATICFILES_FINDERS = (
  88
+    'django.contrib.staticfiles.finders.FileSystemFinder',
  89
+    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  90
+#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
  91
+)
  92
+
  93
+# Make this unique, and don't share it with anybody.
  94
+SECRET_KEY = 'q)gb4hn*010$td+3xy9e=n67tkw%js2o%#@o=$o93)cb8yrbxi'
  95
+
  96
+# List of callables that know how to import templates from various sources.
  97
+TEMPLATE_LOADERS = (
  98
+    'django.template.loaders.filesystem.Loader',
  99
+    'django.template.loaders.app_directories.Loader',
  100
+#     'django.template.loaders.eggs.Loader',
  101
+)
  102
+
  103
+TEMPLATE_CONTEXT_PROCESSORS = (
  104
+    'django.contrib.auth.context_processors.auth',
  105
+    'django.core.context_processors.debug',
  106
+    'django.core.context_processors.i18n',
  107
+    'django.core.context_processors.media',
  108
+    'django.core.context_processors.static',
  109
+    'django.core.context_processors.request',
  110
+)
  111
+
  112
+MIDDLEWARE_CLASSES = (
  113
+    'django.middleware.common.CommonMiddleware',
  114
+    'django.contrib.sessions.middleware.SessionMiddleware',
  115
+    'django.middleware.csrf.CsrfViewMiddleware',
  116
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
  117
+    'django.contrib.messages.middleware.MessageMiddleware',
  118
+)
  119
+
  120
+ROOT_URLCONF = 'demo_project.urls'
  121
+
  122
+TEMPLATE_DIRS = (
  123
+    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
  124
+    # Always use forward slashes, even on Windows.
  125
+    # Don't forget to use absolute paths, not relative paths.
  126
+    os.path.join(PROJECT_DIR, PROJECT_MODULE_NAME, 'templates'),
  127
+)
  128
+
  129
+INSTALLED_APPS = (
  130
+    'django.contrib.auth',
  131
+    'django.contrib.contenttypes',
  132
+    'django.contrib.sessions',
  133
+    'django.contrib.sites',
  134
+    'django.contrib.messages',
  135
+    'django.contrib.staticfiles',
  136
+    'tagging',
  137
+    'catalogs',
  138
+    'videopages',
  139
+    'djangovideos',
  140
+    'django.contrib.admin',
  141
+)
  142
+
  143
+
  144
+if TEST_RECORDER:
  145
+    RECORDER_FIXTURES = [
  146
+        'videopages/fixtures/catalogs.json',
  147
+        'videopages/fixtures/videopages.json'
  148
+    ]
  149
+    RECORDER_IGNORE = (
  150
+        '^/admin.*',
  151
+    )
  152
+
  153
+    RECORDER_AUTOLOGIN = True
  154
+    RECORDER_AUTH = {
  155
+        'username': 'admin',
  156
+        'password': '12345'
  157
+    }
  158
+    RECORDER_INIT_ON_START = False
  159
+    INSTALLED_APPS += ('testrecorder',)
  160
+
  161
+# A sample logging configuration. The only tangible logging
  162
+# performed by this configuration is to send an email to
  163
+# the site admins on every HTTP 500 error.
  164
+# See http://docs.djangoproject.com/en/dev/topics/logging for
  165
+# more details on how to customize your logging configuration.
  166
+LOGGING = {
  167
+    'version': 1,
  168
+    'disable_existing_loggers': False,
  169
+    'handlers': {
  170
+        'mail_admins': {
  171
+            'level': 'ERROR',
  172
+            'class': 'django.utils.log.AdminEmailHandler'
  173
+        }
  174
+    },
  175
+    'loggers': {
  176
+        'django.request': {
  177
+            'handlers': ['mail_admins'],
  178
+            'level': 'ERROR',
  179
+            'propagate': True,
  180
+        },
  181
+    }
  182
+}
10  demo_project/templates/base.html
... ...
@@ -0,0 +1,10 @@
  1
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2
+<html xmlns="http://www.w3.org/1999/xhtml">
  3
+<head>
  4
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5
+    <title>{% block title %}{% endblock %}</title>
  6
+</head>
  7
+<body>
  8
+{% block content %}{% endblock %}
  9
+</body>
  10
+</html>
14  demo_project/urls.py
... ...
@@ -0,0 +1,14 @@
  1
+from django.conf.urls.defaults import patterns, include, url
  2
+
  3
+# Uncomment the next two lines to enable the admin:
  4
+from django.contrib import admin
  5
+admin.autodiscover()
  6
+
  7
+urlpatterns = patterns('',
  8
+
  9
+    # Uncomment the next line to enable the admin:
  10
+    url(r'^admin/', include(admin.site.urls)),
  11
+    url(r'^catalogs/', include('catalogs.urls')),
  12
+    url(r'^videopages/', include('videopages.urls')),
  13
+    url('^videos/', include('djangovideos.urls')),
  14
+)
10  pip-requirements.txt
... ...
@@ -0,0 +1,10 @@
  1
+django>=1.3
  2
+-e git+https://github.com/RANUX/django-catalogs.git#egg=django-catalogs
  3
+django-videos
  4
+django-tagging
  5
+
  6
+# for tests
  7
+-e git+https://github.com/nose-devs/nose.git#egg=nose
  8
+django-nose
  9
+coverage
  10
+-e git+https://github.com/pydevua/django-testrecorder.git#egg=django-testrecorder
88  runtests.py
... ...
@@ -0,0 +1,88 @@
  1
+#!/usr/bin/env python
  2
+# -*- coding: UTF-8 -*-
  3
+import os
  4
+import sys
  5
+from optparse import OptionParser
  6
+
  7
+from django.conf import settings
  8
+
  9
+if not settings.configured:
  10
+    PROJECT_DIR, MODULE_NAME = os.path.split(
  11
+        (os.path.realpath(__file__))
  12
+    )
  13
+
  14
+    settings.configure(
  15
+        DATABASE_ENGINE='sqlite3',
  16
+        DATABASES={
  17
+            'default': {
  18
+                'ENGINE': 'django.db.backends.sqlite3',
  19
+                },
  20
+            },
  21
+        ROOT_URLCONF = 'videopages.urls',
  22
+        NOSE_ARGS = ['--nocapture',
  23
+                     '--all-modules',
  24
+                     '--nologcapture',
  25
+                     '--verbosity=2',
  26
+                     '--with-coverage',
  27
+                     '--cover-package=videopages',
  28
+                     '--cover-html',
  29
+                     #             '--with-doctest',
  30
+                     'videopages'
  31
+                     #             '--cover-erase',
  32
+                     #             '--cover-tests',
  33
+        ],
  34
+        TEMPLATE_CONTEXT_PROCESSORS = (
  35
+            'django.contrib.auth.context_processors.auth',
  36
+            'django.core.context_processors.debug',
  37
+            'django.core.context_processors.i18n',
  38
+            'django.core.context_processors.media',
  39
+            'django.core.context_processors.static',
  40
+            'django.core.context_processors.request',
  41
+        ),
  42
+        MIDDLEWARE_CLASSES = (
  43
+            'django.middleware.common.CommonMiddleware',
  44
+            'django.contrib.sessions.middleware.SessionMiddleware',
  45
+            'django.middleware.csrf.CsrfViewMiddleware',
  46
+            'django.contrib.auth.middleware.AuthenticationMiddleware',
  47
+            'django.contrib.messages.middleware.MessageMiddleware',
  48
+        ),
  49
+        TEMPLATE_LOADERS = (
  50
+            'django.template.loaders.filesystem.Loader',
  51
+            'django.template.loaders.app_directories.Loader',
  52
+        ),
  53
+        TEMPLATE_DIRS = (
  54
+            os.path.join(PROJECT_DIR, 'videopages', 'tests', 'templates'),
  55
+        ),
  56
+        SITE_ID = 1,
  57
+        INSTALLED_APPS=[
  58
+            'django.contrib.auth',
  59
+            'django.contrib.contenttypes',
  60
+            'django.contrib.sessions',
  61
+            'django.contrib.sites',
  62
+            'django.contrib.messages',
  63
+            'tagging',
  64
+            'catalogs',
  65
+            'videopages',
  66
+            'djangovideos',
  67
+        ],
  68
+        DEBUG=False,
  69
+    )
  70
+
  71
+
  72
+from django_nose import NoseTestSuiteRunner
  73
+
  74
+def runtests(*test_args, **kwargs):
  75
+    if not test_args:
  76
+        test_args = ['videopages']
  77
+
  78
+    test_runner = NoseTestSuiteRunner(**kwargs)
  79
+    failures = test_runner.run_tests(test_args)
  80
+    sys.exit(failures)
  81
+
  82
+if __name__ == '__main__':
  83
+    parser = OptionParser()
  84
+    parser.add_option('--verbosity', dest='verbosity', action='store', default=1, type=int)
  85
+    parser.add_options(NoseTestSuiteRunner.options)
  86
+    (options, args) = parser.parse_args()
  87
+
  88
+    runtests(*args, **options.__dict__)
4  videopages/__init__.py
... ...
@@ -0,0 +1,4 @@
  1
+# -*- coding: UTF-8 -*-
  2
+
  3
+__author__ = 'Razzhivin Alexander'
  4
+__email__ = 'admin@httpbots.com'
11  videopages/admin.py
... ...
@@ -0,0 +1,11 @@
  1
+# -*- coding: UTF-8 -*-
  2
+from django.contrib import admin
  3
+from models import VideoPage
  4
+
  5
+
  6
+__author__ = 'Razzhivin Alexander'
  7
+__email__ = 'admin@httpbots.com'
  8
+
  9
+
  10
+admin.site.register(VideoPage)
  11
+
4  videopages/conf/__init__.py
... ...
@@ -0,0 +1,4 @@
  1
+# -*- coding: UTF-8 -*-
  2
+
  3
+__author__ = 'Razzhivin Alexander'
  4
+__email__ = 'admin@httpbots.com'
10  videopages/conf/settings.py
... ...
@@ -0,0 +1,10 @@
  1
+# -*- coding: UTF-8 -*-
  2
+from django.conf import settings
  3
+
  4
+
  5
+__author__ = 'Razzhivin Alexander'
  6
+__email__ = 'admin@httpbots.com'
  7
+
  8
+
  9
+LANGUAGES = getattr(settings, 'LANGUAGES')
  10
+VIDEO_PAGES_PER_PAGE = getattr(settings, 'VIDEO_PAGES_PER_PAGE', 10)
1  videopages/fixtures/catalogs.json
... ...
@@ -0,0 +1 @@
  1
+[{"pk": 1, "model": "catalogs.catalogitem", "fields": {"name": "root", "parent": null, "deleted": false, "slug": "root", "language_code": "en", "path": "root", "last_child": null, "icon": ""}}, {"pk": 2, "model": "catalogs.catalogitem", "fields": {"name": "python lessons", "parent": 1, "deleted": false, "slug": "python-lessons", "language_code": "en", "path": "root/python-lessons", "last_child": null, "icon": ""}}]
12  videopages/fixtures/videopages.json
... ...
@@ -0,0 +1,12 @@
  1
+[
  2
+    {
  3
+        "pk":2,
  4
+        "model":"videopages.videopage",
  5
+        "fields":{
  6
+            "description":"Awesom lessons",
  7
+            "created":"2012-02-23 05:02:06",
  8
+            "modified":"2012-02-23 05:02:06",
  9
+            "author":1
  10
+        }
  11
+    }
  12
+]
29  videopages/models.py
... ...
@@ -0,0 +1,29 @@
  1
+# -*- coding: UTF-8 -*-
  2
+from catalogs.models import CatalogItem
  3
+from django.contrib.auth.models import User
  4
+from django.core.urlresolvers import reverse
  5
+from django.db import models
  6
+from django.utils.translation import ugettext_lazy as _
  7
+from tagging.fields import TagField
  8
+
  9
+__author__ = 'Razzhivin Alexander'
  10
+__email__ = 'admin@httpbots.com'
  11
+
  12
+class VideoPage(CatalogItem):
  13
+
  14
+    author = models.ForeignKey(User, related_name="videos", verbose_name=_('author'))
  15
+
  16
+    created = models.DateTimeField(_('created'), auto_now_add=True)
  17
+    modified = models.DateTimeField(_('modified'), auto_now=True)
  18
+    description = models.TextField(verbose_name=_('description'))
  19
+    tags = TagField(verbose_name=_('tags'), blank=True)
  20
+    moderated = models.BooleanField(_('moderated'), default=False)
  21
+
  22
+    class Meta:
  23
+        ordering = ['-created']
  24
+
  25
+    def __unicode__(self):
  26
+        return u'{0} - {1}'.format(self.author.username, self.slug)
  27
+
  28
+    def get_absolute_url(self):
  29
+        return reverse('videopages_page', args=[self.slug])
1  videopages/templates/videopages/base.html
... ...
@@ -0,0 +1 @@
  1
+{% extends "base.html" %}
17  videopages/templates/videopages/page.html
... ...
@@ -0,0 +1,17 @@
  1
+{% extends "videopages/base.html" %}
  2
+{% load video_tags %}
  3
+
  4
+{% block title %}{{videopage.name}}{% endblock %}
  5
+
  6
+{% block content %}
  7
+
  8
+    <h1>{{ videopage.name }}</h1>
  9
+
  10
+    {% get_videos_for videopage as "videos" %}
  11
+    {% for video in videos %}
  12
+        {% embed_video video 640x480 %}
  13
+    {% endfor %}
  14
+
  15
+    <p>{{ videopage.description }}</p>
  16
+
  17
+{% endblock %}
4  videopages/tests/__init__.py
... ...
@@ -0,0 +1,4 @@
  1
+# -*- coding: UTF-8 -*-
  2
+
  3
+__author__ = 'Razzhivin Alexander'
  4
+__email__ = 'admin@httpbots.com'
10  videopages/tests/templates/base.html
... ...
@@ -0,0 +1,10 @@
  1
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2
+<html xmlns="http://www.w3.org/1999/xhtml">
  3
+<head>
  4
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5
+    <title>{% block title %}{% endblock %}</title>
  6
+</head>
  7
+<body>
  8
+{% block content %}{% endblock %}
  9
+</body>
  10
+</html>
4  videopages/tests/views/__init__.py
... ...
@@ -0,0 +1,4 @@
  1
+# -*- coding: UTF-8 -*-
  2
+
  3
+__author__ = 'Razzhivin Alexander'
  4
+__email__ = 'admin@httpbots.com'
23  videopages/tests/views/page.py
... ...
@@ -0,0 +1,23 @@
  1
+# -*- coding: UTF-8 -*-
  2
+from django.core.urlresolvers import reverse
  3
+from django.test import TestCase
  4
+from videopages.models import VideoPage
  5
+
  6
+
  7
+__author__ = 'Razzhivin Alexander'
  8
+__email__ = 'admin@httpbots.com'
  9
+
  10
+
  11
+class VideoPageViewTestCase(TestCase):
  12
+    fixtures = [
  13
+        'catalogs.json',
  14
+        'videopages.json'
  15
+    ]
  16
+
  17
+    def test_get_page(self):
  18
+        video_page = VideoPage.objects.get(pk=2)
  19
+        url = '{0}/'.format(reverse('videopages_page', args=[video_page.slug]))
  20
+        response = self.client.get(url)
  21
+        for item in [video_page.name, video_page.description]:
  22
+            self.assertContains(response, item)
  23
+
18  videopages/urls.py
... ...
@@ -0,0 +1,18 @@
  1
+# -*- coding: UTF-8 -*-
  2
+from django.conf.urls.defaults import patterns, url
  3
+from django.contrib.auth.decorators import login_required
  4
+from videopages.views.create import create_page
  5
+from videopages.views.edit import EditVideoView
  6
+from videopages.views.list import VideoPageListView
  7
+from views.page import VideoPageView
  8
+
  9
+__author__ = 'Razzhivin Alexander'
  10
+__email__ = 'admin@httpbots.com'
  11
+
  12
+
  13
+urlpatterns = patterns('',
  14
+    url(r'^$', VideoPageListView.as_view(), name='videopages_list'),
  15
+    url(r'^create/$', login_required(create_page), name='videopages_create'),
  16
+    url(r'^edit/(?P<slug>[\w-]+)/$', login_required(EditVideoView.as_view()), name='videopages_edit'),
  17
+    url(r'^(?P<url>.*)$', VideoPageView.as_view(), name='videopages_page'),
  18
+)
4  videopages/views/__init__.py
... ...
@@ -0,0 +1,4 @@
  1
+# -*- coding: UTF-8 -*-
  2
+
  3
+__author__ = 'Razzhivin Alexander'
  4
+__email__ = 'admin@httpbots.com'
25  videopages/views/page.py
... ...
@@ -0,0 +1,25 @@
  1
+# -*- coding: UTF-8 -*-
  2
+from django.http import HttpResponseRedirect
  3
+from django.shortcuts import get_object_or_404
  4
+from django.views.generic.base import TemplateView
  5
+from videopages.models import VideoPage
  6
+
  7
+__author__ = 'Razzhivin Alexander'
  8
+__email__ = 'admin@httpbots.com'
  9
+
  10
+
  11
+class VideoPageView(TemplateView):
  12
+    template_name = 'videopages/page.html'
  13
+
  14
+
  15
+    def get(self, request, *args, **kwargs):
  16
+        url = kwargs.get('url')
  17
+
  18
+        if url:
  19
+            if not url.endswith('/'):
  20
+                return HttpResponseRedirect("%s/" % request.path)
  21
+
  22
+            slug = filter(None, url.split("/"))[-1]  # filter removes empty strings
  23
+            videopage = get_object_or_404(VideoPage, slug=slug, deleted=False)
  24
+
  25
+        return self.render_to_response({'videopage': videopage})

0 notes on commit 5e9356c

Please sign in to comment.
Something went wrong with that request. Please try again.