-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 85d4ec6
Showing
33 changed files
with
641 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.py[cod] | ||
spiderproject/*.scrapy_log | ||
.DS_Store | ||
|
||
env/ | ||
deploy/ | ||
/static_pub/ | ||
fabfile.py |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class BlogConfig(AppConfig): | ||
name = 'blog' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generated by Django 2.0.9 on 2018-10-16 02:30 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import modelcluster.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('wagtailcore', '0040_page_draft_title'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='BlogCategory', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255)), | ||
('slug', models.SlugField(max_length=80, unique=True)), | ||
], | ||
options={ | ||
'verbose_name_plural': 'Categories', | ||
'verbose_name': 'Category', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='PostPage', | ||
fields=[ | ||
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')), | ||
('categories', modelcluster.fields.ParentalManyToManyField(blank=True, to='blog.BlogCategory')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=('wagtailcore.page',), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 2.0.9 on 2018-10-16 02:37 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import modelcluster.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('blog', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='BlogPageBlogCategory', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('blog_category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_pages', to='blog.BlogCategory')), | ||
('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='categories2', to='blog.PostPage')), | ||
], | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='blogpageblogcategory', | ||
unique_together={('page', 'blog_category')}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
import datetime | ||
from datetime import date | ||
|
||
import wagtail | ||
from django import forms | ||
from django.db import models | ||
from django.http import Http404, HttpResponse | ||
from django.utils.dateformat import DateFormat | ||
from django.utils.formats import date_format | ||
from modelcluster.fields import ParentalKey, ParentalManyToManyField | ||
from modelcluster.tags import ClusterTaggableManager | ||
from taggit.models import Tag as TaggitTag | ||
from taggit.models import TaggedItemBase | ||
from wagtail.admin.edit_handlers import (FieldPanel, FieldRowPanel, | ||
InlinePanel, MultiFieldPanel, | ||
PageChooserPanel, StreamFieldPanel) | ||
from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField | ||
from wagtail.contrib.routable_page.models import RoutablePageMixin, route | ||
from wagtail.core import blocks | ||
from wagtail.core.fields import RichTextField, StreamField | ||
from wagtail.core.models import Page | ||
from wagtail.embeds.blocks import EmbedBlock | ||
from wagtail.images.blocks import ImageChooserBlock | ||
from wagtail.images.edit_handlers import ImageChooserPanel | ||
from wagtail.snippets.models import register_snippet | ||
from wagtail.snippets.edit_handlers import SnippetChooserPanel | ||
|
||
# Create your models here. | ||
|
||
class PostPage(Page): | ||
categories = ParentalManyToManyField('blog.BlogCategory', blank=True) | ||
|
||
content_panels = Page.content_panels + [ | ||
FieldPanel('categories', widget=forms.CheckboxSelectMultiple), | ||
InlinePanel('categories2', label='category'), | ||
] | ||
|
||
|
||
@register_snippet | ||
class BlogCategory(models.Model): | ||
name = models.CharField(max_length=255) | ||
slug = models.SlugField(unique=True, max_length=80) | ||
|
||
panels = [ | ||
FieldPanel('name'), | ||
FieldPanel('slug'), | ||
] | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
class Meta: | ||
verbose_name = "Category" | ||
verbose_name_plural = "Categories" | ||
|
||
|
||
class BlogPageBlogCategory(models.Model): | ||
page = ParentalKey('blog.PostPage', on_delete=models.CASCADE, related_name='categories2') | ||
blog_category = models.ForeignKey( | ||
'blog.BlogCategory', on_delete=models.CASCADE, related_name='blog_pages') | ||
|
||
panels = [ | ||
SnippetChooserPanel('blog_category'), | ||
] | ||
|
||
class Meta: | ||
unique_together = ('page', 'blog_category') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('wagtailcore', '0040_page_draft_title'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='HomePage', | ||
fields=[ | ||
('page_ptr', models.OneToOneField(on_delete=models.CASCADE, parent_link=True, auto_created=True, primary_key=True, serialize=False, to='wagtailcore.Page')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=('wagtailcore.page',), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.db import migrations | ||
|
||
|
||
def create_homepage(apps, schema_editor): | ||
# Get models | ||
ContentType = apps.get_model('contenttypes.ContentType') | ||
Page = apps.get_model('wagtailcore.Page') | ||
Site = apps.get_model('wagtailcore.Site') | ||
HomePage = apps.get_model('home.HomePage') | ||
|
||
# Delete the default homepage | ||
# If migration is run multiple times, it may have already been deleted | ||
Page.objects.filter(id=2).delete() | ||
|
||
# Create content type for homepage model | ||
homepage_content_type, __ = ContentType.objects.get_or_create( | ||
model='homepage', app_label='home') | ||
|
||
# Create a new homepage | ||
homepage = HomePage.objects.create( | ||
title="Home", | ||
draft_title="Home", | ||
slug='home', | ||
content_type=homepage_content_type, | ||
path='00010001', | ||
depth=2, | ||
numchild=0, | ||
url_path='/home/', | ||
) | ||
|
||
# Create a site with the new homepage set as the root | ||
Site.objects.create( | ||
hostname='localhost', root_page=homepage, is_default_site=True) | ||
|
||
|
||
def remove_homepage(apps, schema_editor): | ||
# Get models | ||
ContentType = apps.get_model('contenttypes.ContentType') | ||
HomePage = apps.get_model('home.HomePage') | ||
|
||
# Delete the default homepage | ||
# Page and Site objects CASCADE | ||
HomePage.objects.filter(slug='home', depth=2).delete() | ||
|
||
# Delete content type for homepage model | ||
ContentType.objects.filter(model='homepage', app_label='home').delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('home', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(create_homepage, remove_homepage), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.db import models | ||
|
||
from wagtail.core.models import Page | ||
|
||
|
||
class HomePage(Page): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block body_class %}template-homepage{% endblock %} | ||
|
||
{% block content %} | ||
<h1>Welcome to your new Wagtail site!</h1> | ||
|
||
<p>You can access the admin interface <a href="{% url 'wagtailadmin_home' %}">here</a> (make sure you have run "./manage.py createsuperuser" in the console first).</p> | ||
|
||
<p>If you haven't already given the documentation a read, head over to <a href="http://docs.wagtail.io/">http://docs.wagtail.io</a> to start building on Wagtail</p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "wagtail_parentalmanytomanyfield_example.settings.dev") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Django>=2.0,<2.1 | ||
wagtail>=2.2,<2.3 | ||
isort |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{% extends "base.html" %} | ||
{% load static wagtailcore_tags %} | ||
|
||
{% block body_class %}template-searchresults{% endblock %} | ||
|
||
{% block title %}Search{% endblock %} | ||
|
||
{% block content %} | ||
<h1>Search</h1> | ||
|
||
<form action="{% url 'search' %}" method="get"> | ||
<input type="text" name="query"{% if search_query %} value="{{ search_query }}"{% endif %}> | ||
<input type="submit" value="Search" class="button"> | ||
</form> | ||
|
||
{% if search_results %} | ||
<ul> | ||
{% for result in search_results %} | ||
<li> | ||
<h4><a href="{% pageurl result %}">{{ result }}</a></h4> | ||
{% if result.search_description %} | ||
{{ result.search_description }} | ||
{% endif %} | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
{% if search_results.has_previous %} | ||
<a href="{% url 'search' %}?query={{ search_query|urlencode }}&page={{ search_results.previous_page_number }}">Previous</a> | ||
{% endif %} | ||
|
||
{% if search_results.has_next %} | ||
<a href="{% url 'search' %}?query={{ search_query|urlencode }}&page={{ search_results.next_page_number }}">Next</a> | ||
{% endif %} | ||
{% elif search_query %} | ||
No results found | ||
{% endif %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator | ||
from django.shortcuts import render | ||
|
||
from wagtail.core.models import Page | ||
from wagtail.search.models import Query | ||
|
||
|
||
def search(request): | ||
search_query = request.GET.get('query', None) | ||
page = request.GET.get('page', 1) | ||
|
||
# Search | ||
if search_query: | ||
search_results = Page.objects.live().search(search_query) | ||
query = Query.get(search_query) | ||
|
||
# Record hit | ||
query.add_hit() | ||
else: | ||
search_results = Page.objects.none() | ||
|
||
# Pagination | ||
paginator = Paginator(search_results, 10) | ||
try: | ||
search_results = paginator.page(page) | ||
except PageNotAnInteger: | ||
search_results = paginator.page(1) | ||
except EmptyPage: | ||
search_results = paginator.page(paginator.num_pages) | ||
|
||
return render(request, 'search/search.html', { | ||
'search_query': search_query, | ||
'search_results': search_results, | ||
}) |
Empty file.
Empty file.
Oops, something went wrong.