Merge branch 'master' of https://code.with.camp/CAMP/camp
This commit is contained in:
commit
f26ddd3a41
|
@ -45,7 +45,6 @@ class MaxLengthAdminMarkdownxWidget(AdminMarkdownxWidget):
|
||||||
if not attrs:
|
if not attrs:
|
||||||
attrs = {}
|
attrs = {}
|
||||||
attrs['maxlength'] = 250
|
attrs['maxlength'] = 250
|
||||||
print(dir(self))
|
|
||||||
return super(MaxLengthAdminMarkdownxWidget, self).get_context(name, value, attrs)
|
return super(MaxLengthAdminMarkdownxWidget, self).get_context(name, value, attrs)
|
||||||
|
|
||||||
class Media:
|
class Media:
|
||||||
|
@ -70,7 +69,7 @@ class ContentAdmin(admin.ModelAdmin):
|
||||||
list_filter = ['datestart', 'type']
|
list_filter = ['datestart', 'type']
|
||||||
search_fields = ['title', 'body', 'header', 'shortname']
|
search_fields = ['title', 'body', 'header', 'shortname']
|
||||||
raw_id_fields = ['photo']
|
raw_id_fields = ['photo']
|
||||||
inlines = [ContentParentsInline, FileInline, LinkInline]
|
inlines = [FileInline, LinkInline]
|
||||||
formfield_overrides = {
|
formfield_overrides = {
|
||||||
models.TextField: {'widget': MaxLengthAdminMarkdownxWidget},
|
models.TextField: {'widget': MaxLengthAdminMarkdownxWidget},
|
||||||
}
|
}
|
||||||
|
|
33
content/migrations/0011_auto_20180822_1832.py
Normal file
33
content/migrations/0011_auto_20180822_1832.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.8 on 2018-08-22 18:32
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import markdownx.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('content', '0010_auto_20180222_1319'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='content',
|
||||||
|
name='photo',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='main_photo', to='photologue.Photo'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='content',
|
||||||
|
name='schedule',
|
||||||
|
field=markdownx.models.MarkdownxField(blank=True, default='', null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='content',
|
||||||
|
name='teaser',
|
||||||
|
field=models.TextField(blank=True, null=True, validators=[django.core.validators.MaxLengthValidator(250)]),
|
||||||
|
),
|
||||||
|
]
|
21
content/migrations/0012_content_related_content.py
Normal file
21
content/migrations/0012_content_related_content.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.8 on 2018-08-22 19:08
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
import sortedm2m.fields
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('content', '0011_auto_20180822_1832'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='content',
|
||||||
|
name='related_content',
|
||||||
|
field=sortedm2m.fields.SortedManyToManyField(help_text=None, to='content.Content'),
|
||||||
|
),
|
||||||
|
]
|
23
content/migrations/0013_related.py
Normal file
23
content/migrations/0013_related.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.8 on 2018-08-22 19:08
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
def migrate_relations(apps, schema_editor):
|
||||||
|
Content = apps.get_model("content", "Content")
|
||||||
|
for c in Content.objects.all():
|
||||||
|
for r in c.parents.all():
|
||||||
|
c.related_content.add(r)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('content', '0012_content_related_content'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(migrate_relations),
|
||||||
|
]
|
||||||
|
|
23
content/migrations/0014_migrate_shortname.py
Normal file
23
content/migrations/0014_migrate_shortname.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.8 on 2018-08-22 19:08
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
def migrate_shortname(apps, schema_editor):
|
||||||
|
Content = apps.get_model("content", "Content")
|
||||||
|
for c in Content.objects.filter(shortname__contains=' '):
|
||||||
|
c.shortname = c.shortname.replace(' ', '_')
|
||||||
|
c.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('content', '0013_related'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(migrate_shortname),
|
||||||
|
]
|
||||||
|
|
|
@ -6,10 +6,14 @@ from django.core.validators import MaxLengthValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.html import mark_safe
|
from django.utils.html import mark_safe
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
from django.db.models.signals import m2m_changed
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
|
||||||
from photologue.models import Photo, Gallery
|
from photologue.models import Photo, Gallery
|
||||||
from markdownx.models import MarkdownxField
|
from markdownx.models import MarkdownxField
|
||||||
from markdownx.utils import markdownify
|
from markdownx.utils import markdownify
|
||||||
|
from sortedm2m.fields import SortedManyToManyField
|
||||||
import ox
|
import ox
|
||||||
import lxml.html
|
import lxml.html
|
||||||
|
|
||||||
|
@ -95,6 +99,8 @@ class Content(models.Model):
|
||||||
place = models.CharField(max_length=255, null=True, blank=True)
|
place = models.CharField(max_length=255, null=True, blank=True)
|
||||||
parents = models.ManyToManyField('Content', through='ContentContent', related_name="children")
|
parents = models.ManyToManyField('Content', through='ContentContent', related_name="children")
|
||||||
|
|
||||||
|
related_content = SortedManyToManyField('Content', related_name='reverse_related_content')
|
||||||
|
|
||||||
resources = models.ManyToManyField('Resources', through='ContentResource', related_name="content")
|
resources = models.ManyToManyField('Resources', through='ContentResource', related_name="content")
|
||||||
gallery = models.ForeignKey(Gallery, null=True, blank=True, related_name="content")
|
gallery = models.ForeignKey(Gallery, null=True, blank=True, related_name="content")
|
||||||
|
|
||||||
|
@ -176,6 +182,19 @@ class Content(models.Model):
|
||||||
managed = True
|
managed = True
|
||||||
db_table = 'content'
|
db_table = 'content'
|
||||||
|
|
||||||
|
def reverse(self):
|
||||||
|
ids = set(self.related_content.all().values_list('id', flat=True))
|
||||||
|
for r in self.reverse_related_content.exclude(id__in=ids):
|
||||||
|
self.reverse_related_content.remove(r)
|
||||||
|
reverse_ids = set(self.reverse_related_content.all().values_list('id', flat=True))
|
||||||
|
for r in self.related_content.filter(id__in=ids - reverse_ids):
|
||||||
|
self.reverse_related_content.add(r)
|
||||||
|
|
||||||
|
@receiver(m2m_changed, sender='content.Content_related_content')
|
||||||
|
def post_save_reverse(sender, **kwargs):
|
||||||
|
if kwargs.get('action') == 'post_add':
|
||||||
|
c = kwargs['instance']
|
||||||
|
c.reverse()
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class ContentContent(models.Model):
|
class ContentContent(models.Model):
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div class="large-4 medium-4 columns">
|
<div class="large-4 medium-4 columns">
|
||||||
{% include "related.html" with related=content.children.all %}
|
{% include "related.html" with related=content.related_content.all %}
|
||||||
{% if latest_content_list %}
|
{% if latest_content_list %}
|
||||||
<h4 class="sidebar-h4">{{section}}</h4>
|
<h4 class="sidebar-h4">{{section}}</h4>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user