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