Taking in changes from andis

This commit is contained in:
2020-06-13 00:26:41 +02:00
3 changed files with 25 additions and 4 deletions

View File

@@ -65,7 +65,7 @@ ROOT_URLCONF = 'fet2020.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates_design1')],
'DIRS': [os.path.join(BASE_DIR, 'templates'),os.path.join(BASE_DIR, 'templates_design1')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [

View File

@@ -13,6 +13,9 @@ from django.db.models import Q
from datetime import timedelta
import logging
logger = logging.getLogger('posts')
#TODO: is_fetsitzung -> is_fetmeeting
############
@@ -108,11 +111,27 @@ class Post(models.Model):
if self.image:
return self.image.url
else:
return ""
image=self.find_an_image()
if image:
return image.url
else:
return ""
def key(self):
return self.slug or self.id
def find_an_image(self):
"find an image via another post"
posts1=Post.objects.filter(slug__in=self.tags.names()).filter(image__isnull=False)[0:1].all() # Query all posts that have a slug that equals one of the tags
if len(posts1)>0:
return posts1.get().image
posts2=self.tags.similar_objects()
for p in posts2:
if p.image is not None:
return p.image
return None
@property
def url(self):
return reverse('posts.show', kwargs={"id":self.slug})
@@ -136,6 +155,7 @@ class PostSerializer(serializers.HyperlinkedModelSerializer):
fields = ['slug', 'title', 'subtitle', 'body', 'url', 'public_date',
'legacy_id', 'image', 'event_start', 'event_end',
'is_fetsitzung']
class News(Post):
class Meta:
proxy = True

View File

@@ -43,7 +43,8 @@ def show(request,id=None):
p=Post.objects.get(id=int(id))
elif id != ""and not id is None:
p=Post.objects.get(slug=(id))
return render(request, 'posts/show.html', {"post":p,"next":get_next_dict().get(p.slug,None)})
similar_posts = p.tags.similar_objects()
return render(request, 'posts/show.html', {"post":p,"next":get_next_dict().get(p.slug,None), "related_posts": similar_posts})
# Ajax function that is called to calculate a slug from the title
def slug_calc(request):