diff --git a/project/projects/__init__.py b/project/projects/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/projects/migrations/0001_initial.py b/project/projects/migrations/0001_initial.py new file mode 100644 index 0000000..96ad005 --- /dev/null +++ b/project/projects/migrations/0001_initial.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2016-11-25 23:10 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import project.projects.models +import wagtail.wagtailcore.fields + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('wagtailcore', '0030_index_on_pagerevision_created_at'), + ('wagtaildocs', '0007_merge'), + ('wagtailimages', '0015_fill_filter_spec_field'), + ] + + operations = [ + migrations.CreateModel( + name='ProjectPage', + 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')), + ('date', models.DateField(verbose_name='Post date')), + ('intro', models.CharField(max_length=250)), + ('body', wagtail.wagtailcore.fields.RichTextField()), + ('url', models.URLField(blank=True, validators=[project.projects.models.validate_url])), + ('download_url', models.URLField(blank=True, validators=[project.projects.models.validate_url])), + ('asset', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtaildocs.Document')), + ('main_image', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')), + ], + options={ + 'abstract': False, + }, + bases=('wagtailcore.page',), + ), + ] diff --git a/project/projects/migrations/__init__.py b/project/projects/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/projects/models.py b/project/projects/models.py new file mode 100644 index 0000000..f4afaf0 --- /dev/null +++ b/project/projects/models.py @@ -0,0 +1,60 @@ +from django.db import models +from django.core.exceptions import ValidationError + +from wagtail.wagtailcore.models import Page +from wagtail.wagtailcore.fields import RichTextField +from wagtail.wagtaildocs.edit_handlers import DocumentChooserPanel +from wagtail.wagtailadmin.edit_handlers import FieldPanel +from wagtail.wagtailimages.edit_handlers import ImageChooserPanel +from wagtail.wagtailsearch import index + +from project.common.models import Entity + + +ALLOWED_DOMAINS = [ + 'github' +] + + +def validate_url(value): + for part in ALLOWED_DOMAINS: + if part in value.lower(): + return True + raise ValidationError('Invalid domain, should be in {}'.format(ALLOWED_DOMAINS)) + + +class ProjectPage(Entity): + main_image = models.ForeignKey( + 'wagtailimages.Image', + null=True, + blank=True, + on_delete=models.SET_NULL, + related_name='+' + ) + date = models.DateField("Post date") + intro = models.CharField(max_length=250) + body = RichTextField() + url = models.URLField(validators=[validate_url], blank=True) + download_url = models.URLField(validators=[validate_url], blank=True) + asset = models.ForeignKey( + 'wagtaildocs.Document', + null=True, + blank=True, + on_delete=models.SET_NULL, + related_name='+' + ) + + search_fields = Page.search_fields + [ + index.SearchField('intro'), + index.SearchField('body'), + ] + + content_panels = Page.content_panels + [ + FieldPanel('date'), + ImageChooserPanel('main_image'), + FieldPanel('intro'), + FieldPanel('body'), + FieldPanel('url'), + FieldPanel('download_url'), + DocumentChooserPanel('asset') + ] diff --git a/project/settings.py b/project/settings.py index 677b36e..8d4edc3 100755 --- a/project/settings.py +++ b/project/settings.py @@ -48,6 +48,7 @@ INSTALLED_APPS = [ 'project.blog', 'project.common', 'project.home', + 'project.projects', 'project.search', ]