Compare commits
No commits in common. "76d25a637005e946bf3982a803759e72d2274dcd" and "7acbbe32c3a6d84184d3a115565cedb1e1b082fb" have entirely different histories.
76d25a6370
...
7acbbe32c3
BIN
news1/db.sqlite3
BIN
news1/db.sqlite3
Binary file not shown.
@ -38,7 +38,6 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'posts',
|
'posts',
|
||||||
'rest_framework',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@ -106,7 +105,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'de-de'
|
LANGUAGE_CODE = 'en-us'
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'UTC'
|
||||||
|
|
||||||
|
@ -18,7 +18,5 @@ from django.urls import path, include
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('posts/' , include('posts.urls')),
|
path('posts/' , include('posts.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('accounts/' , include('django.contrib.auth.urls')),
|
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from.import views
|
from.import views
|
||||||
|
|
||||||
|
|
||||||
urlpatterns =[
|
urlpatterns =[
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
path('new', views.new, name='new'),
|
|
||||||
path('delete/<int:deleteId>', views.delete, name='delete'),
|
|
||||||
path('notices/', views.notice_list),
|
|
||||||
path('notices/<int:id>/', views.notice_detail),
|
|
||||||
]
|
]
|
||||||
|
@ -1,71 +1,17 @@
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.shortcuts import render
|
||||||
from django.shortcuts import render, redirect
|
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
|
||||||
from rest_framework.parsers import JSONParser
|
|
||||||
|
|
||||||
from posts.forms import NoticeForm
|
|
||||||
from posts.serializers import NoticeSerializer
|
|
||||||
from.models import Notice
|
from.models import Notice
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.http import HttpResponse, JsonResponse
|
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
notices= Notice.objects.all()
|
notices= Notice.objects.all()
|
||||||
notices= notices.filter(pub_start__lte=timezone.now())
|
notices= notices.filter(pub_start__lte=timezone.now())
|
||||||
notices= notices.filter(pub_end__gte= timezone.now())
|
notices= notices.filter(pub_end__gte= timezone.now())
|
||||||
context={"notices":notices}
|
context={"notices":notices}
|
||||||
return render(request, 'posts/notice.html', context)
|
return render(request, 'posts/notice.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
|
||||||
def new(request):
|
|
||||||
if request.method == "POST":
|
|
||||||
form = NoticeForm(request.POST)
|
|
||||||
if form.is_valid():
|
|
||||||
newNotice = Notice(notice_title=form.cleaned_data['title'],
|
|
||||||
notice_text=form.cleaned_data['text'],
|
|
||||||
pub_start=form.cleaned_data['start'],
|
|
||||||
pub_end=form.cleaned_data['end'])
|
|
||||||
newNotice.save()
|
|
||||||
return redirect('index')
|
|
||||||
context = {'form': NoticeForm()}
|
|
||||||
return render(request, 'posts/edit.html', context)
|
|
||||||
|
|
||||||
def delete(request, deleteId=None):
|
|
||||||
if deleteId !=None:
|
|
||||||
delNotice= Notice.objects.get(id=deleteId)
|
|
||||||
if delNotice!= None:
|
|
||||||
delNotice.delete()
|
|
||||||
return redirect('index')
|
|
||||||
@csrf_exempt
|
|
||||||
def notice_list(request):
|
|
||||||
if request.method == 'GET':
|
|
||||||
notices = Notice.objects.all()
|
|
||||||
serializer = NoticeSerializer(notices, many=True)
|
|
||||||
return JsonResponse(serializer.data, safe=False)
|
|
||||||
elif request.method=='POST':
|
|
||||||
data = JSONParser().parse(request)
|
|
||||||
serializer = NoticeSerializer(data=data)
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save()
|
|
||||||
return JsonResponse(serializer.data, status=201)
|
|
||||||
return JsonResponse(serializer.errors, status=201)
|
|
||||||
@csrf_exempt
|
|
||||||
def notice_detail(request, id):
|
|
||||||
try:
|
|
||||||
notice= Notice.objects.get(id =id)
|
|
||||||
except Notice.DoesNotExist:
|
|
||||||
return HttpResponse(status=404)
|
|
||||||
if request.method =='GET':
|
|
||||||
serializer = NoticeSerializer(notice)
|
|
||||||
return JsonResponse(serializer.data)
|
|
||||||
elif request.method =='PUT':
|
|
||||||
data = JSONParser().parse(request)
|
|
||||||
serializer = NoticeSerializer(notice, data=data)
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save()
|
|
||||||
return JsonResponse(serializer.data)
|
|
||||||
return JsonResponse(serializer.errors, status=400)
|
|
||||||
elif request.method == 'DELETE':
|
|
||||||
notice.delete()
|
|
||||||
return HttpResponse(status=204)
|
|
Loading…
x
Reference in New Issue
Block a user