Skip to content

Commit 8524dcb

Browse files
committed
Initial commit
0 parents  commit 8524dcb

File tree

13 files changed

+532
-0
lines changed

13 files changed

+532
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.pyc
2+
/dist/
3+
/mezzanine_slides.egg-info/
4+
/MANIFEST

MANIFEST.in

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include README.md
2+
recursive-include mezzanine_slides/static *
3+
recursive-include mezzanine_slides/templates *

README.md

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# mezzanine-slides
2+
3+
Add simple slide functionality to your Mezzanine based website allowing for
4+
beautiful banners at the tops of pages.
5+
6+
7+
# Setup
8+
9+
Add `mezzanine_slides` to your `INSTALLED_APPS` and syncdb. Migrations are
10+
included if you use South. You can use the templates included by running
11+
`collecttemplates` but this will overwrite any changes you have made to your
12+
`base.html` and `pages/page.html` templates. If you wish to add the template
13+
markup yourself see Templates below.
14+
15+
16+
# Templates
17+
18+
Add this to your `pages/page.html` anywhere as long as it's not inside another
19+
block:
20+
21+
{% block slides %}{% if page.slide_set.all %}
22+
<div class="row">
23+
<div class="span12">
24+
<ul class="rslides">{% for image in page.slide_set.all %}
25+
<li><img src="{{ image.file.url }}" alt="{{ image.description }}"/></li>
26+
{% endfor %}</ul>
27+
</div>
28+
</div>
29+
{% endif %}{% endblock %}
30+
31+
Add this to `base.html` where you would like the slides to appear, which is
32+
usually between your main content and the navigation:
33+
34+
{% block slides %}{% endblock %}
35+
36+
Notice that I include the `row` and `span12` classes on the `pages/page.html`
37+
template so that if you don't have any slides then nothing is added to the page.
38+
39+
Now you'll need to include the CSS and JS in your compress areas of your
40+
`base.html` template:
41+
42+
{% compress css %}
43+
...
44+
<link rel="stylesheet" href="{{ STATIC_URL }}css/responsiveslides.css">
45+
{% endcompress %}
46+
47+
48+
{% compress js %}
49+
...
50+
<script src="{{ STATIC_URL }}js/responsiveslides.min.js"></script>
51+
{% endcompress %}
52+
53+
Lastly you'll need to invoke the slides JavaScript by putting
54+
`$('.rslides').responsiveSlides();` on in your JavaScript somewhere. In the
55+
`base.html` template I put this in the header around line 34 where I found some
56+
other JavaScript functions to just make it easy and try to conform to the
57+
original Mezzanine as much as possible, here is an excerpt of the area:
58+
59+
<script>
60+
$(function() {
61+
...
62+
$('.rslides').responsiveSlides();
63+
});
64+
</script>
65+
66+
## License (Simplified BSD)
67+
68+
Copyright (c) Isaac Bythewood
69+
All rights reserved.
70+
71+
Redistribution and use in source and binary forms, with or without
72+
modification, are permitted provided that the following conditions are met:
73+
74+
1. Redistributions of source code must retain the above copyright notice,
75+
this list of conditions and the following disclaimer.
76+
77+
2. Redistributions in binary form must reproduce the above copyright notice,
78+
this list of conditions and the following disclaimer in the documentation
79+
and/or other materials provided with the distribution.
80+
81+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
82+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
83+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
84+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
85+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
86+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
87+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
88+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
89+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

mezzanine_slides/__init__.py

Whitespace-only changes.

mezzanine_slides/admin.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from copy import deepcopy
2+
3+
from django.contrib import admin
4+
5+
from mezzanine.pages.models import RichTextPage
6+
7+
from mezzanine.core.admin import TabularDynamicInlineAdmin
8+
from mezzanine.pages.admin import PageAdmin
9+
from mezzanine.forms.admin import FormAdmin
10+
from mezzanine.galleries.admin import GalleryAdmin
11+
12+
try:
13+
from cartridge.shop.models import Category
14+
from cartridge.shop.admin import CategoryAdmin
15+
cartridge = True
16+
except ImportError:
17+
cartridge = False
18+
19+
from .models import Slide
20+
21+
22+
"""
23+
We do what we do here instead of just attaching it to PageAdmin because more
24+
things then just pages inherit PageAdmin and if we just inject it into PageAdmin
25+
I've had some very bad things happen. Thus I inject it into each page type
26+
individually in a way that best suits it.
27+
"""
28+
29+
30+
class SlideInline(TabularDynamicInlineAdmin):
31+
model = Slide
32+
33+
34+
class RichTextPageAdmin(PageAdmin):
35+
inlines = (SlideInline,)
36+
37+
admin.site.unregister(RichTextPage)
38+
admin.site.register(RichTextPage, RichTextPageAdmin)
39+
40+
FormAdmin.inlines += (SlideInline,)
41+
GalleryAdmin.inlines += (SlideInline,)
42+
43+
44+
if cartridge:
45+
class CategoryAdminInline(CategoryAdmin):
46+
inlines = (SlideInline,)
47+
48+
admin.site.unregister(Category)
49+
admin.site.register(Category, CategoryAdminInline)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# -*- coding: utf-8 -*-
2+
import datetime
3+
from south.db import db
4+
from south.v2 import SchemaMigration
5+
from django.db import models
6+
7+
8+
class Migration(SchemaMigration):
9+
10+
def forwards(self, orm):
11+
# Adding model 'Slider'
12+
db.create_table('mezzanine_slides_slide', (
13+
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
14+
('_order', self.gf('django.db.models.fields.IntegerField')(null=True)),
15+
('page', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['pages.Page'], null=True, blank=True)),
16+
('file', self.gf('mezzanine.core.fields.FileField')(max_length=200)),
17+
('description', self.gf('django.db.models.fields.CharField')(max_length=70, blank=True)),
18+
))
19+
db.send_create_signal('core', ['Slider'])
20+
21+
22+
def backwards(self, orm):
23+
# Deleting model 'Slider'
24+
db.delete_table('core_slider')
25+
26+
27+
models = {
28+
'contenttypes.contenttype': {
29+
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
30+
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
31+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
32+
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
33+
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
34+
},
35+
'core.slider': {
36+
'Meta': {'ordering': "['_order']", 'object_name': 'Slider'},
37+
'_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
38+
'description': ('django.db.models.fields.CharField', [], {'max_length': '70', 'blank': 'True'}),
39+
'file': ('mezzanine.core.fields.FileField', [], {'max_length': '200'}),
40+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
41+
'page': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['pages.Page']", 'null': 'True', 'blank': 'True'})
42+
},
43+
'generic.assignedkeyword': {
44+
'Meta': {'ordering': "('_order',)", 'object_name': 'AssignedKeyword'},
45+
'_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
46+
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
47+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
48+
'keyword': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'assignments'", 'to': "orm['generic.Keyword']"}),
49+
'object_pk': ('django.db.models.fields.IntegerField', [], {})
50+
},
51+
'generic.keyword': {
52+
'Meta': {'object_name': 'Keyword'},
53+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
54+
'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
55+
'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
56+
'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
57+
},
58+
'pages.page': {
59+
'Meta': {'ordering': "('titles',)", 'object_name': 'Page'},
60+
'_meta_title': ('django.db.models.fields.CharField', [], {'max_length': '500', 'null': 'True', 'blank': 'True'}),
61+
'_order': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
62+
'content_model': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True'}),
63+
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
64+
'expiry_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
65+
'gen_description': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
66+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
67+
'in_menus': ('mezzanine.pages.fields.MenusField', [], {'default': '[1, 2, 3]', 'max_length': '100', 'null': 'True', 'blank': 'True'}),
68+
'keywords': ('mezzanine.generic.fields.KeywordsField', [], {'object_id_field': "'object_pk'", 'to': "orm['generic.AssignedKeyword']", 'frozen_by_south': 'True'}),
69+
'keywords_string': ('django.db.models.fields.CharField', [], {'max_length': '500', 'blank': 'True'}),
70+
'login_required': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
71+
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['pages.Page']"}),
72+
'publish_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
73+
'short_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
74+
'site': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['sites.Site']"}),
75+
'slug': ('django.db.models.fields.CharField', [], {'max_length': '2000', 'null': 'True', 'blank': 'True'}),
76+
'status': ('django.db.models.fields.IntegerField', [], {'default': '2'}),
77+
'title': ('django.db.models.fields.CharField', [], {'max_length': '500'}),
78+
'titles': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True'})
79+
},
80+
'sites.site': {
81+
'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
82+
'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
83+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
84+
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
85+
}
86+
}
87+
88+
complete_apps = ['core']

mezzanine_slides/migrations/__init__.py

Whitespace-only changes.

mezzanine_slides/models.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from urllib import unquote
2+
from string import punctuation
3+
4+
from django.db import models
5+
from django.utils.translation import ugettext_lazy as _
6+
7+
from mezzanine.pages.models import Page
8+
from mezzanine.core.models import Orderable
9+
from mezzanine.core.fields import FileField
10+
11+
12+
class Slide(Orderable):
13+
"""
14+
Allows for pretty banner images across the top of pages that will cycle
15+
through each other with a fade effect.
16+
"""
17+
page = models.ForeignKey(Page, null=True, blank=True)
18+
file = FileField(_('File'), max_length=200, upload_to='galleries', format='Image')
19+
description = models.CharField(_('Description'), blank=True, max_length=70)
20+
21+
class Meta:
22+
verbose_name = _('Slide')
23+
verbose_name_plural = _('Slides')
24+
ordering = ['_order']
25+
26+
def __unicode__(self):
27+
return self.description
28+
29+
def save(self, *args, **kwargs):
30+
"""
31+
If no description is given when created, create one from the
32+
file name.
33+
"""
34+
if not self.id and not self.description:
35+
name = unquote(self.file.url).split('/')[-1].rsplit('.', 1)[0]
36+
name = name.replace("'", '')
37+
name = ''.join([c if c not in punctuation else ' ' for c in name])
38+
# str.title() doesn't deal with unicode very well.
39+
# http://bugs.python.org/issue6412
40+
name = ''.join([s.upper() if i == 0 or name[i - 1] == ' ' else s
41+
for i, s in enumerate(name)])
42+
self.description = name
43+
super(Slide, self).save(*args, **kwargs)
44+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*! http://responsiveslides.com v1.32 by @viljamis */
2+
3+
.rslides {
4+
position: relative;
5+
list-style: none;
6+
overflow: hidden;
7+
width: 100%;
8+
padding: 0;
9+
margin: 0;
10+
}
11+
12+
.rslides li {
13+
position: absolute;
14+
display: none;
15+
width: 100%;
16+
left: 0;
17+
top: 0;
18+
}
19+
20+
.rslides li:first-child {
21+
position: relative;
22+
display: block;
23+
float: left;
24+
}
25+
26+
.rslides img {
27+
display: block;
28+
height: auto;
29+
float: left;
30+
width: 100%;
31+
border: 0;
32+
}

mezzanine_slides/static/js/responsiveslides.min.js

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)