123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import logging
- from django.shortcuts import render, redirect, render_to_response
- from django.http import HttpResponse
- from django.utils import timezone
- from django.contrib import messages
-
- from .models import Notice
- from .forms import NoticeForm
-
- logger = None
-
- def init_loger(logger_type):
- global logger
- if logger == None:
- logger = logging.getLogger()
- logger.setLevel(logging.DEBUG)
- logger.addHandler(logging.StreamHandler())
-
- # Create your views here.
- def index(request):
- init_loger('django.db.backends')
- notices = Notice.objects.all()
- notices = Notice.objects.filter(pub_start__lte=timezone.now(), pub_end__gte=timezone.now())
- message = ""
-
- context = {
- "notices": notices,
- 'message': message,
- }
- return render(request, 'posts/index.html', context)
-
- 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('posts')
-
- context = {'form' : NoticeForm()}
- return render(request, 'posts/edit.html', context)
-
- def delete(request, deleteId=None):
- init_loger(__name__)
- logger.info(deleteId)
- message = ""
- if deleteId:
- delNotice = Notice.objects.get(id=deleteId)
- if delNotice:
- delNotice.delete()
- message = "Notice has been deleted."
- return redirect('posts')
-
-
|