瀏覽代碼

Merge branch 'master' into 62-blog-index-styling

Edd Baldry 8 年之前
父節點
當前提交
cdb3585b26

+ 1 - 1
.gitignore

@@ -3,6 +3,7 @@
 *.log
 *.swp
 *.retry
+.env
 *~
 /logs
 /data
@@ -16,4 +17,3 @@ __pycache__
 /.vagrant/
 /Vagrantfile.local
 !.gitignore
-

+ 20 - 0
bakerydemo/base/migrations/0012_auto_20170222_0756.py

@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-22 07:56
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('base', '0011_auto_20170220_0111'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='gallerypage',
+            old_name='choices',
+            new_name='collection',
+        ),
+    ]

+ 3 - 31
bakerydemo/base/models.py

@@ -5,8 +5,6 @@ from django.db import models
 from modelcluster.fields import ParentalKey
 from modelcluster.models import ClusterableModel
 
-from wagtail.contrib.modeladmin.options import (
-    ModelAdmin, ModelAdminGroup, modeladmin_register)
 from wagtail.wagtailadmin.edit_handlers import (
     FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel,
     PageChooserPanel, StreamFieldPanel,
@@ -201,7 +199,7 @@ class GalleryPage(BasePageFieldsMixin, Page):
     """
     This is a page to list locations from the selected Collection
     """
-    choices = models.ForeignKey(
+    collection = models.ForeignKey(
         Collection,
         limit_choices_to=~models.Q(name__in=['Root']),
         null=True,
@@ -211,19 +209,12 @@ class GalleryPage(BasePageFieldsMixin, Page):
     )
 
     content_panels = BasePageFieldsMixin.content_panels + [
-        FieldPanel('choices'),
+        FieldPanel('collection'),
     ]
 
-    # parent_page_types = [
-    #     'home.HomePage'
-    # ]
-
     # Defining what content type can sit under the parent. Since it's a blank
     # array no subpage can be added
-    subpage_types = [
-    ]
-
-    # api_fields = ['introduction']
+    subpage_types = []
 
 
 class FormField(AbstractFormField):
@@ -253,22 +244,3 @@ class FormPage(AbstractEmailForm):
             FieldPanel('subject'),
         ], "Email"),
     ]
-
-
-class PeopleModelAdmin(ModelAdmin):
-    model = People
-    menu_label = 'People'  # ditch this to use verbose_name_plural from model
-    menu_icon = 'fa-people'  # change as required
-    list_display = ('first_name', 'last_name', 'job_title', 'thumb_image')
-
-
-class MyModelAdminGroup(ModelAdminGroup):
-    menu_label = 'WagtailBakery'
-    menu_icon = 'folder-open-inverse'  # change as required
-    menu_order = 200  # will put in 3rd place (000 being 1st, 100 2nd)
-    items = (PeopleModelAdmin,)
-
-
-# When using a ModelAdminGroup class to group several ModelAdmin classes together,
-# you only need to register the ModelAdminGroup class with Wagtail:
-modeladmin_register(MyModelAdminGroup)

+ 3 - 4
bakerydemo/base/templatetags/gallery_tags.py

@@ -1,17 +1,16 @@
 from django import template
 
-from wagtail.wagtailcore.models import Page
 from wagtail.wagtailimages.models import Image
 
-
 register = template.Library()
 
+
 # Retrieves a single gallery item and returns a gallery of images
 @register.inclusion_tag('tags/gallery.html', takes_context=True)
 def gallery(context, gallery):
     images = Image.objects.filter(collection=gallery)
-    
+
     return {
         'images': images,
         'request': context['request'],
-    }
+    }

+ 62 - 0
bakerydemo/base/wagtail_hooks.py

@@ -0,0 +1,62 @@
+from wagtail.contrib.modeladmin.options import (
+    ModelAdmin, ModelAdminGroup, modeladmin_register)
+
+from bakerydemo.breads.models import Country, BreadType
+from bakerydemo.base.models import People, FooterText
+
+'''
+N.B. To see what icons are available for use in Wagtail menus and StreamField block types,
+enable the styleguide in settings:
+
+INSTALLED_APPS = (
+   ...
+   'wagtail.contrib.wagtailstyleguide',
+   ...
+)
+
+or see http://kave.github.io/general/2015/12/06/wagtail-streamfield-icons.html
+
+This demo project includes the full font-awesome set via CDN in base.html, so the entire
+font-awesome icon set is available to you. Options are at http://fontawesome.io/icons/.
+'''
+
+
+class BreadTypeAdmin(ModelAdmin):
+    # These stub classes allow us to put various models into the custom "Wagtail Bakery" menu item
+    # rather than under the default Snippets section.
+    model = BreadType
+
+
+class BreadCountryAdmin(ModelAdmin):
+    model = Country
+
+
+class BreadModelAdminGroup(ModelAdminGroup):
+    menu_label = 'Bread Categories'
+    menu_icon = 'fa-suitcase'  # change as required
+    menu_order = 200  # will put in 3rd place (000 being 1st, 100 2nd)
+    items = (BreadTypeAdmin, BreadCountryAdmin)
+
+
+class PeopleModelAdmin(ModelAdmin):
+    model = People
+    menu_label = 'People'  # ditch this to use verbose_name_plural from model
+    menu_icon = 'fa-users'  # change as required
+    list_display = ('first_name', 'last_name', 'job_title', 'thumb_image')
+
+
+class FooterTextAdmin(ModelAdmin):
+    model = FooterText
+
+
+class BakeryModelAdminGroup(ModelAdminGroup):
+    menu_label = 'Bakery Misc'
+    menu_icon = 'fa-cutlery'  # change as required
+    menu_order = 300  # will put in 4th place (000 being 1st, 100 2nd)
+    items = (PeopleModelAdmin, FooterTextAdmin)
+
+
+# When using a ModelAdminGroup class to group several ModelAdmin classes together,
+# you only need to register the ModelAdminGroup class with Wagtail:
+modeladmin_register(BreadModelAdminGroup)
+modeladmin_register(BakeryModelAdminGroup)

+ 1 - 1
bakerydemo/breads/models.py

@@ -1,5 +1,5 @@
-from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
 from django.db import models
+from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
 
 from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel
 from wagtail.wagtailcore.fields import StreamField

+ 2 - 2
bakerydemo/templates/base/gallery_page.html

@@ -18,8 +18,8 @@
 <div class="container">
     <div class="row">
         <div class="col-xs-12">
-            {{ page.introduction }}
-            {% gallery page.choices %}
+            <h2>{{ page.introduction }}</h2>
+            {% gallery page.collection %}
         </div>
     </div>
 </div>

+ 1 - 1
bakerydemo/templates/tags/gallery.html

@@ -3,7 +3,7 @@
 {% for img in images %}
 {% image img fill-285x200-c100 as img_obj %}
 <div class="col-sm-6">
-	<a href="">
+	<a href="{{img_obj.image.get_usage.first.specific.url}}">
 		<figure class="gallery-figure">
 			<img src="{{img_obj.url}}" class="img-responsive" />
 			<figcaption>{{ img.title }}</figcaption>

+ 17 - 10
readme.md

@@ -6,11 +6,17 @@ This is a demonstration project for [Wagtail CMS](http://wagtail.io).
 *We do __not__ recommend using this project to start your own site*. This project is only to provide some examples of
 implementing common features, it is not an exemplar of Django or Wagtail best practice.
 
-If you're reasonably new to Python/Django, we suggest you run this project on a Virtual Machine using Vagrant, which
-helps  resolve common software dependency issues. However for more experienced developers, instructions to start this
-project without Vagrant follow below.
+This project can be installed in one of three ways:
 
-Once you're familiar with the examples in this project and you want to start a real site, we strongly recommend running
+- Vagrant
+- Docker
+- Traditional/manual Django setup
+
+If you're new to Python/Django, we suggest you run this project on a Virtual Machine using Vagrant or
+via Docker, both of which help resolve common software dependency issues. Developers more familiar with
+virtualenv and traditional Django app setup instructions should use the Local Setup instructions below.
+
+Once you're familiar with the examples in this project and you want to start a real site, run
 the ``wagtail start`` command in a fresh virtual environment, explained in the
 [Wagtail CMS Documentation](http://wagtail.readthedocs.org/en/latest/getting_started/).
 
@@ -70,15 +76,16 @@ docker-compose logs -f
 
 Local Setup
 -----------
-Don't want to set up a whole VM nor use Docker to try out Wagtail? No problem.
-
-### Dependencies
-* [PIP](https://github.com/pypa/pip)
+Don't want to set up a whole Vagrant VM or use Docker to try out Wagtail? No problem. You'll probably want to start
+with a fresh virtualenv.
 
 ### Installation
 
-With PIP installed run the following commands:
+With [PIP](https://github.com/pypa/pip) and [virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/)
+installed, run:
 
+    mkvirtualenv wagtailbakerydemo
+    cd ~/dev [or your preferred dev directory]
     git clone git@github.com:wagtail/bakerydemo.git
     cd wagtaildemo
     pip install -r requirements.txt
@@ -89,7 +96,7 @@ to help with this. It reads environment variables located in a file name .env in
     $ cp bakerydemo/settings/local.py.example bakerydemo/settings/local.py
     $ echo "DJANGO_SETTINGS_MODULE=bakerydemo.settings.local" > .env
 
-Execute the following commands:
+To set up your database and load initial data, run the following commands:
 
     ./manage.py migrate
     ./manage.py load_initial_data