no functional changes:
update format
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
from django.contrib import admin
|
||||
import django.contrib.auth.admin
|
||||
import django.contrib.auth.models
|
||||
import taggit.admin
|
||||
|
||||
from django.contrib import admin, auth
|
||||
|
||||
from .models import Post, Event, News, FetMeeting
|
||||
from .forms import MyPostForm, MyEventForm, MyNewsForm, MyFetMeetingForm
|
||||
|
||||
import django.contrib.auth.admin
|
||||
import django.contrib.auth.models
|
||||
from django.contrib import auth
|
||||
|
||||
admin.site.unregister(auth.models.User)
|
||||
admin.site.unregister(auth.models.Group)
|
||||
import taggit.admin
|
||||
#import taggit.models
|
||||
|
||||
admin.site.unregister(taggit.models.Tag)
|
||||
|
||||
|
||||
@@ -18,7 +16,7 @@ class MyPostAdmin(admin.ModelAdmin):
|
||||
form = MyPostForm
|
||||
model = Post
|
||||
list_filter = ['is_event']
|
||||
list_display = ['title','subtitle','slug','public_date']
|
||||
list_display = ['title', 'subtitle', 'slug', 'public_date']
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
obj.author = request.user
|
||||
@@ -38,7 +36,7 @@ class MyPostAdmin(admin.ModelAdmin):
|
||||
class MyEventAdmin(MyPostAdmin):
|
||||
form = MyEventForm
|
||||
model = Event
|
||||
list_display = ['title','subtitle','slug','event_start','public_date']
|
||||
list_display = ['title', 'subtitle', 'slug', 'event_start', 'public_date']
|
||||
|
||||
admin.site.register(Event, MyEventAdmin)
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
from django import forms
|
||||
from ckeditor_uploader.widgets import CKEditorUploadingWidget
|
||||
from django import forms
|
||||
|
||||
from .models import Post, Event, News, FetMeeting
|
||||
|
||||
|
||||
class MyPostForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Post
|
||||
fields = ['title','subtitle','tags', 'image','body','slug','author']
|
||||
fields = ['title', 'subtitle', 'tags', 'image', 'body', 'slug', 'author']
|
||||
|
||||
widgets = {'body': CKEditorUploadingWidget(config_name='default')}
|
||||
|
||||
@@ -19,8 +20,7 @@ class MyPostForm(forms.ModelForm):
|
||||
class MyNewsForm(MyPostForm):
|
||||
class Meta:
|
||||
model = News
|
||||
fields = ['title','subtitle','tags', 'image','body',
|
||||
'slug','author']
|
||||
fields = ['title', 'subtitle', 'tags', 'image', 'body', 'slug', 'author']
|
||||
|
||||
widgets = {'body': CKEditorUploadingWidget(config_name='default')}
|
||||
|
||||
@@ -30,8 +30,8 @@ class MyNewsForm(MyPostForm):
|
||||
class MyEventForm(MyPostForm):
|
||||
class Meta:
|
||||
model = Event
|
||||
fields = ['title','subtitle','tags', 'image','body',
|
||||
'event_start','event_end', 'event_place','slug','author']
|
||||
fields = ['title', 'subtitle', 'tags', 'image', 'body',
|
||||
'event_start', 'event_end', 'event_place', 'slug', 'author']
|
||||
|
||||
widgets = {'body': CKEditorUploadingWidget(config_name='default')}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
|
||||
urlpatterns=[
|
||||
path('func/tag_complete', views.tag_complete),
|
||||
path('func/slug_calc', views.slug_calc),
|
||||
path('t/<str:tag>',views.tags,name='posts.tags'),
|
||||
path('',views.index,name='posts.index'),
|
||||
path('<str:id>',views.show, name='posts.show'),
|
||||
path('t/<str:tag>', views.tags, name='posts.tags'),
|
||||
path('', views.index, name='posts.index'),
|
||||
path('<str:id>', views.show, name='posts.show'),
|
||||
]
|
||||
@@ -1,5 +1,5 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from collections import deque
|
||||
|
||||
from .models import Post, PostSerializer
|
||||
@@ -12,39 +12,44 @@ from django.core.cache import cache
|
||||
|
||||
from django.utils.text import slugify
|
||||
from django.utils import timezone
|
||||
from django.http import JsonResponse
|
||||
|
||||
|
||||
def get_next_dict():
|
||||
posts=Post.article_objects.order_by('-public_date').values('slug')
|
||||
posts = Post.article_objects.order_by('-public_date').values('slug')
|
||||
print(posts)
|
||||
d={}
|
||||
d = {}
|
||||
print(d)
|
||||
for k,v in enumerate(posts):
|
||||
if k ==len(posts)-1:
|
||||
if k == len(posts) - 1:
|
||||
break
|
||||
d[v['slug']]=posts[k+1]['slug']
|
||||
d[v['slug']] = posts[k+1]['slug']
|
||||
print(d)
|
||||
return d
|
||||
|
||||
# Create your views here.
|
||||
def index(request):
|
||||
posts=deque(Post.objects.order_by('-public_date').all())
|
||||
f=lambda p: p.tags
|
||||
t=map(f, posts)
|
||||
posts = deque(Post.objects.order_by('-public_date').all())
|
||||
f = lambda p: p.tags
|
||||
t = map(f, posts)
|
||||
|
||||
return render(request, 'posts/index.html', {"posts": posts, "tags_list": t })
|
||||
return render(request, 'posts/index.html', {"posts": posts, "tags_list": t})
|
||||
|
||||
def tags(request,tag=""):
|
||||
posts=deque(Post.objects.filter(tags__name=tag))
|
||||
return render(request, 'posts/index.html', {"posts": posts, "tags_list":None })
|
||||
posts = deque(Post.objects.filter(tags__name=tag))
|
||||
return render(request, 'posts/index.html', {"posts": posts, "tags_list": None})
|
||||
|
||||
def show(request,id=None):
|
||||
if id.isdigit() or id is int:
|
||||
p=Post.objects.get(id=int(id))
|
||||
elif id != ""and not id is None:
|
||||
p=Post.objects.get(slug=(id))
|
||||
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})
|
||||
p = Post.objects.get(id=int(id))
|
||||
elif id != "" and not id is None:
|
||||
p = Post.objects.get(slug=(id))
|
||||
|
||||
context = {
|
||||
"post": p,
|
||||
"next": get_next_dict().get(p.slug,None),
|
||||
"related_posts": p.tags.similar_objects()
|
||||
}
|
||||
return render(request, 'posts/show.html', context)
|
||||
|
||||
# Ajax function that is called to calculate a slug from the title
|
||||
def slug_calc(request):
|
||||
@@ -56,7 +61,7 @@ def slug_calc(request):
|
||||
datetime_now = timezone.now()
|
||||
date_str = datetime_now.strftime("%Y-%m-%d")
|
||||
|
||||
slug_str = slugify(date_str)+"-"+slugify(title)
|
||||
slug_str = slugify(date_str) + "-" + slugify(title)
|
||||
|
||||
return HttpResponse(slug_str)
|
||||
|
||||
@@ -88,6 +93,7 @@ class PostViewSet(viewsets.ModelViewSet):
|
||||
#permission_classes = [permissions.IsAuthenticated]
|
||||
filter_backends = [DjangoFilterBackend]
|
||||
filterset_fields = ['legacy_id', 'slug','legacy_rubrik_id']
|
||||
lookup_field='slug'
|
||||
lookup_field = 'slug'
|
||||
|
||||
def pre_save(self, obj):
|
||||
obj.image = self.request.FILES.get('image')
|
||||
|
||||
Reference in New Issue
Block a user