Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mozilla/kuma
...
head fork: mozilla/kuma
Checking mergeability… Don't worry, you can still create the pull request.
  • 8 commits
  • 29 files changed
  • 0 commit comments
  • 4 contributors
Showing with 40 additions and 2,215 deletions.
  1. +0 −4 apps/gallery/__init__.py
  2. +0 −152 apps/gallery/fixtures/gallery/media.json
  3. +0 −197 apps/gallery/forms.py
  4. +0 −67 apps/gallery/models.py
  5. +0 −66 apps/gallery/templates/gallery/confirm_media_delete.html
  6. +0 −33 apps/gallery/templates/gallery/edit_media.html
  7. +0 −65 apps/gallery/templates/gallery/gallery.html
  8. +0 −15 apps/gallery/templates/gallery/includes/media_list.html
  9. +0 −137 apps/gallery/templates/gallery/includes/upload_media_form.html
  10. +0 −83 apps/gallery/templates/gallery/media.html
  11. +0 −56 apps/gallery/templates/gallery/search.html
  12. +0 −63 apps/gallery/tests/__init__.py
  13. BIN  apps/gallery/tests/media/test.flv
  14. BIN  apps/gallery/tests/media/test.ogv
  15. BIN  apps/gallery/tests/media/test.rtf
  16. BIN  apps/gallery/tests/media/test.webm
  17. +0 −102 apps/gallery/tests/test__utils.py
  18. +0 −53 apps/gallery/tests/test_models.py
  19. +0 −167 apps/gallery/tests/test_templates.py
  20. +0 −467 apps/gallery/tests/test_views.py
  21. +0 −20 apps/gallery/urls.py
  22. +0 −99 apps/gallery/utils.py
  23. +0 −341 apps/gallery/views.py
  24. +0 −1  apps/sumo/parser.py
  25. +0 −4 apps/sumo/views.py
  26. +7 −2 apps/wiki/models.py
  27. +22 −0 apps/wiki/tests/test_models.py
  28. +11 −0 docs/installation.rst
  29. +0 −21 settings.py
View
4 apps/gallery/__init__.py
@@ -1,4 +0,0 @@
-# The number of items per page
-ITEMS_PER_PAGE = 20
-# Snowman draft
-DRAFT_TITLE_PREFIX = u'\u2603\u2603\u2603 '
View
152 apps/gallery/fixtures/gallery/media.json
@@ -1,152 +0,0 @@
-[
- {
- "pk": 1,
- "model": "gallery.image",
- "fields": {
- "updated": "2007-10-30 12:34:19",
- "description": "This image was automatically migrated.",
- "created": "2007-10-30 12:34:19",
- "locale": "en-US",
- "title": "fx2-quicktimeflash.png",
- "file": "uploads/gallery/images/fx2-quicktimeflash.png",
- "creator": 180054,
- "thumbnail": "uploads/gallery/images/thumbnails/fx2-quicktimeflash.png"
- }
- },
- {
- "pk": 2,
- "model": "gallery.image",
- "fields": {
- "updated": "2009-08-30 12:19:42",
- "description": "This image was automatically migrated.",
- "created": "2009-08-30 12:19:42",
- "locale": "en-US",
- "title": "0a85171f1802a3b0d9f46ffb997ddc02-1251659983-259-2.png",
- "file": "uploads/gallery/images/0a85171f1802a3b0d9f46ffb997ddc02-1251659983-259-2.png",
- "creator": 180054,
- "thumbnail": "uploads/gallery/images/thumbnails/0a85171f1802a3b0d9f46ffb997ddc02-1251659983-259-2.png"
- }
- },
- {
- "pk": 3,
- "model": "gallery.image",
- "fields": {
- "updated": "2009-05-28 16:19:43",
- "description": "This image was automatically migrated.",
- "created": "2009-05-28 16:19:43",
- "locale": "en-US",
- "title": "5b566c185ee0e0a9e4fbff7fab19f74f-1243552783-538-1.png",
- "file": "uploads/gallery/images/5b566c185ee0e0a9e4fbff7fab19f74f-1243552783-538-1.png",
- "creator": 180054,
- "thumbnail": "uploads/gallery/images/thumbnails/5b566c185ee0e0a9e4fbff7fab19f74f-1243552783-538-1.png"
- }
- },
- {
- "pk": 4,
- "model": "gallery.image",
- "fields": {
- "updated": "2009-10-12 14:01:31",
- "description": "This image was automatically migrated.",
- "created": "2009-10-12 14:01:31",
- "locale": "en-US",
- "title": "8fb20706da4e445395e96836f21d7890-1255381291-635-1.png",
- "file": "uploads/gallery/images/8fb20706da4e445395e96836f21d7890-1255381291-635-1.png",
- "creator": 180054,
- "thumbnail": "uploads/gallery/images/thumbnails/8fb20706da4e445395e96836f21d7890-1255381291-635-1.png"
- }
- },
- {
- "pk": 5,
- "model": "gallery.image",
- "fields": {
- "updated": "2010-07-29 11:07:56",
- "description": "This image was automatically migrated.",
- "created": "2010-07-29 11:07:56",
- "locale": "en-US",
- "title": "cbbf9711182275da24d1dcfb226ee51a-1280426876-482-1.jpg",
- "file": "uploads/gallery/images/cbbf9711182275da24d1dcfb226ee51a-1280426876-482-1.jpg",
- "creator": 180054,
- "thumbnail": "uploads/gallery/images/thumbnails/cbbf9711182275da24d1dcfb226ee51a-1280426876-482-1.jpg"
- }
- },
- {
- "pk": 1,
- "model": "gallery.video",
- "fields": {
- "updated": "2009-06-23 19:46:39",
- "ogv": "",
- "description": "This video was automatically migrated.",
- "created": "2009-06-23 19:46:39",
- "locale": "en-US",
- "title": "b66ce67d9c04f50a86b11ba5e4a2fcea-1245811599-938-0",
- "webm": "",
- "flv": "uploads/gallery/videos/b66ce67d9c04f50a86b11ba5e4a2fcea-1245811599-938-0.swf",
- "creator": 180054,
- "thumbnail": ""
- }
- },
- {
- "pk": 2,
- "model": "gallery.video",
- "fields": {
- "updated": "2009-08-15 18:45:50",
- "ogv": "uploads/gallery/videos/0c1dabb9bbec4f505cc0af87ca2fa2ea-1250387150-245-0.ogg",
- "description": "This video was automatically migrated.",
- "created": "2009-08-15 18:45:50",
- "locale": "en-US",
- "title": "0c1dabb9bbec4f505cc0af87ca2fa2ea-1250387150-245-0",
- "webm": "",
- "flv": "uploads/gallery/videos/0c1dabb9bbec4f505cc0af87ca2fa2ea-1250387150-245-0.flv",
- "creator": 180054,
- "thumbnail": ""
- }
- },
- {
- "pk": 3,
- "model": "gallery.video",
- "fields": {
- "updated": "2009-10-22 15:51:58",
- "ogv": "",
- "description": "This video was automatically migrated.",
- "created": "2009-10-22 15:51:58",
- "locale": "en-US",
- "title": "0bafa67c599b3d0a9e34e65f90610c2f-1256251919-703-0",
- "webm": "",
- "flv": "uploads/gallery/videos/0bafa67c599b3d0a9e34e65f90610c2f-1256251919-703-0.swf",
- "creator": 180054,
- "thumbnail": ""
- }
- },
- {
- "pk": 4,
- "model": "gallery.video",
- "fields": {
- "updated": "2009-06-11 18:57:41",
- "ogv": "uploads/gallery/videos/4a56e2efc975baab469d2e40fcb9cea6-1244771860-995-0.ogg",
- "description": "This video was automatically migrated.",
- "created": "2009-06-11 18:57:41",
- "locale": "en-US",
- "title": "4a56e2efc975baab469d2e40fcb9cea6-1244771860-995-0",
- "webm": "",
- "flv": "uploads/gallery/videos/4a56e2efc975baab469d2e40fcb9cea6-1244771860-995-0.flv",
- "creator": 180054,
- "thumbnail": ""
- }
- },
- {
- "pk": 5,
- "model": "gallery.video",
- "fields": {
- "updated": "2009-07-09 20:18:20",
- "ogv": "uploads/gallery/videos/c6db1a7b7a335c7fd6d26cdc3fbdbf06-1247195900-992-0.ogg",
- "description": "This video was automatically migrated.",
- "created": "2009-07-09 20:18:20",
- "locale": "en-US",
- "title": "c6db1a7b7a335c7fd6d26cdc3fbd1802-1247195900-992-0",
- "webm": "",
- "flv": "uploads/gallery/videos/c6db1a7b7a335c7fd6d26cdc3fbdbf06-1247195900-992-0.flv",
- "creator": 180054,
- "thumbnail": ""
- }
- }
-]
View
197 apps/gallery/forms.py
@@ -1,197 +0,0 @@
-from django import forms
-from django.conf import settings
-from django.core.exceptions import ValidationError
-
-from tower import ugettext_lazy as _lazy
-
-from gallery import DRAFT_TITLE_PREFIX
-from gallery.models import Image, Video
-from sumo.form_fields import StrippedCharField
-from sumo_locales import LOCALES
-from upload.forms import clean_image_extension
-
-# Error messages
-MSG_TITLE_REQUIRED = _lazy(u'Please provide a title.')
-MSG_TITLE_SHORT = _lazy(
- u'The title is too short (%(show_value)s characters). It must be at '
- 'least %(limit_value)s characters.')
-MSG_TITLE_LONG = _lazy(
- u'Please keep the length of your title to %(limit_value)s characters '
- 'or less. It is currently %(show_value)s characters.')
-MSG_DESCRIPTION_REQUIRED = _lazy(u'Please provide a description.')
-MSG_DESCRIPTION_LONG = _lazy(
- u'Please keep the length of your description to %(limit_value)s '
- 'characters or less. It is currently %(show_value)s characters.')
-MSG_IMAGE_REQUIRED = _lazy(u'You have not selected an image to upload.')
-MSG_IMAGE_LONG = _lazy(
- u'Please keep the length of your image filename to %(max)s '
- 'characters or less. It is currently %(length)s characters.')
-MSG_WEBM_LONG = _lazy(
- u'Please keep the length of your webm filename to %(max)s '
- 'characters or less. It is currently %(length)s characters.')
-MSG_OGV_LONG = _lazy(
- u'Please keep the length of your ogv filename to %(max)s '
- 'characters or less. It is currently %(length)s characters.')
-MSG_FLV_LONG = _lazy(
- u'Please keep the length of your flv filename to %(max)s '
- 'characters or less. It is currently %(length)s characters.')
-MSG_VID_REQUIRED = _lazy(
- u'The video has no files associated with it. You must upload one of the '
- 'following extensions: webm, ogv, flv.')
-MSG_TITLE_DRAFT = _lazy(u'Please select a different title.')
-
-TITLE_HELP_TEXT = _lazy(u'Include this in wiki syntax with [[%(type)s:title]]')
-DESCRIPTION_HELP_TEXT = _lazy(u'Provide a brief description of this media.')
-
-
-class ImageUploadFormAsync(forms.Form):
- """Image upload form for async requests."""
- file = forms.ImageField(error_messages={'required': MSG_IMAGE_REQUIRED,
- 'max_length': MSG_IMAGE_LONG},
- max_length=settings.MAX_FILENAME_LENGTH)
-
- def clean(self):
- c = super(ImageUploadFormAsync, self).clean()
- clean_image_extension(c.get('file'))
- return c
-
-
-class ImageForm(forms.ModelForm):
- """Image form."""
- file = forms.ImageField(error_messages={'required': MSG_IMAGE_REQUIRED,
- 'max_length': MSG_IMAGE_LONG},
- max_length=settings.MAX_FILENAME_LENGTH)
- locale = forms.ChoiceField(
- label=_lazy(u'Locale'),
- choices=[(k, LOCALES[k].native) for
- k in settings.SUMO_LANGUAGES],
- initial=settings.WIKI_DEFAULT_LANGUAGE)
- title = StrippedCharField(
- label=_lazy(u'Title'),
- help_text=TITLE_HELP_TEXT % {'type': u'Image'},
- min_length=5, max_length=255,
- error_messages={'required': MSG_TITLE_REQUIRED,
- 'min_length': MSG_TITLE_SHORT,
- 'max_length': MSG_TITLE_LONG})
- description = StrippedCharField(
- label=_lazy(u'Description'),
- help_text=DESCRIPTION_HELP_TEXT,
- max_length=10000, widget=forms.Textarea(),
- error_messages={'required': MSG_DESCRIPTION_REQUIRED,
- 'max_length': MSG_DESCRIPTION_LONG})
-
- def clean(self):
- c = super(ImageForm, self).clean()
- c = clean_draft(self, c)
- clean_image_extension(c.get('file'))
- return c
-
- def save(self, update_user=None, **kwargs):
- return save_form(self, update_user, **kwargs)
-
- class Meta:
- model = Image
- fields = ('file', 'locale', 'title', 'description')
-
-
-class VideoUploadFormAsync(forms.ModelForm):
- """Video upload form for async requests."""
- flv = forms.FileField(required=False,
- error_messages={'max_length': MSG_FLV_LONG},
- max_length=settings.MAX_FILENAME_LENGTH)
- ogv = forms.FileField(required=False,
- error_messages={'max_length': MSG_OGV_LONG},
- max_length=settings.MAX_FILENAME_LENGTH)
- webm = forms.FileField(required=False,
- error_messages={'max_length': MSG_WEBM_LONG},
- max_length=settings.MAX_FILENAME_LENGTH)
- thumbnail = forms.ImageField(required=False,
- error_messages={'max_length': MSG_IMAGE_LONG},
- max_length=settings.MAX_FILENAME_LENGTH)
-
- def clean(self):
- c = super(VideoUploadFormAsync, self).clean()
- if not ('webm' in c and c['webm'] and
- c['webm'].name.endswith('.webm') or
- 'ogv' in c and c['ogv'] and
- (c['ogv'].name.endswith('.ogv') or
- c['ogv'].name.endswith('.ogg')) or
- 'flv' in c and c['flv'] and c['flv'].name.endswith('.flv') or
- 'thumbnail' in c and c['thumbnail']):
- raise ValidationError(MSG_VID_REQUIRED)
- clean_image_extension(c.get('thumbnail'))
- return c
-
- class Meta:
- model = Video
- fields = ('webm', 'ogv', 'flv', 'thumbnail')
-
-
-class VideoForm(forms.ModelForm):
- """Video form."""
- flv = forms.FileField(required=False,
- error_messages={'max_length': MSG_FLV_LONG},
- max_length=settings.MAX_FILENAME_LENGTH)
- ogv = forms.FileField(required=False,
- error_messages={'max_length': MSG_OGV_LONG},
- max_length=settings.MAX_FILENAME_LENGTH)
- webm = forms.FileField(required=False,
- error_messages={'max_length': MSG_WEBM_LONG},
- max_length=settings.MAX_FILENAME_LENGTH)
- thumbnail = forms.ImageField(required=False,
- error_messages={'max_length': MSG_IMAGE_LONG},
- max_length=settings.MAX_FILENAME_LENGTH)
- locale = forms.ChoiceField(
- label=_lazy(u'Locale'),
- choices=[(k, LOCALES[k].native) for
- k in settings.SUMO_LANGUAGES],
- initial=settings.WIKI_DEFAULT_LANGUAGE)
- title = StrippedCharField(
- label=_lazy(u'Title'),
- help_text=TITLE_HELP_TEXT % {'type': u'Video'},
- min_length=5, max_length=255,
- error_messages={'required': MSG_TITLE_REQUIRED,
- 'min_length': MSG_TITLE_SHORT,
- 'max_length': MSG_TITLE_LONG})
- description = StrippedCharField(
- label=_lazy(u'Description'),
- help_text=DESCRIPTION_HELP_TEXT,
- max_length=10000, widget=forms.Textarea(),
- error_messages={'required': MSG_DESCRIPTION_REQUIRED,
- 'max_length': MSG_DESCRIPTION_LONG})
-
- def clean(self):
- """Ensure one of the supported file formats has been uploaded"""
- c = super(VideoForm, self).clean()
- if not ('webm' in c and c['webm'] or
- 'ogv' in c and c['ogv'] or
- 'flv' in c and c['flv']):
- raise ValidationError(MSG_VID_REQUIRED)
- clean_draft(self, c)
- clean_image_extension(c.get('thumbnail'))
- return self.cleaned_data
-
- def save(self, update_user=None, **kwargs):
- return save_form(self, update_user, **kwargs)
-
- class Meta:
- model = Video
- fields = ('webm', 'ogv', 'flv', 'thumbnail', 'locale',
- 'title', 'description')
-
-
-def clean_draft(form, cleaned_data):
- """Drafts reserve a special title."""
- c = cleaned_data
- if 'title' in c and c['title'].startswith(DRAFT_TITLE_PREFIX):
- raise ValidationError(MSG_TITLE_DRAFT)
- return c
-
-
-def save_form(form, update_user=None, **kwargs):
- """Save a media form, add user to updated_by."""
- obj = super(form.__class__, form).save(commit=False, **kwargs)
- if update_user:
- obj.updated_by = update_user
- obj.save()
- return obj
View
67 apps/gallery/models.py
@@ -1,67 +0,0 @@
-from datetime import datetime
-
-from django.conf import settings
-from django.contrib.auth.models import User
-from django.db import models
-
-from sumo.models import ModelBase, LocaleField
-from sumo.urlresolvers import reverse
-
-
-class Media(ModelBase):
- """Generic model for media"""
- title = models.CharField(max_length=255, db_index=True)
- created = models.DateTimeField(default=datetime.now, db_index=True)
- updated = models.DateTimeField(default=datetime.now, db_index=True)
- updated_by = models.ForeignKey(User, null=True)
- description = models.TextField(max_length=10000)
- locale = LocaleField(default=settings.GALLERY_DEFAULT_LANGUAGE,
- db_index=True)
-
- class Meta:
- abstract = True
- ordering = ['-created']
- unique_together = ('locale', 'title')
-
- def __unicode__(self):
- return '[%s] %s' % (self.locale, self.title)
-
-
-class Image(Media):
- creator = models.ForeignKey(User, related_name='gallery_images')
- file = models.ImageField(upload_to=settings.GALLERY_IMAGE_PATH,
- max_length=settings.MAX_FILEPATH_LENGTH)
- thumbnail = models.ImageField(
- upload_to=settings.GALLERY_IMAGE_THUMBNAIL_PATH, null=True,
- max_length=settings.MAX_FILEPATH_LENGTH)
-
- def get_absolute_url(self):
- return reverse('gallery.media', args=['image', self.id])
-
- def thumbnail_url_if_set(self):
- """Returns self.thumbnail, if set, else self.file"""
- return self.thumbnail.url if self.thumbnail else self.file.url
-
-
-class Video(Media):
- creator = models.ForeignKey(User, related_name='gallery_videos')
- webm = models.FileField(upload_to=settings.GALLERY_VIDEO_PATH, null=True,
- max_length=settings.MAX_FILEPATH_LENGTH)
- ogv = models.FileField(upload_to=settings.GALLERY_VIDEO_PATH, null=True,
- max_length=settings.MAX_FILEPATH_LENGTH)
- flv = models.FileField(upload_to=settings.GALLERY_VIDEO_PATH, null=True,
- max_length=settings.MAX_FILEPATH_LENGTH)
- poster = models.ImageField(upload_to=settings.GALLERY_VIDEO_THUMBNAIL_PATH,
- max_length=settings.MAX_FILEPATH_LENGTH,
- null=True)
- thumbnail = models.ImageField(
- upload_to=settings.GALLERY_VIDEO_THUMBNAIL_PATH, null=True,
- max_length=settings.MAX_FILEPATH_LENGTH)
-
- def get_absolute_url(self):
- return reverse('gallery.media', args=['video', self.id])
-
- def thumbnail_url_if_set(self):
- """Returns self.thumbnail.url, if set, else default thumbnail URL"""
- progress_url = settings.GALLERY_VIDEO_THUMBNAIL_PROGRESS_URL
- return self.thumbnail.url if self.thumbnail else progress_url
View
66 apps/gallery/templates/gallery/confirm_media_delete.html
@@ -1,66 +0,0 @@
-{# vim: set ts=2 et sts=2 sw=2: #}
-{% extends "gallery/media.html" %}
-{% if media_type == 'image' %}
- {% set delete_this = _('Delete image') %}
- {% set delete_confirm = _('Are you sure you want to delete this image?') %}
- {% set delete_warning = _('You are about to permanently delete this image. <strong>This cannot be undone!</strong> Are you sure you want to continue?') %}
- {% set title = _('Delete image | {t} | Media Gallery')|f(t=media.title) %}
-{% else %}
- {% set delete_this = _('Delete video') %}
- {% set delete_confirm = _('Are you sure you want to delete this video?') %}
- {% set delete_warning = _('You are about to permanently delete this video. <strong>This cannot be undone!</strong> Are you sure you want to continue?') %}
- {% set title = _('Delete video | {t} | Media Gallery')|f(t=media.title) %}
-{% endif %}
-{% set crumbs = [(url('gallery.gallery', media_type), _('Media Gallery')),
- (url('gallery.media', media_type, media.id), media.title),
- (None, delete_this)] %}
-
-{% block content %}
- <article id="media-object-delete" class="main">
- <h1>{{ delete_confirm }}</h1>
- <div class="to-delete">
- <label>{{ _('Title') }}</label>
- <div>{{ media.title }}</div>
- <label>{{ _('Locale') }}</label>
- <div>{{ settings.LOCALES[media.locale].native }}</div>
- <label>{{ _('Description') }}</label>
- <div>{{ media.description|wiki_to_html }}</div>
- <label>{{ _('Creator') }}</label>
- <div>{{ media.creator }}</div>
- <label>{{ _('Date') }}</label>
- <div>{{ datetimeformat(media.created, format='longdatetime') }}</div>
- {% if media_type == 'video' %}
- <label>{{ _('Available formats') }}</label>
- <div>
- <ul>
- {% if media.flv %}
- <li>FLV</li>
- {% endif %}
- {% if media.ogv %}
- <li>OGV</li>
- {% endif %}
- {% if media.webm %}
- <li>WEBM</li>
- {% endif %}
- </ul>
- </div>
- <label class="clear">{{ _('Video') }}</label>
- <div>{{ generate_video(media) }}</div>
- {% else %}
- <label>{{ _('Available formats') }}</label>
- <div>{{ media_format|upper }}</div>
- <label>{{ _('Image') }}</label>
- <div><img src="{{ media.file.url }}" alt="{{ media.title }}" /></div>
- {% endif %}
-
- <form action="{{ url('gallery.delete_media', media_type, media.id) }}" method="post">
- {{ csrf() }}
- <p>{{ delete_warning|safe }}</p>
- <div class="form-actions">
- <a href="{{ url('gallery.media', media_type, media.id) }}">{{ _('Cancel') }}</a>
- <input type="submit" class="btn" value="{{ delete_this }}" />
- </div>
- </form>
- </div>
- </article>
-{% endblock %}
View
33 apps/gallery/templates/gallery/edit_media.html
@@ -1,33 +0,0 @@
-{# vim: set ts=2 et sts=2 sw=2: #}
-{% extends "gallery/media.html" %}
-{% from "layout/errorlist.html" import errorlist %}
-{% if media_type == 'image' %}
- {% set edit_this = _('Edit image') %}
- {% set save_this = _('Save image') %}
- {% set title = _('Edit image | {t} | Media Gallery')|f(t=media.title) %}
-{% else %}
- {% set edit_this = _('Edit video') %}
- {% set save_this = _('Save video') %}
- {% set title = _('Edit video | {t} | Media Gallery')|f(t=media.title) %}
-{% endif %}
-{% set crumbs = [(url('gallery.gallery', media_type), _('Media Gallery')),
- (url('gallery.media', media_type, media.id), media.title),
- (None, edit_this)] %}
-
-{% block content %}
- <article id="media-object-edit" class="main">
- <h1>{{ media.title }}</h1>
- <form action="{{ url('gallery.edit_media', media_type, media.id) }}" method="post">
- {{ csrf() }}
- {{ errorlist(form) }}
- <div class="form-item description">
- {{ form.description.label_tag()|safe }}
- {{ form.description|safe }}
- </div>
- <div class="form-actions form-item">
- <a href="{{ url('gallery.media', media_type, media.id) }}">{{ _('Cancel') }}</a>
- <input type="submit" class="btn" value="{{ save_this }}" />
- </div>
- </form>
- </article>
-{% endblock %}
View
65 apps/gallery/templates/gallery/gallery.html
@@ -1,65 +0,0 @@
-{# vim: set ts=2 et sts=2 sw=2: #}
-{% extends "base.html" %}
-{% set title = _('Media Gallery') %}
-{% set styles = ('wiki', 'gallery') %}
-{% set scripts = ('wiki', 'gallery') %}
-{% set crumbs = [(None, _('Media Gallery'))] %}
-
-{% block content %}
- <article id="gallery-list" class="main">
- <h1>{{ _('Media Gallery') }}</h1>
- <div id="locale-filter">
- {% if user.is_authenticated() %}
- <a id="btn-upload" class="btn-upload" href="#">{{ _('Upload a New Media File') }}</a>
- {% endif %}
- <form action="" method="get">
- <label for="select-locale">{{ _('Show media for:') }}</label>
- <select id="select-locale" name="lang" class="autosubmit">
- {% for lang in settings.LANGUAGE_CHOICES %}
- <option value="{{ lang[0] }}" {% if lang[0] == request.locale %}selected="selected"{% endif %}>{{ lang[1] }} ({{ lang[0] }})</option>
- {% endfor %}
- </select>
- <noscript>
- <input type="submit" value="{{ _('Go') }}">
- {% if user.is_authenticated() %}
- <div>{{ _('You have JavaScript disabled. Please enable JavaScript to upload files.') }}</div>
- {% endif %}
- </noscript>
- </form>
- </div>
- <div id="search-filter">
- <div id="media-type-filter">
- <span>{{ _("Show:") }}</span>
- <ol>
- <li>
- {% if media_type == 'image' %}
- <span>{{ _('Images') }}</span>
- {% else %}
- <a href="{{ url('gallery.gallery', 'image') }}">{{ _('Images') }}</a>
- {% endif %}
- </li>
- <li>
- {% if media_type == 'video' %}
- <span>{{ _('Videos') }}</span>
- {% else %}
- <a href="{{ url('gallery.gallery', 'video') }}">{{ _('Videos') }}</a>
- {% endif %}
- </li>
- </ol>
- </div>
- <div id="gallery-search">
- <form action="{{ url('gallery.search', media_type=media_type) }}" method="get">
- <input type="text" name="q" required="required" />
- <input type="submit" value="{{ _('Search Gallery') }}">
- </form>
- </div>
- </div>
- {% with media_list=media %}
- {% include 'gallery/includes/media_list.html' %}
- {% endwith %}
-
- {% if user.is_authenticated() %}
- {% include 'gallery/includes/upload_media_form.html' %}
- {% endif %}
- </article>
-{% endblock %}
View
15 apps/gallery/templates/gallery/includes/media_list.html
@@ -1,15 +0,0 @@
-{# vim: set ts=2 et sts=2 sw=2: #}
-{% if media_list.object_list %}
- <ol id="media-list">
- {% for m in media_list.object_list %}
- <li>
- <a href="{{ m.get_absolute_url() }}" title="{{ m.title }}">
- <img src="{{ m.thumbnail_url_if_set() }}" alt="{{ m.title }}" />
- </a>
- </li>
- {% endfor %}
- </ol>
- {{ media_list|paginator }}
-{% else %}
- <p>{{ _('No media files found.') }}</p>
-{% endif %}
View
137 apps/gallery/templates/gallery/includes/upload_media_form.html
@@ -1,137 +0,0 @@
-{# vim: set ts=2 et sts=2 sw=2: #}
-{% from "layout/errorlist.html" import errorlist %}
-{% if image_form.instance.pk %}
- {% set current_form = image_form %}
-{% else %}
- {% set current_form = video_form %}
-{% endif %}
-<div id="gallery-upload-modal" class="kbox" title="{% if current_form.instance.pk %}{{ _('Continue Uploading Media') }}{% else %}{{ _('Upload a New Media File') }}{% endif %}" data-modal="true" data-target="#btn-upload" data-id="upload-kbox" data-position="none">
- <form id="gallery-upload-type" action="" method="post"{% if current_form.instance.pk %} class="draft"{% endif %}>
- <label class="row-left upload-type">{{ _('Upload') }}</label>
- <div class="row-right upload-type">
- <label><input type="radio" name="upload-type" value="image" checked="checked"> {{ _('Image') }}</label>
- <label><input type="radio" name="upload-type" value="video"> {{ _('Video') }}</label>
- </div>
- </form>
- <form id="gallery-upload-image" class="upload-form {% if image_form.instance.pk %}draft{% endif %}"
- data-post-url="{{ url('gallery.upload_async', media_type='image') }}"
- method="post" enctype="multipart/form-data"
- action="{{ url('gallery.upload', media_type='image') }}">
- {{ csrf() }}
- {{ errorlist(image_form) }}
- <label for="id_file" class="row-left upload-media file">{{ _('Image') }}</label>
- <div class="row-right upload-media file">
- <label for="id_file">{{ _('Select an image file to upload.') }}</label>
- {{ image_form['file']|safe }}
- <div class="details">{{ _('Accepted formats include: PNG, JPEG, GIF. <a target="_blank" href="{learn_more}">Learn more...</a>')|fe(learn_more='http://infohost.nmt.edu/tcc/help/pubs/pil/formats.html') }}</div>
- </div>
- <label class="row-left progress file">{{ _('Progress') }}</label>
- <div class="row-right progress file">
- <span></span>
- <a href="{{ url('gallery.gallery', media_type=media_type) }}">{{ _('Cancel') }}</a>
- </div>
- <label class="row-left preview">{{ _('Preview') }}</label>
- <div class="row-right preview">
- {% if image_form.instance.pk %}
- <div class="image-preview file">
- <img src="{{ image_form.instance.thumbnail_url_if_set() }}">
- </div>
- <input type="submit" name="cancel" class="draft link-btn" data-name="file" data-action="{{ url('gallery.cancel_draft', media_type='image') }}" value="{{ _('Delete this image') }}">
- {% endif %}
- </div>
- {% for field in current_form if field.name in ('title', 'locale', 'description') %}
- <label class="row-left metadata" for="id_{{ field.name }}">{{ field.label }}</label>
- <div class="row-right metadata">
- {% if field.help_text %}
- <div class="details">{{ field.help_text }}</div>
- {% endif %}
- {{ field|safe }}
- </div>
- {% endfor %}
- <div class="upload-action">
- <input type="submit" name="upload" value="{{ _('Submit file') }}">
- <input type="submit" name="cancel" class="kbox-cancel link-btn{% if image_form.instance.pk %} draft{% endif %}" data-action="{{ url('gallery.cancel_draft', media_type='image') }}" value="{{ _('Cancel') }}">
- </div>
- </form>
- <form id="gallery-upload-video" class="upload-form {% if video_form.instance.pk %}draft{% endif %} {% if video_form.instance.pk %}errors{% endif %}"
- data-post-url="{{ url('gallery.upload_async', media_type='video') }}"
- method="post" enctype="multipart/form-data"
- action="{{ url('gallery.upload', media_type='video') }}">
- {{ csrf() }}
- {{ errorlist(video_form) }}
- <label class="row-left upload-media" for="id_flv">{{ _('Video') }}</label>
- <div class="row-right upload-media flv">
- <label for="id_flv">{{ _('Select a Flash video (FLV) to upload.') }}</label>
- {{ video_form['flv']|safe }}
- <div class="details">{{ _('Please no SWFs, only FLVs.') }}</div>
- </div>
- <div class="row-right upload-media ogv">
- <label for="id_ogv">{{ _('Select an Ogv video to upload.') }}</label>
- {{ video_form['ogv']|safe }}
- </div>
- <div class="row-right upload-media webm">
- <label for="id_webm">{{ _('Select a WebM video to upload.') }}</label>
- {{ video_form['webm']|safe }}
- </div>
- <label class="row-left progress flv ogv webm">{{ _('Progress') }}</label>
- <div class="row-right progress flv">
- <span></span>
- <a href="{{ url('gallery.gallery', media_type=media_type) }}">{{ _('Cancel') }}</a>
- </div>
- <div class="row-right progress ogv">
- <span></span>
- <a href="{{ url('gallery.gallery', media_type=media_type) }}">{{ _('Cancel') }}</a>
- </div>
- <div class="row-right progress webm">
- <span></span>
- <a href="{{ url('gallery.gallery', media_type=media_type) }}">{{ _('Cancel') }}</a>
- </div>
- <label class="row-left preview">{{ _('Preview') }}</label>
- <div class="row-right preview">
- <ul>
- {% if video_form.instance.pk %}
- {% if video_form.instance.flv %}
- <li class="video-preview flv">
- {{ video_form.instance.flv.name.rsplit('/', 1)[-1] }}
- <input type="submit" name="cancel" class="draft link-btn" data-name="flv" data-action="{{ url('gallery.cancel_draft', media_type='video')|urlparams(field='flv') }}" value="{{ _('Delete {format} file')|fe(format='flv') }}">
- </li>
- {% endif %}
- {% if video_form.instance.ogv %}
- <li class="video-preview ogv">
- {{ video_form.instance.ogv.name.rsplit('/', 1)[-1] }}
- <input type="submit" name="cancel" class="draft link-btn" data-name="ogv" data-action="{{ url('gallery.cancel_draft', media_type='video')|urlparams(field='ogv') }}" value="{{ _('Delete {format} file')|fe(format='ogv') }}">
- </li>
- {% endif %}
- {% if video_form.instance.webm %}
- <li class="video-preview webm">
- {{ video_form.instance.webm.name.rsplit('/', 1)[-1] }}
- <input type="submit" name="cancel" class="draft kbox-cancel link-btn" data-name="webm" data-action="{{ url('gallery.cancel_draft', media_type='video')|urlparams(field='webm') }}" value="{{ _('Delete {format} file')|fe(format='webm') }}">
- </li>
- {% endif %}
- {% endif %}
- </ul>
- </div>
- <label class="row-left progress thumbnail">{{ _('Progress') }}</label>
- <div class="row-right progress thumbnail">
- <span></span>
- <a href="{{ url('gallery.gallery', media_type=media_type) }}">{{ _('Cancel') }}</a>
- </div>
- <label class="row-left upload-media thumbnail">{{ _('Thumbnail') }}</label>
- <div class="row-right upload-media thumbnail">
- {% if video_form.instance.thumbnail %}
- <div class="image-preview">
- <img src="{{ video_form.instance.thumbnail.url }}"/>
- </div>
- <input type="submit" name="cancel" class="draft link-btn" data-name="thumbnail" data-action="{{ url('gallery.cancel_draft', media_type='video')|urlparams(field='thumbnail') }}" value="{{ _('Delete thumbnail') }}">
- {% endif %}
- <label for="id_thumbnail">{{ _('Upload a thumbnail for your video. Suggested size: {width}x{height}px')|f(width=settings.THUMBNAIL_SIZE, height=settings.THUMBNAIL_SIZE) }}</label>
- {{ video_form['thumbnail']|safe }}
- </div>
- <div class="upload-action">
- <input type="submit" name="upload" value="{{ _('Submit file') }}">
- <input class="kbox-cancel link-btn{% if video_form.instance.pk %} draft{% endif %}"
- data-action="{{ url('gallery.cancel_draft', media_type='video')}}"
- name="cancel" type="submit" value="{{ _('Cancel') }}">
- </div>
- </form>
-</div>
View
83 apps/gallery/templates/gallery/media.html
@@ -1,83 +0,0 @@
-{# vim: set ts=2 et sts=2 sw=2: #}
-{% extends "base.html" %}
-{% if not title %}
- {% set title = _('{title} | Media Gallery')|f(title=media.title) %}
-{% endif %}
-{% set styles = ('gallery',) %}
-{% set scripts = ('wiki',) %}
-{% if not crumbs %}
- {% set crumbs = [(url('gallery.gallery', media_type), _('Media Gallery')),
- (None, media.title)] %}
-{% endif %}
-{% if media_type == 'image' %}
- {% set delete_this = _('Delete this image') %}
- {% set edit_this = _('Edit this image') %}
-{% else %}
- {% set delete_this = _('Delete this video') %}
- {% set edit_this = _('Edit this video') %}
-{% endif %}
-
-{% block content %}
- <article id="media-object" class="main">
- <h1>{{ media.title|truncate(length=55, killwords=True) }}</h1>
- {% if user.is_authenticated() %}
- <a id="btn-upload" class="btn-upload" href="{{ url('gallery.gallery', media_type)|urlparams(hash='upload') }}">{{ _('Upload a New Media File') }}</a>
- {% endif %}
- <div id="media-metainfo">
- <ul id="media-info">
- {% if media_type =='image' %}
- <li class="dimensions">
- {{ media.file.width }} x {{ media.file.height }} px
- </li>
- <li class="size">
- {{ media.file.size // 1024 }} KB
- </li>
- {% else %}{# video #}
- {% if media.flv %}
- <li class="format-flv">
- FLV ({{ media.flv.size // 1024 }} KB)
- </li>
- {% endif %}
- {% if media.ogv %}
- <li class="format-ogv">
- OGV ({{ media.ogv.size // 1024 }} KB)
- </li>
- {% endif %}
- {% if media.webm %}
- <li class="format-webm">
- WEBM ({{ media.webm.size // 1024 }} KB)
- </li>
- {% endif %}
- {% endif %}
- {% if media_format %}
- <li class="format">{{ media_format|upper }}</li>
- {% endif %}
- </ul>
- <ul id="media-meta">
- <li class="creator">{{ _('by {user}')|f(user=media.creator) }}</li>
- <li class="created">{{ _('Uploaded {date}')|fe(date=datetimeformat(media.created, format='datetime')) }}</li>
- <li class="locale">{{ settings.LANGUAGES[media.locale.lower()] }}</li>
- </ul>
- </div>
- <div id="media-view">
- {% if media_type == 'image' %}
- <img src="{{ media.file.url }}" alt="{{ media.title }}" />
- {% else %}
- {{ generate_video(media) }}
- {% endif %}
- </div>
- <div class="description">{{ media.description|wiki_to_html }}</div>
- <form id="media-actions" action="{{ url('gallery.delete_media', media_type, media.pk) }}" method="GET">
- {% if user == media.creator or
- (media_type == 'image' and user.has_perm('gallery.delete_image')) or
- (media_type == 'video' and user.has_perm('gallery.delete_video')) %}
- <input type="submit" value="{{ delete_this }}" />
- {% endif %}
- {% if user == media.creator or
- (media_type == 'image' and user.has_perm('gallery.change_image')) or
- (media_type == 'video' and user.has_perm('gallery.change_video')) %}
- <a href="{{ url('gallery.edit_media', media_type, media.id) }}">{{ edit_this }}</a>
- {% endif %}
- </form>
- </article>
-{% endblock %}
View
56 apps/gallery/templates/gallery/search.html
@@ -1,56 +0,0 @@
-{# vim: set ts=2 et sts=2 sw=2: #}
-{% extends "base.html" %}
-{% set title = _('Media Gallery Search') %}
-{% set styles= ('gallery',) %}
-{% set scripts = ('wiki',) %}
-{% set crumbs = [(url('gallery.gallery', media_type), _('Media Gallery')),
- (None, _('Search'))] %}
-
-{% block content %}
- <article id="gallery-list" class="main">
- <h1>{{ _('Media Gallery') }}</h1>
- <div id="locale-filter">
- <form action="" method="get">
- <label for="select-locale">{{ _('Show media for:') }}</label>
- <select id="select-locale" name="lang" class="autosubmit">
- {% for lang in settings.LANGUAGE_CHOICES %}
- <option value="{{ lang[0] }}" {% if lang[0] == request.locale %}selected="selected"{% endif %}>{{ lang[1] }} ({{ lang[0] }})</option>
- {% endfor %}
- </select>
- <noscript>
- <input type="submit" value="{{ _('Go') }}">
- </noscript>
- </form>
- </div>
- <div id="search-filter">
- <div id="media-type-filter">
- <span>{{ _("Show:") }}</span>
- <ol>
- <li>
- {% if media_type == 'image' %}
- <span>{{ _('Images') }}</span>
- {% else %}
- <a href="{{ url('gallery.search', 'image')|urlparams(q=q) }}">{{ _('Images') }}</a>
- {% endif %}
- </li>
- <li>
- {% if media_type == 'video' %}
- <span>{{ _('Videos') }}</span>
- {% else %}
- <a href="{{ url('gallery.search', 'video')|urlparams(q=q) }}">{{ _('Videos') }}</a>
- {% endif %}
- </li>
- </ol>
- </div>
- <div id="gallery-search">
- <form action="{{ url('gallery.search', media_type) }}" method="get">
- <input type="text" name="q" value="{{ q }}" required="required" />
- <input type="submit" value="{{ _('Search Gallery') }}">
- </form>
- </div>
- </div>
- {% with media_list=media %}
- {% include 'gallery/includes/media_list.html' %}
- {% endwith %}
- </article>
-{% endblock %}
View
63 apps/gallery/tests/__init__.py
@@ -1,63 +0,0 @@
-from django.core.files import File
-
-from gallery.models import Image, Video
-from sumo.tests import get_user
-
-
-def image(file_and_save=True, **kwargs):
- """Return a saved image.
-
- Requires a users fixture if no creator is provided.
-
- """
- u = None
- if 'creator' not in kwargs:
- u = get_user()
-
- defaults = {'title': 'Some title', 'description': 'Some description',
- 'creator': u}
- defaults.update(kwargs)
-
- img = Image(**defaults)
- if not file_and_save:
- return img
-
- if 'file' not in kwargs:
- with open('apps/upload/tests/media/test.jpg') as f:
- up_file = File(f)
- img.file.save(up_file.name, up_file, save=True)
-
- return img
-
-
-def video(file_and_save=True, **kwargs):
- """Return a saved video.
-
- Requires a users fixture if no creator is provided.
-
- """
- u = None
- if 'creator' not in kwargs:
- u = get_user()
-
- defaults = {'title': 'Some title', 'description': 'Some description',
- 'creator': u}
- defaults.update(kwargs)
-
- vid = Video(**defaults)
- if not file_and_save:
- return vid
-
- if 'file' not in kwargs:
- with open('apps/gallery/tests/media/test.webm') as f:
- up_file = File(f)
- vid.webm.save(up_file.name, up_file, save=False)
- with open('apps/gallery/tests/media/test.ogv') as f:
- up_file = File(f)
- vid.ogv.save(up_file.name, up_file, save=False)
- with open('apps/gallery/tests/media/test.flv') as f:
- up_file = File(f)
- vid.flv.save(up_file.name, up_file, save=False)
- vid.save()
-
- return vid
View
BIN  apps/gallery/tests/media/test.flv
Binary file not shown
View
BIN  apps/gallery/tests/media/test.ogv
Binary file not shown
View
BIN  apps/gallery/tests/media/test.rtf
Binary file not shown
View
BIN  apps/gallery/tests/media/test.webm
Binary file not shown
View
102 apps/gallery/tests/test__utils.py
@@ -1,102 +0,0 @@
-from django.conf import settings
-from django.contrib.auth.models import User
-from django.core.exceptions import PermissionDenied
-from django.core.files import File
-
-from gallery.models import Image, Video
-from gallery.tests import image, video
-from gallery.utils import create_image, create_video, check_media_permissions
-from sumo.tests import TestCase
-from sumo.urlresolvers import reverse
-from upload.tests import check_file_info
-
-
-class CheckPermissionsTestCase(TestCase):
- fixtures = ['users.json']
-
- def setUp(self):
- super(CheckPermissionsTestCase, self).setUp()
- self.user = User.objects.get(username='tagger')
-
- def tearDown(self):
- Image.objects.all().delete()
- Video.objects.all().delete()
- super(CheckPermissionsTestCase, self).tearDown()
-
- def test_check_own_object(self):
- """tagger can edit a video s/he doesn't own."""
- vid = video(creator=self.user)
- check_media_permissions(vid, self.user, 'change')
-
- def test_check_not_own_object(self):
- """tagger cannot delete an image s/he doesn't own."""
- img = image()
- fn = lambda: check_media_permissions(img, self.user, 'delete')
- self.assertRaises(PermissionDenied, fn)
-
- def test_check_has_perm(self):
- """Admin has perm to change video."""
- u = User.objects.get(username='admin')
- vid = video(creator=u)
- check_media_permissions(vid, u, 'change')
-
-
-class CreateImageTestCase(TestCase):
- fixtures = ['users.json']
-
- def setUp(self):
- super(CreateImageTestCase, self).setUp()
- self.user = User.objects.all()[0]
-
- def tearDown(self):
- Image.objects.all().delete()
- super(CreateImageTestCase, self).tearDown()
-
- def test_create_image(self):
- """
- An image is created from an uploaded file.
-
- Verifies all appropriate fields are correctly set.
- """
- with open('apps/upload/tests/media/test.jpg') as f:
- up_file = File(f)
- file_info = create_image({'image': up_file}, self.user)
-
- image = Image.objects.all()[0]
- delete_url = reverse('gallery.delete_media',
- args=['image', image.id])
- check_file_info(
- file_info, name='apps/upload/tests/media/test.jpg',
- width=90, height=120, delete_url=delete_url,
- url=image.get_absolute_url(), thumbnail_url=image.file.url)
-
-
-class CreateVideoTestCase(TestCase):
- fixtures = ['users.json']
-
- def setUp(self):
- super(CreateVideoTestCase, self).setUp()
- self.user = User.objects.all()[0]
-
- def tearDown(self):
- Video.objects.all().delete()
- super(CreateVideoTestCase, self).tearDown()
-
- def test_create_video(self):
- """
- A video is created from an uploaded file.
-
- Verifies all appropriate fields are correctly set.
- """
- with open('apps/gallery/tests/media/test.flv') as f:
- up_file = File(f)
- file_info = create_video({'flv': up_file}, self.user)
-
- vid = Video.objects.all()[0]
- delete_url = reverse('gallery.delete_media',
- args=['video', vid.id])
- check_file_info(
- file_info, name='apps/gallery/tests/media/test.flv',
- width=32, height=32, delete_url=delete_url,
- url=vid.get_absolute_url(),
- thumbnail_url=settings.GALLERY_VIDEO_THUMBNAIL_PROGRESS_URL)
View
53 apps/gallery/tests/test_models.py
@@ -1,53 +0,0 @@
-from nose.tools import eq_
-from nose import SkipTest
-
-from sumo.tests import TestCase
-from gallery.models import Image, Video
-from gallery.tests import image, video
-from upload.tasks import generate_thumbnail
-
-
-class ImageTestCase(TestCase):
- fixtures = ['users.json']
-
- def tearDown(self):
- Image.objects.all().delete()
- super(ImageTestCase, self).tearDown()
-
- def test_new_image(self):
- """New Image is created and saved"""
- img = image()
- eq_('Some title', img.title)
- eq_(150, img.file.width)
- eq_(200, img.file.height)
-
- def test_thumbnail_url_if_set(self):
- """thumbnail_url_if_set() returns self.thumbnail if set, or else
- returns self.file"""
- img = image()
- eq_(img.file.url, img.thumbnail_url_if_set())
-
- generate_thumbnail(img, 'file', 'thumbnail')
- eq_(img.thumbnail.url, img.thumbnail_url_if_set())
-
-
-class VideoTestCase(TestCase):
- fixtures = ['users.json']
-
- def tearDown(self):
- Video.objects.all().delete()
- super(VideoTestCase, self).tearDown()
-
- def test_new_video(self):
- """New Video is created and saved"""
- vid = video()
- eq_('Some title', vid.title)
- assert vid.webm.name.endswith('098f6b.webm')
- assert vid.ogv.name.endswith('098f6b.ogv')
- assert vid.flv.name.endswith('098f6b.flv')
-
- def test_thumbnail_url_if_set(self):
- """thumbnail_url_if_set() returns self.thumbnail if set, or else
- returns URL to default thumbnail"""
- # TODO: write this test when implementing video thumbnail generation
- raise SkipTest
View
167 apps/gallery/tests/test_templates.py
@@ -1,167 +0,0 @@
-from django.contrib.auth.models import User
-
-from nose import SkipTest
-from nose.tools import eq_
-from pyquery import PyQuery as pq
-
-from sumo.helpers import urlparams
-from sumo.tests import TestCase, get, LocalizingClient, post
-from sumo.urlresolvers import reverse
-from gallery.models import Image, Video
-from gallery.tests import image, video
-from gallery.utils import get_draft_title
-
-
-class GalleryPageCase(TestCase):
- fixtures = ['users.json']
-
- def tearDown(self):
- Image.objects.all().delete()
- super(GalleryPageCase, self).tearDown()
-
- def test_gallery_images(self):
- """Test that all images show up on images gallery page.
-
- Also, Make sure they don't show up on videos page.
-
- """
- img = image()
- response = get(self.client, 'gallery.gallery', args=['image'])
- eq_(200, response.status_code)
- doc = pq(response.content)
- imgs = doc('#media-list li img')
- eq_(1, len(imgs))
- eq_(img.thumbnail_url_if_set(), imgs[0].attrib['src'])
-
- def test_gallery_locale(self):
- """Test that images only show for their set locale."""
- image(locale='es')
- url = reverse('gallery.gallery', args=['image'])
- response = self.client.get(url, follow=True)
- eq_(200, response.status_code)
- doc = pq(response.content)
- imgs = doc('#media-list li img')
- eq_(0, len(imgs))
-
- locale_url = reverse('gallery.gallery', locale='es',
- args=['image'])
- response = self.client.get(locale_url, follow=True)
- eq_(200, response.status_code)
- doc = pq(response.content)
- imgs = doc('#media-list li img')
- eq_(1, len(imgs))
-
- def test_gallery_upload_modal(self):
- # TODO(paul) this will probably be broken up into separate tests:
- # * Upload modal has the URL's locale selected
- # * POSTing invalid data shows error messages and pre-fills that data
- raise SkipTest
-
-
-class GalleryAsyncCase(TestCase):
- fixtures = ['users.json']
-
- def tearDown(self):
- Image.objects.all().delete()
- super(GalleryAsyncCase, self).tearDown()
-
- def test_gallery_image_list(self):
- """Test for ajax endpoint without search parameter."""
- img = image()
- url = urlparams(reverse('gallery.async'), type='image')
- response = self.client.get(url, follow=True)
- eq_(200, response.status_code)
- doc = pq(response.content)
- imgs = doc('#media-list li img')
- eq_(1, len(imgs))
- eq_(img.thumbnail_url_if_set(), imgs[0].attrib['src'])
-
- def test_gallery_image_search(self):
- """Test for ajax endpoint with search parameter."""
- img = image()
- url = urlparams(reverse('gallery.async'), type='image', q='foobar')
- response = self.client.get(url, follow=True)
- eq_(200, response.status_code)
- doc = pq(response.content)
- imgs = doc('#media-list li img')
- eq_(0, len(imgs))
-
- url = urlparams(reverse('gallery.async'), type='image', q=img.title)
- response = self.client.get(url, follow=True)
- eq_(200, response.status_code)
- doc = pq(response.content)
- imgs = doc('#media-list li img')
- eq_(1, len(imgs))
- eq_(img.thumbnail_url_if_set(), imgs[0].attrib['src'])
-
-
-class GalleryUploadTestCase(TestCase):
- fixtures = ['users.json']
-
- def setUp(self):
- super(GalleryUploadTestCase, self).setUp()
- self.client = LocalizingClient()
- self.client.login(username='pcraciunoiu', password='testpass')
- self.u = User.objects.get(username='pcraciunoiu')
-
- def tearDown(self):
- Image.objects.all().delete()
- Video.objects.all().delete()
- super(GalleryUploadTestCase, self).tearDown()
-
- def test_image_draft_shows(self):
- """The image draft is loaded for this user."""
- image(title=get_draft_title(self.u), creator=self.u)
- response = get(self.client, 'gallery.gallery', args=['image'])
- eq_(200, response.status_code)
- doc = pq(response.content)
- assert doc('.image-preview img').attr('src').endswith('098f6b.jpg')
- eq_(1, doc('.image-preview img').length)
-
- def test_video_draft_shows(self):
- """The video draft is loaded for this user."""
- video(title=get_draft_title(self.u), creator=self.u)
- response = get(self.client, 'gallery.gallery', args=['image'])
- eq_(200, response.status_code)
- doc = pq(response.content)
- # Preview for all 3 video formats: flv, ogv, webm
- eq_(3, doc('ul li.video-preview').length)
-
- def test_image_draft_post(self):
- """Posting to the page saves the field values for the image draft."""
- image(title=get_draft_title(self.u), creator=self.u)
- response = post(self.client, 'gallery.gallery',
- {'description': '??', 'title': 'test'}, args=['image'])
- eq_(200, response.status_code)
- doc = pq(response.content)
- # Preview for all 3 video formats: flv, ogv, webm
- eq_('??', doc('#gallery-upload-modal textarea').html())
- eq_('test', doc('#gallery-upload-modal input[name="title"]').val())
-
- def test_video_draft_post(self):
- """Posting to the page saves the field values for the video draft."""
- video(title=get_draft_title(self.u), creator=self.u)
- response = post(self.client, 'gallery.gallery',
- {'title': 'zTestz'}, args=['image'])
- eq_(200, response.status_code)
- doc = pq(response.content)
- # Preview for all 3 video formats: flv, ogv, webm
- eq_('zTestz', doc('#gallery-upload-modal input[name="title"]').val())
-
-
-class MediaPageCase(TestCase):
- fixtures = ['users.json']
-
- def tearDown(self):
- Image.objects.all().delete()
- super(MediaPageCase, self).tearDown()
-
- def test_image_media_page(self):
- """Test the media page."""
- img = image()
- response = self.client.get(img.get_absolute_url(), follow=True)
- eq_(200, response.status_code)
- doc = pq(response.content)
- eq_(img.title, doc('#media-object h1').text())
- eq_(img.description, doc('#media-object div.description').text())
- eq_(img.file.url, doc('#media-view img')[0].attrib['src'])
View
467 apps/gallery/tests/test_views.py
@@ -1,467 +0,0 @@
-import json
-
-from django.conf import settings
-from django.contrib.auth.models import User
-
-from nose.tools import eq_
-from pyquery import PyQuery as pq
-
-from gallery import forms
-from gallery.models import Image, Video
-from gallery.tests import image, video
-from gallery.utils import get_draft_title
-from gallery.views import _get_media_info
-from sumo.tests import post, LocalizingClient, TestCase
-from sumo.urlresolvers import reverse
-
-
-TEST_IMG = 'apps/upload/tests/media/test.jpg'
-TEST_VID = {'webm': 'apps/gallery/tests/media/test.webm',
- 'ogv': 'apps/gallery/tests/media/test.ogv',
- 'thumbnail': TEST_IMG,
- 'flv': 'apps/gallery/tests/media/test.flv'}
-INVALID_VID = 'apps/gallery/tests/media/test.rtf'
-VIDEO_PATH = settings.MEDIA_URL + settings.GALLERY_VIDEO_PATH
-
-
-class DeleteEditImageTestCase(TestCase):
- fixtures = ['users.json']
-
- def setUp(self):
- super(DeleteEditImageTestCase, self).setUp()
- self.client = LocalizingClient()
- self.client.login(username='jsocol', password='testpass')
-
- def tearDown(self):
- Image.objects.all().delete()
- super(DeleteEditImageTestCase, self).tearDown()
-
- def test_delete_image(self):
- """Deleting an uploaded image works."""
- # Upload the image first
- im = image()
- r = post(self.client, 'gallery.delete_media', args=['image', im.id])
-
- eq_(200, r.status_code)
- eq_(0, Image.objects.count())
-
- def test_delete_image_without_permissions(self):
- """Can't delete an image I didn't create."""
- self.client.login(username='tagger', password='testpass')
- img = image()
- r = post(self.client, 'gallery.delete_media', args=['image', img.id])
-
- eq_(403, r.status_code)
- eq_(1, Image.objects.count())
-
- def test_delete_own_image(self):
- """Can delete an image I created."""
- self.client.login(username='tagger', password='testpass')
- u = User.objects.get(username='tagger')
- img = image(creator=u)
- r = post(self.client, 'gallery.delete_media', args=['image', img.id])
-
- eq_(200, r.status_code)
- eq_(0, Image.objects.count())
-
- def test_edit_own_image(self):
- """Can edit an image I created."""
- u = User.objects.get(username='jsocol')
- img = image(creator=u)
- r = post(self.client, 'gallery.edit_media', {'description': 'arrr'},
- args=['image', img.id])
-
- eq_(200, r.status_code)
- eq_('arrr', Image.uncached.get().description)
-
- def test_edit_image_without_permissions(self):
- """Can't edit an image I didn't create."""
- u = User.objects.get(username='pcraciunoiu')
- img = image(creator=u)
- r = post(self.client, 'gallery.edit_media', {'description': 'arrr'},
- args=['image', img.id])
-
- eq_(403, r.status_code)
-
- def test_edit_image_with_permissions(self):
- """Editing image sets the updated_by field."""
- self.client.login(username='admin', password='testpass')
- img = image()
- r = post(self.client, 'gallery.edit_media', {'description': 'arrr'},
- args=['image', img.id])
-
- eq_(200, r.status_code)
- eq_('admin', Image.objects.get().updated_by.username)
-
-
-class UploadImageTestCase(TestCase):
- fixtures = ['users.json']
-
- def setUp(self):
- super(UploadImageTestCase, self).setUp()
- self.client = LocalizingClient()
- self.client.login(username='pcraciunoiu', password='testpass')
-
- def tearDown(self):
- Image.objects.all().delete()
- super(UploadImageTestCase, self).tearDown()
-
- def test_empty_image(self):
- """Specifying an invalid model returns 400."""
- r = post(self.client, 'gallery.upload_async', {'file': ''},
- args=['image'])
-
- eq_(400, r.status_code)
- json_r = json.loads(r.content)
- eq_('error', json_r['status'])
- eq_('Could not upload your image.', json_r['message'])
- eq_('You have not selected an image to upload.',
- json_r['errors']['file'][0])
-
- def test_upload_image(self):
- """Uploading an image works."""
- with open(TEST_IMG) as f:
- r = post(self.client, 'gallery.upload_async', {'file': f},
- args=['image'])
- img = Image.objects.all()[0]
-
- eq_(1, Image.objects.count())
- eq_(200, r.status_code)
- json_r = json.loads(r.content)
- eq_('success', json_r['status'])
- file = json_r['file']
- eq_('test.jpg', file['name'])
- eq_(90, file['width'])
- eq_(120, file['height'])
- assert file['url'].endswith(img.get_absolute_url())
- eq_('pcraciunoiu', img.creator.username)
- eq_(150, img.file.width)
- eq_(200, img.file.height)
- eq_(get_draft_title(img.creator), img.title)
- eq_('Autosaved draft.', img.description)
- eq_('en-US', img.locale)
-
- def test_upload_unicode_image(self):
- """Uploading an unicode image works."""
- with open(u'apps/upload/tests/media/123ascii\u6709\u52b9.jpg') as f:
- r = post(self.client, 'gallery.upload_async', {'file': f},
- args=['image'])
-
- eq_(1, Image.objects.count())
- eq_(200, r.status_code)
- json_r = json.loads(r.content)
- eq_('success', json_r['status'])
-
- def test_invalid_image(self):
- """Make sure invalid files are not accepted as images."""
- with open('apps/gallery/__init__.py', 'rb') as f:
- r = post(self.client, 'gallery.upload_async', {'file': f},
- args=['image'])
-
- eq_(400, r.status_code)
- json_r = json.loads(r.content)
- eq_('error', json_r['status'])
- eq_('Could not upload your image.', json_r['message'])
- eq_('Upload a valid image. The file you uploaded was either not an '
- 'image or a corrupted image.', json_r['errors']['file'][0])
-
- def test_invalid_image_extension(self):
- """Make sure invalid extensions are not accepted as images."""
- with open('apps/upload/tests/media/test_invalid.ext', 'rb') as f:
- r = post(self.client, 'gallery.upload_async', {'file': f},
- args=['image'])
-
- eq_(400, r.status_code)
- json_r = json.loads(r.content)
- eq_('error', json_r['status'])
- eq_('Could not upload your image.', json_r['message'])
- eq_('Please upload an image with one of the following extensions: '
- 'jpg, jpeg, png, gif.', json_r['errors']['__all__'][0])
-
- def test_invalid_thumbnail_extension(self):
- """Make sure invalid extensions are not accepted as thumbnails."""
- with open('apps/upload/tests/media/test_invalid.ext', 'rb') as f:
- r = post(self.client, 'gallery.upload_async', {'thumbnail': f},
- args=['video'])
-
- eq_(400, r.status_code)
- json_r = json.loads(r.content)
- eq_('error', json_r['status'])
- eq_('Could not upload your video.', json_r['message'])
- eq_('Please upload an image with one of the following extensions: '
- 'jpg, jpeg, png, gif.', json_r['errors']['__all__'][0])
-
- def test_upload_image_long_filename(self):
- """Uploading an image with a filename that's too long fails."""
- with open('apps/upload/tests/media/a_really_long_filename_worth_'
- 'more_than_250_characters__a_really_long_filename_worth_'
- 'more_than_250_characters__a_really_long_filename_worth_'
- 'more_than_250_characters__a_really_long_filename_worth_'
- 'more_than_250_characters__a_really_long_filename_yes_.jpg')\
- as f:
- r = post(self.client, 'gallery.upload_async', {'file': f},
- args=['image'])
-
- eq_(400, r.status_code)
- json_r = json.loads(r.content)
- eq_('error', json_r['status'])
- eq_('Could not upload your image.', json_r['message'])
- eq_(forms.MSG_IMAGE_LONG % {'length': 251,
- 'max': settings.MAX_FILENAME_LENGTH},
- json_r['errors']['file'][0])
-
- def test_upload_draft_image(self):
- """Uploading draft image works, sets locale too."""
- u = User.objects.get(username='pcraciunoiu')
- img = image(creator=u, title=get_draft_title(u))
- # No thumbnail yet.
- eq_(None, img.thumbnail)
-
- r = post(self.client, 'gallery.upload',
- {'locale': 'de', 'title': 'Hasta la vista',
- 'description': 'Auf wiedersehen!'},
- args=['image'])
-
- eq_(200, r.status_code)
- img = Image.objects.all()[0]
- eq_('de', img.locale)
- eq_('Hasta la vista', img.title)
- eq_('Auf wiedersehen!', img.description)
- # Thumbnail generated after form is saved.
- eq_(90, img.thumbnail.width)
-
- def test_image_title_locale_unique_validation(self):
- """Posting an existing locale/title combination shows a validation
- error."""
- u = User.objects.get(username='pcraciunoiu')
- image(creator=u, title=get_draft_title(u))
- post(self.client, 'gallery.upload',
- {'locale': 'de', 'title': 'Hasta la vista',
- 'description': 'Auf wiedersehen!'}, args=['image'])
- image(creator=u, title=get_draft_title(u))
- r = post(self.client, 'gallery.upload',
- {'locale': 'de', 'title': 'Hasta la vista',
- 'description': 'Auf wiedersehen!'},
- args=['image'])
- eq_(200, r.status_code)
- doc = pq(r.content)
- msg = 'Image with this Locale and Title already exists.'
- assert doc('ul.errorlist li').text().startswith(msg)
-
-
-class ViewHelpersTestCase(TestCase):
- fixtures = ['users.json']
-
- def tearDown(self):
- Image.objects.all().delete()
- Video.objects.all().delete()
- super(ViewHelpersTestCase, self).setUp()
-
- def test_get_media_info_video(self):
- """Gets video and format info."""
- vid = video()
- info_vid, info_format = _get_media_info(vid.pk, 'video')
- eq_(vid.pk, info_vid.pk)
- eq_(None, info_format)
-
- def test_get_media_info_image(self):
- """Gets image and format info."""
- img = image()
- info_img, info_format = _get_media_info(img.pk, 'image')
- eq_(img.pk, info_img.pk)
- eq_('jpeg', info_format)
-
-
-class UploadVideoTestCase(TestCase):
- fixtures = ['users.json']
-
- def setUp(self):
- super(UploadVideoTestCase, self).setUp()
- self.client = LocalizingClient()
- self.client.login(username='pcraciunoiu', password='testpass')
-
- def tearDown(self):
- Video.objects.all().delete()
- super(UploadVideoTestCase, self).tearDown()
-
- def _upload_extension(self, ext):
- with open(TEST_VID[ext]) as f:
- r = post(self.client, 'gallery.upload_async', {ext: f},
- args=['video'])
- return r
-
- def test_upload_video(self):
- """Uploading a video works."""
- r = self._upload_extension('ogv')
- vid = Video.objects.all()[0]
-
- eq_(1, Video.objects.count())
- eq_(200, r.status_code)
- json_r = json.loads(r.content)
- eq_('success', json_r['status'])
- file = json_r['file']
- eq_('test.ogv', file['name'])
- eq_(32, file['width'])
- eq_(32, file['height'])
- assert file['url'].endswith(vid.get_absolute_url())
- eq_('pcraciunoiu', vid.creator.username)
- eq_(get_draft_title(vid.creator), vid.title)
- eq_('Autosaved draft.', vid.description)
- eq_('en-US', vid.locale)
- with open(TEST_VID['ogv']) as f:
- eq_(f.read(), vid.ogv.read())
-
- def test_delete_video_ogv(self):
- """Deleting an uploaded video works."""
- # Upload the video first
- self._upload_extension('ogv')
- vid = Video.objects.all()[0]
- r = post(self.client, 'gallery.delete_media',
- args=['video', vid.id])
-
- eq_(200, r.status_code)
- eq_(0, Video.objects.count())
-
- def test_upload_video_ogv_flv(self):
- """Upload the same video, in ogv and flv formats"""
- ogv = open(TEST_VID['ogv'])
- flv = open(TEST_VID['flv'])
- post(self.client, 'gallery.upload_async', {'ogv': ogv, 'flv': flv},
- args=['video'])
- ogv.close()
- flv.close()
- vid = Video.objects.all()[0]
- assert vid.ogv.url.endswith('098f6b.ogv')
- assert vid.flv.url.endswith('098f6b.flv')
-
- def test_upload_video_all(self):
- """Upload the same video, in all formats"""
- webm = open(TEST_VID['webm'])
- ogv = open(TEST_VID['ogv'])
- flv = open(TEST_VID['flv'])
- post(self.client, 'gallery.upload_async',
- {'webm': webm, 'ogv': ogv, 'flv': flv}, args=['video'])
- webm.close()
- ogv.close()
- flv.close()
- vid = Video.objects.all()[0]
- assert vid.webm.url.endswith('098f6b.webm')
- assert vid.ogv.url.endswith('098f6b.ogv')
- assert vid.flv.url.endswith('098f6b.flv')
-
- def test_video_required(self):
- """At least one video format is required to upload."""
- r = post(self.client, 'gallery.upload_async', args=['video'])
- eq_(400, r.status_code)
- json_r = json.loads(r.content)
- eq_('error', json_r['status'])
- eq_('Could not upload your video.', json_r['message'])
- eq_('The video has no files associated with it. You must upload one '
- 'of the following extensions: webm, ogv, flv.',
- json_r['errors']['__all__'][0])
-
- def test_upload_video_long_filename(self):
- """Uploading a video with a filename that's too long fails."""
- for k in ('flv', 'ogv', 'webm'):
- with open('apps/upload/tests/media/a_really_long_filename_worth_'
- 'more_than_250_characters__a_really_long_filename_worth_'
- 'more_than_250_characters__a_really_long_filename_worth_'
- 'more_than_250_characters__a_really_long_filename_worth_'
- 'more_than_250_characters__a_really_long_filename_yes_'
- '.jpg')\
- as f:
- r = post(self.client, 'gallery.upload_async', {k: f},
- args=['video'])
-
- eq_(400, r.status_code)
- json_r = json.loads(r.content)
- eq_('error', json_r['status'])
- eq_('Could not upload your video.', json_r['message'])
- message = getattr(forms, 'MSG_' + k.upper() + '_LONG')
- eq_(message % {'length': 251, 'max': settings.MAX_FILENAME_LENGTH},
- json_r['errors'][k][0])
-
- def test_invalid_video_extension(self):
- """Make sure invalid video extensions are not accepted."""
- with open(INVALID_VID) as f:
- r = post(self.client, 'gallery.upload_async', {'webm': f},
- args=['video'])
- eq_(400, r.status_code)
- json_r = json.loads(r.content)
- eq_('error', json_r['status'])
- eq_('Could not upload your video.', json_r['message'])
- eq_(forms.MSG_VID_REQUIRED, json_r['errors']['__all__'][0])
-
- def test_upload_thumbnail(self):
- """Uploading a thumbnail sets the field and adds a poster."""
- r = self._upload_extension('thumbnail')
- vid = Video.objects.all()[0]
-
- eq_(1, Video.objects.count())
- eq_(200, r.status_code)
- eq_(150, vid.thumbnail.width)
- eq_(150, vid.poster.width)
-
- def test_upload_draft_video(self):
- """Uploading draft video works, sets locale too."""
- # Upload a thumbnail/poster
- self._upload_extension('webm')
- self._upload_extension('thumbnail')
- vid = Video.uncached.all()[0]
- assert vid.thumbnail
- assert vid.poster
-
- r = post(self.client, 'gallery.upload',
- {'locale': 'de', 'title': 'Hasta la vista',
- 'description': 'Auf wiedersehen!'},
- args=['video'])
-
- vid = Video.uncached.all()[0]
- eq_(200, r.status_code)