2
0
Эх сурвалжийг харах

Merge branch 'master' of https://github.com/wagtail/bakerydemo

Scot Hacker 8 жил өмнө
parent
commit
545a49dbda

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 307 - 0
bakerydemo/base/fixtures/breads.json


+ 10 - 0
bakerydemo/base/fixtures/collections.json

@@ -0,0 +1,10 @@
+[{
+  "model": "wagtailcore.collection",
+  "pk": 2,
+  "fields": {
+    "path": "00010001",
+    "depth": 2,
+    "numchild": 0,
+    "name": "Breads"
+  }
+}]

+ 217 - 0
bakerydemo/base/fixtures/images.json

@@ -0,0 +1,217 @@
+[
+{
+  "model": "wagtailimages.image",
+  "pk": 2,
+  "fields": {
+    "collection": 2,
+    "title": "Anadama",
+    "file": "original_images/Anadama_bread_1.jpg",
+    "width": 4752,
+    "height": 3168,
+    "created_at": "2017-02-10T13:03:58.541Z",
+    "uploaded_by_user": 1,
+    "focal_point_x": null,
+    "focal_point_y": null,
+    "focal_point_width": null,
+    "focal_point_height": null,
+    "file_size": null
+  }
+},
+{
+  "model": "wagtailimages.image",
+  "pk": 3,
+  "fields": {
+    "collection": 2,
+    "title": "Anpan",
+    "file": "original_images/Bean-jam-bunanpankatori-cityjapan.JPG",
+    "width": 800,
+    "height": 640,
+    "created_at": "2017-02-10T13:05:45.828Z",
+    "uploaded_by_user": 1,
+    "focal_point_x": null,
+    "focal_point_y": null,
+    "focal_point_width": null,
+    "focal_point_height": null,
+    "file_size": null
+  }
+},
+{
+  "model": "wagtailimages.image",
+  "pk": 4,
+  "fields": {
+    "collection": 2,
+    "title": "Bazin",
+    "file": "original_images/Bazin.jpg",
+    "width": 1600,
+    "height": 1200,
+    "created_at": "2017-02-10T13:08:04.012Z",
+    "uploaded_by_user": 1,
+    "focal_point_x": null,
+    "focal_point_y": null,
+    "focal_point_width": null,
+    "focal_point_height": null,
+    "file_size": null
+  }
+},
+{
+  "model": "wagtailimages.image",
+  "pk": 5,
+  "fields": {
+    "collection": 2,
+    "title": "Belgian Waffle",
+    "file": "original_images/Belgische_waffeln.jpg",
+    "width": 2025,
+    "height": 1536,
+    "created_at": "2017-02-10T13:10:05.988Z",
+    "uploaded_by_user": 1,
+    "focal_point_x": null,
+    "focal_point_y": null,
+    "focal_point_width": null,
+    "focal_point_height": null,
+    "file_size": null
+  }
+},
+{
+  "model": "wagtailimages.image",
+  "pk": 6,
+  "fields": {
+    "collection": 2,
+    "title": "Bhakri",
+    "file": "original_images/Another_Vegetarian_Meal.jpg",
+    "width": 1600,
+    "height": 1200,
+    "created_at": "2017-02-10T13:15:25.730Z",
+    "uploaded_by_user": 1,
+    "focal_point_x": null,
+    "focal_point_y": null,
+    "focal_point_width": null,
+    "focal_point_height": null,
+    "file_size": null
+  }
+},
+{
+  "model": "wagtailimages.image",
+  "pk": 7,
+  "fields": {
+    "collection": 2,
+    "title": "Black Bread",
+    "file": "original_images/Mischbrot-1.jpg",
+    "width": 2000,
+    "height": 1500,
+    "created_at": "2017-02-10T13:17:14.968Z",
+    "uploaded_by_user": 1,
+    "focal_point_x": null,
+    "focal_point_y": null,
+    "focal_point_width": null,
+    "focal_point_height": null,
+    "file_size": null
+  }
+},
+{
+  "model": "wagtailimages.image",
+  "pk": 8,
+  "fields": {
+    "collection": 2,
+    "title": "Appam",
+    "file": "original_images/Appam_served_with_Coconut_Milk_in_Tamil_Nadu.JPG",
+    "width": 2362,
+    "height": 1064,
+    "created_at": "2017-02-10T13:19:24.588Z",
+    "uploaded_by_user": 1,
+    "focal_point_x": null,
+    "focal_point_y": null,
+    "focal_point_width": null,
+    "focal_point_height": null,
+    "file_size": null
+  }
+},
+{
+  "model": "wagtailimages.image",
+  "pk": 9,
+  "fields": {
+    "collection": 1,
+    "title": "Arepa",
+    "file": "original_images/Arepa_asada.JPG",
+    "width": 1600,
+    "height": 1200,
+    "created_at": "2017-02-10T13:22:40.113Z",
+    "uploaded_by_user": 1,
+    "focal_point_x": null,
+    "focal_point_y": null,
+    "focal_point_width": null,
+    "focal_point_height": null,
+    "file_size": null
+  }
+},
+{
+  "model": "wagtailimages.image",
+  "pk": 10,
+  "fields": {
+    "collection": 2,
+    "title": "Bolani",
+    "file": "original_images/Bolani_Afghan_bread_01.jpg",
+    "width": 1280,
+    "height": 960,
+    "created_at": "2017-02-10T13:24:28.559Z",
+    "uploaded_by_user": 1,
+    "focal_point_x": null,
+    "focal_point_y": null,
+    "focal_point_width": null,
+    "focal_point_height": null,
+    "file_size": null
+  }
+},
+{
+  "model": "wagtailimages.image",
+  "pk": 11,
+  "fields": {
+    "collection": 2,
+    "title": "Baguette",
+    "file": "original_images/Baguette_de_pain_WikiCheese_Lausanne.jpg",
+    "width": 4032,
+    "height": 1958,
+    "created_at": "2017-02-10T13:24:47.838Z",
+    "uploaded_by_user": 1,
+    "focal_point_x": null,
+    "focal_point_y": null,
+    "focal_point_width": null,
+    "focal_point_height": null,
+    "file_size": null
+  }
+},
+{
+  "model": "wagtailimages.image",
+  "pk": 12,
+  "fields": {
+    "collection": 2,
+    "title": "Bammie",
+    "file": "original_images/Bammies.jpg",
+    "width": 1700,
+    "height": 1527,
+    "created_at": "2017-02-10T13:27:19.252Z",
+    "uploaded_by_user": 1,
+    "focal_point_x": null,
+    "focal_point_y": null,
+    "focal_point_width": null,
+    "focal_point_height": null,
+    "file_size": null
+  }
+},
+{
+  "model": "wagtailimages.image",
+  "pk": 13,
+  "fields": {
+    "collection": 1,
+    "title": "Bagel",
+    "file": "original_images/Plain-Bagel.jpg",
+    "width": 1920,
+    "height": 1660,
+    "created_at": "2017-02-10T13:28:30.500Z",
+    "uploaded_by_user": 1,
+    "focal_point_x": null,
+    "focal_point_y": null,
+    "focal_point_width": null,
+    "focal_point_height": null,
+    "file_size": null
+  }
+}]

+ 29 - 0
bakerydemo/base/models.py

@@ -19,6 +19,8 @@ from wagtail.wagtailadmin.edit_handlers import (
 from wagtail.wagtailsnippets.models import register_snippet
 from .blocks import BaseStreamBlock
 from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField
+from wagtail.contrib.modeladmin.options import (
+    ModelAdmin, ModelAdminGroup, modeladmin_register)
 
 
 @register_snippet
@@ -47,6 +49,15 @@ class People(ClusterableModel):
         index.SearchField('last_name'),
     ]
 
+    @property
+    def thumb_image(self):
+       # fail silently if there is no profile pic or the rendition file can't
+       # be found. Note @richbrennan worked out how to do this...
+       try:
+           return self.image.get_rendition('fill-50x50').img_tag()
+       except:
+           return ''
+
     def __str__(self):
         return self.first_name + " " + self.last_name
 
@@ -241,3 +252,21 @@ 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)

+ 2 - 10
bakerydemo/settings/dev.py

@@ -1,19 +1,11 @@
 from .base import *
 
-
-# SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = True
-TEMPLATES[0]['OPTIONS']['debug'] = True
-
-# SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = 'CHANGEME!!!'
-
-INTERNAL_IPS = ('127.0.0.1', '10.0.2.2')
-
-BASE_URL = 'http://localhost:8000'
 
 EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
 
+# BASE_URL required for notification emails
+BASE_URL = 'http://localhost:8000'
 
 try:
     from .local import *

+ 0 - 175
bakerydemo/settings/production.py

@@ -1,175 +0,0 @@
-import os
-import dj_database_url
-
-from .base import *
-
-# Do not set SECRET_KEY, Postgres or LDAP password or any other sensitive data here.
-# Instead, use environment variables or create a local.py file on the server.
-
-# Disable debug mode
-DEBUG = False
-TEMPLATES[0]['OPTIONS']['debug'] = False
-
-
-# Configuration from environment variables
-# Alternatively, you can set these in a local.py file on the server
-
-env = os.environ.copy()
-
-# On Torchbox servers, many environment variables are prefixed with "CFG_"
-for key, value in os.environ.items():
-    if key.startswith('CFG_'):
-        env[key[4:]] = value
-
-
-# Basic configuration
-
-APP_NAME = env.get('APP_NAME', 'bakerydemo')
-
-if 'SECRET_KEY' in env:
-    SECRET_KEY = env['SECRET_KEY']
-
-if 'ALLOWED_HOSTS' in env:
-    ALLOWED_HOSTS = env['ALLOWED_HOSTS'].split(',')
-
-if 'PRIMARY_HOST' in env:
-    BASE_URL = 'http://%s/' % env['PRIMARY_HOST']
-
-if 'SERVER_EMAIL' in env:
-    SERVER_EMAIL = env['SERVER_EMAIL']
-
-if 'CACHE_PURGE_URL' in env:
-    INSTALLED_APPS += ( 'wagtail.contrib.wagtailfrontendcache', )
-    WAGTAILFRONTENDCACHE = {
-        'default': {
-            'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
-            'LOCATION': env['CACHE_PURGE_URL'],
-        },
-    }
-
-if 'STATIC_URL' in env:
-    STATIC_URL = env['STATIC_URL']
-
-if 'STATIC_DIR' in env:
-    STATIC_ROOT = env['STATIC_DIR']
-
-if 'MEDIA_URL' in env:
-    MEDIA_URL = env['MEDIA_URL']
-
-if 'MEDIA_DIR' in env:
-    MEDIA_ROOT = env['MEDIA_DIR']
-
-
-# Database
-
-if 'DATABASE_URL' in os.environ:
-    DATABASES = {'default': dj_database_url.config()}
-
-else:
-    DATABASES = {
-        'default': {
-            'ENGINE': 'django.db.backends.postgresql_psycopg2',
-            'NAME': env.get('PGDATABASE', APP_NAME),
-            'CONN_MAX_AGE': 600,  # number of seconds database connections should persist for
-
-            # User, host and port can be configured by the PGUSER, PGHOST and
-            # PGPORT environment variables (these get picked up by libpq).
-        }
-    }
-
-
-# Elasticsearch
-
-if 'ELASTICSEARCH_URL' in env:
-    WAGTAILSEARCH_BACKENDS = {
-        'default': {
-            'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch.ElasticSearch',
-            'URLS': [env['ELASTICSEARCH_URL']],
-            'INDEX': APP_NAME,
-            'ATOMIC_REBUILD': True,
-        },
-    }
-
-
-# Logging
-
-LOGGING = {
-    'version': 1,
-    'disable_existing_loggers': False,
-    'handlers': {
-        'mail_admins': {
-            'level': 'ERROR',
-            'class': 'django.utils.log.AdminEmailHandler',
-        },
-    },
-    'formatters': {
-        'default': {
-            'verbose': '[%(asctime)s] (%(process)d/%(thread)d) %(name)s %(levelname)s: %(message)s'
-        }
-    },
-    'loggers': {
-        'bakerydemo': {
-            'handlers':     [],
-            'level':        'INFO',
-            'propagate':    False,
-            'formatter':    'verbose',
-        },
-        'wagtail': {
-            'handlers':     [],
-            'level':        'INFO',
-            'propagate':    False,
-            'formatter':    'verbose',
-        },
-        'django.request': {
-            'handlers':     ['mail_admins'],
-            'level':        'ERROR',
-            'propagate':    False,
-            'formatter':    'verbose',
-        },
-        'django.security': {
-            'handlers':     ['mail_admins'],
-            'level':        'ERROR',
-            'propagate':    False,
-            'formatter':    'verbose',
-        },
-    },
-}
-
-
-if 'LOG_DIR' in env:
-    # bakerydemo log
-    LOGGING['handlers']['bakerydemo_file'] = {
-        'level':        'INFO',
-        'class':        'cloghandler.ConcurrentRotatingFileHandler',
-        'filename':     os.path.join(env['LOG_DIR'], 'bakerydemo.log'),
-        'maxBytes':     5242880, # 5MB
-        'backupCount':  5
-    }
-    LOGGING['loggers']['wagtail']['handlers'].append('bakerydemo_file')
-
-    # Wagtail log
-    LOGGING['handlers']['wagtail_file'] = {
-        'level':        'INFO',
-        'class':        'cloghandler.ConcurrentRotatingFileHandler',
-        'filename':     os.path.join(env['LOG_DIR'], 'wagtail.log'),
-        'maxBytes':     5242880, # 5MB
-        'backupCount':  5
-    }
-    LOGGING['loggers']['wagtail']['handlers'].append('wagtail_file')
-
-    # Error log
-    LOGGING['handlers']['errors_file'] = {
-        'level':        'ERROR',
-        'class':        'cloghandler.ConcurrentRotatingFileHandler',
-        'filename':     os.path.join(env['LOG_DIR'], 'error.log'),
-        'maxBytes':     5242880, # 5MB
-        'backupCount':  5
-    }
-    LOGGING['loggers']['django.request']['handlers'].append('errors_file')
-    LOGGING['loggers']['django.security']['handlers'].append('errors_file')
-
-
-try:
-    from .local import *
-except ImportError:
-    pass

+ 4 - 4
bakerydemo/templates/about_page.html

@@ -2,12 +2,12 @@
 {% load wagtailimages_tags %}
 
 {% block content %}
-	{{ page.title }}
+    {{ page.title }}
 
     <div class="image">
         {% image page.image width-500 as photo %}
               <img src="{{ photo.url }}" width="{{ photo.width }}" height="{{ photo.height }}" alt="{{ photo.alt }}" />
-	</div>
+    </div>
 
-	{{ page.body }}
-{% endblock content %}
+    {{ page.body }}
+{% endblock content %}

+ 1 - 1
bakerydemo/templates/base/about_page.html

@@ -10,4 +10,4 @@
     </div>
 
     {{ page.body }}
-{% endblock content %}
+{% endblock content %}

+ 1 - 0
bakerydemo/templates/base/form_page.html

@@ -1,5 +1,6 @@
 {% extends "base.html" %}
 {% load wagtailcore_tags %}
+
 {% block content %}
     {{ page.intro|richtext }}
 

+ 1 - 0
bakerydemo/templates/base/form_page_landing.html

@@ -1,5 +1,6 @@
 {% extends "base.html" %}
 {% load wagtailcore_tags %}
+
 {% block content %}
     <h1>{{ page.title }}</h1>
     {{ page.thank_you_text|richtext }}

+ 8 - 8
bakerydemo/templates/blocks/heading_block.html

@@ -1,15 +1,15 @@
 {% if self.size == 'h2' %}
-	    <h2>{{ self.heading_text }}</h2>
+        <h2>{{ self.heading_text }}</h2>
 
-	{% elif self.size == 'h3' %}
-	    <h3>{{ self.heading_text }}</h3>
+    {% elif self.size == 'h3' %}
+        <h3>{{ self.heading_text }}</h3>
 
-	{% elif self.size == 'h4' %}
-	    <h4>{{ self.heading_text }}</h4>
+    {% elif self.size == 'h4' %}
+        <h4>{{ self.heading_text }}</h4>
 
 {% endif %}
 
 {% comment %}
-	Content is coming from the StandardBlock StreamField
-	class within `blocks.py`
-{% endcomment %}
+    Content is coming from the StandardBlock StreamField
+    class within `blocks.py`
+{% endcomment %}

+ 2 - 4
bakerydemo/templates/blocks/image_block.html

@@ -1,8 +1,6 @@
 {% load wagtailimages_tags %}
 
-
-
 <figure>
-  {% image self.image fill-600x600 %}
-      <figcaption>{{ self.caption }} - {{ self.attribution }}</figcaption>
+    {% image self.image fill-600x600 %}
+    <figcaption>{{ self.caption }} - {{ self.attribution }}</figcaption>
 </figure>

+ 1 - 1
bakerydemo/templates/blocks/paragraph_block.html

@@ -1 +1 @@
-        {{ self }}
+{{ self }}

+ 0 - 1
bakerydemo/templates/blog/blog_index_page.html

@@ -3,7 +3,6 @@
 
 {% block content %}
     {{ page.title }}
-
     {% for blog in blogs %}
         <div>
             <h2><a href="{{ blog.full_url }}">{{ blog.title }}</a></h2>

+ 1 - 2
bakerydemo/templates/breads/breads_index_page.html

@@ -3,8 +3,7 @@
 
 {% block content %}
     {{ page.title }}
-
     {% for bread in breads %}
         <div><a href="{{ bread.slug }}">{{ bread.title }}</a></div>
     {% endfor %}
-{% endblock content %}
+{% endblock content %}

+ 0 - 1
bakerydemo/templates/search/search_results.html

@@ -4,7 +4,6 @@
 {% block title %}Search{% if search_results %} results{% endif %}{% endblock %}
 
 {% block content %}
-
     <h1>
         Search results{% if request.GET.query %} for “{{ request.GET.query }}”{% endif %}
     </h1>

+ 0 - 4
bakerydemo/templates/tags/sidebar_menu.html

@@ -2,13 +2,10 @@
 {% get_site_root as site_root %}
 
 {% if calling_page|has_protocol_parent and calling_page.content_type.model == 'standardpage' %}
-
   <div class="off-canvas position-left reveal-for-large bla" id="offCanvasLeft" data-off-canvas>
     {% protocol_menu calling_page=calling_page %}
   </div>
-
 {% elif ancestor.has_children %}
-
   <div class="off-canvas position-left reveal-for-large" id="offCanvasLeft" data-off-canvas>
     <nav class="sidebar-nav">
       <h3>In this section</h3>
@@ -32,5 +29,4 @@
       </ul>
     </nav>
   </div>
-
 {% endif %}

+ 0 - 1
bakerydemo/templates/tags/top_menu.html

@@ -1,7 +1,6 @@
 {% load navigation_tags wagtailcore_tags %}
 {% get_site_root as site_root %}
 
-
 <div class="navigation-bar">
     <ul id="main-menu">
       {% for menuitem in menuitems %}

+ 1 - 0
bakerydemo/templates/tags/top_menu_children.html

@@ -1,4 +1,5 @@
 {% load navigation_tags wagtailcore_tags %}
+
 <ul class="submenu">
   {% for child in menuitems_children %}
     <li><a href="{% pageurl child %}">{{ child.title }}</a></li>

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно