diff --git a/cms/models.py b/cms/models.py
index 019fb89..69e8e6a 100644
--- a/cms/models.py
+++ b/cms/models.py
@@ -12,6 +12,36 @@ from django.dispatch import receiver
from taggit.managers import TaggableManager
+from aircox.cms import routes
+
+
+class ProxyPost:
+ """
+ Class used to simulate a Post model when it is required to render an
+ item linked to a Post but that is not that itself. This is to ensure
+ the right attributes are set.
+ """
+ detail_url = None
+ date = None
+ image = None
+ title = None
+ content = None
+
+ def __init__(self, post = None, **kwargs):
+ if post:
+ self.update_empty(post)
+ self.__dict__.update(**kwargs)
+
+ def update_empty(self, thread):
+ """
+ Update empty fields using thread object
+ """
+ for i in ('date', 'image', 'title', 'content'):
+ if not getattr(self, i):
+ setattr(self, i, getattr(thread, i))
+ if not self.detail_url:
+ self.detail_url = thread.detail_url()
+
class Post (models.Model):
"""
@@ -64,6 +94,14 @@ class Post (models.Model):
blank = True,
)
+ search_fields = [ 'title', 'content' ]
+
+ def get_proxy(self):
+ """
+ Return a ProxyPost instance using this post
+ """
+ return ProxyPost(self)
+
@classmethod
def children_of(cl, thread, queryset = None):
"""
@@ -77,10 +115,15 @@ class Post (models.Model):
thread_type__pk = thread_type.id)
return qs
- def detail_url (self):
- return reverse(self._website.name_of_model(self.__class__) + '_detail',
- kwargs = { 'pk': self.pk,
- 'slug': slugify(self.title) })
+ def detail_url(self):
+ return self.route_url(routes.DetailRoute,
+ { 'pk': self.pk, 'slug': slugify(self.title) })
+
+ @classmethod
+ def route_url(cl, route, kwargs = None):
+ name = cl._website.name_of_model(cl)
+ name = route.get_view_name(name)
+ return reverse(name, kwargs = kwargs)
class Meta:
abstract = True
@@ -170,6 +213,7 @@ class RelatedPostBase (models.base.ModelBase):
}.items() if not attrs.get(x) })
model = super().__new__(cl, name, bases, attrs)
+ print(model, model.related)
cl.register(rel.model, model)
# name clashes
@@ -317,7 +361,7 @@ class RelatedPost (Post, metaclass = RelatedPostBase):
super().__init__(*kargs, **kwargs)
# we use this method for sync, in order to avoid intrusive code on other
# applications, e.g. using signals.
- if self._relation.rel_to_post:
+ if self.pk and self._relation.rel_to_post:
self.rel_to_post(save = False)
def save (self, *args, **kwargs):
diff --git a/cms/routes.py b/cms/routes.py
index fda6e03..10c0708 100644
--- a/cms/routes.py
+++ b/cms/routes.py
@@ -1,3 +1,4 @@
+from django.db import models
from django.conf.urls import url
from django.contrib.contenttypes.models import ContentType
from django.utils import timezone
@@ -118,7 +119,7 @@ class ThreadRoute(Route):
thread_model = ContentType.objects.get_for_model(thread_model)
return model.objects.filter(
thread_type = thread_model,
- thread_pk = int(pk)
+ thread_id = int(pk)
)
@@ -143,15 +144,16 @@ class SearchRoute(Route):
name = 'search'
@classmethod
- def get_queryset(cl, website, model, request, q, **kwargs):
- qs = model.objects
+ def get_queryset(cl, website, model, request, **kwargs):
+ q = request.GET.get('q') or ''
+ qs = None
+
for search_field in model.search_fields or []:
- r = model.objects.filter(**{ search_field + '__icontains': q })
+ r = models.Q(**{ search_field + '__icontains': q })
if qs: qs = qs | r
else: qs = r
- qs.distinct()
- return qs
+ return model.objects.filter(qs).distinct()
## TODO: by tag
diff --git a/cms/static/aircox/cms/styles.css b/cms/static/aircox/cms/styles.css
index 8c2406d..d18f4f5 100644
--- a/cms/static/aircox/cms/styles.css
+++ b/cms/static/aircox/cms/styles.css
@@ -24,9 +24,10 @@ body {
vertical-align: top;
}
+
main .section {
- width: calc(50% - 2em);
- display: inline-block;
+/* width: calc(50% - 2em);
+ display: inline-block; */
padding: 0.5em;
}
diff --git a/cms/templates/aircox/cms/base_content.html b/cms/templates/aircox/cms/base_content.html
deleted file mode 100644
index 93b8ff5..0000000
--- a/cms/templates/aircox/cms/base_content.html
+++ /dev/null
@@ -1,8 +0,0 @@
-{% block pre_title %}
-{% endblock %}
-{% block title %}
-{% endblock %}
-{% block content %}
-{% endblock %}
-
-
diff --git a/cms/templates/aircox/cms/base_section.html b/cms/templates/aircox/cms/base_section.html
deleted file mode 100644
index 4a054b6..0000000
--- a/cms/templates/aircox/cms/base_section.html
+++ /dev/null
@@ -1,9 +0,0 @@
-
-<{{ tag }} class="section {{ classes }}"
- {% for key, value in attrs.items %}{{ key }} = "{{ value|addslashes }}"
- {% endfor %} >
-{% block content %}
-{{ content|safe }}
-{% endblock %}
-{{ tag }}>
-
diff --git a/cms/templates/aircox/cms/content_object.html b/cms/templates/aircox/cms/content_object.html
new file mode 100644
index 0000000..5353c9c
--- /dev/null
+++ b/cms/templates/aircox/cms/content_object.html
@@ -0,0 +1,8 @@
+
+<{{ tag }} class="{{ classes }}"
+ {% for k, v in attrs.items %}{{ k }} = "{{ v|addslashes }}" {% endfor %} >
+ {% block content %}
+ {{ content|safe }}
+ {% endblock %}
+{{ tag }}>
+
diff --git a/cms/templates/aircox/cms/detail.html b/cms/templates/aircox/cms/detail.html
index dc1d37a..e50fe53 100644
--- a/cms/templates/aircox/cms/detail.html
+++ b/cms/templates/aircox/cms/detail.html
@@ -1,4 +1,4 @@
-{% extends embed|yesno:"aircox/cms/base_content.html,aircox/cms/base_site.html" %}
+{% extends "aircox/cms/website.html" %}
{% load aircox_cms %}
{% block title %}
@@ -29,8 +29,6 @@
{% endblock %}
{% block content %}
-{% for section in sections %}
-{{ section|safe }}
-{% endfor %}
+{{ content }}
{% endblock %}
diff --git a/cms/templates/aircox/cms/list.html b/cms/templates/aircox/cms/list.html
index abce834..9786b7b 100644
--- a/cms/templates/aircox/cms/list.html
+++ b/cms/templates/aircox/cms/list.html
@@ -1,4 +1,4 @@
-{% extends embed|yesno:"aircox/cms/base_content.html,aircox/cms/base_site.html" %}
+{% extends "aircox/cms/website.html" %}
{% load i18n %}
{% load thumbnail %}
@@ -23,7 +23,7 @@
{% endif %}
- {% if 'image' in view.fields %}
+ {% if 'image' in view.fields and post.image %}
{% endif %}
diff --git a/cms/templates/aircox/cms/section.html b/cms/templates/aircox/cms/section.html
index 494006c..afecc88 100644
--- a/cms/templates/aircox/cms/section.html
+++ b/cms/templates/aircox/cms/section.html
@@ -1,4 +1,4 @@
-{% extends "aircox/cms/base_section.html" %}
+{% extends "aircox/cms/content_object.html" %}
{% block content %}
{% if title %}
@@ -30,5 +30,5 @@
{% endblock %}
{% endif %}
-
{% endblock %}
+
diff --git a/cms/templates/aircox/cms/section_list.html b/cms/templates/aircox/cms/section_list.html
index c28de59..8ca6106 100644
--- a/cms/templates/aircox/cms/section_list.html
+++ b/cms/templates/aircox/cms/section_list.html
@@ -2,7 +2,7 @@
{% load thumbnail %}
-{% block section_content %}
+% block section_content %}