#!/usr/bin/env python
#coding:utf-8

from django.http import HttpResponse,Http404
from .models import FikanoteDB, AgendaDB, Shownote
from django.template import RequestContext
from shownoteform import ShownoteForm
from agendaform import AgendaForm
from django.shortcuts import render
import json
import datetime

def shownote(request):
    if request.method == 'GET': 
        agendas = AgendaDB.objects().order_by('-date')
        return render(request, 'edit_shownote.html', 
                      {'agendas': agendas 
                       , 'agendaform': AgendaForm()
                       , 'shownoteform': ShownoteForm() 
                       } )

    elif request.method == 'POST': 
        form = ShownoteForm(request.POST) 
        if form.is_valid(): 
            number = FikanoteDB.objects().count()+1
            # add to shownote
            shownotes = []
            list_title = request.POST.getlist('agenda_title')
            list_url = request.POST.getlist('agenda_url')
            list_id = request.POST.getlist('agenda_id')
            for i in range(len(list_title)):
                shownotes.append(Shownote(title=list_title[i], url=list_url[i]))
            FikanoteDB(number = number
                       , title=form.cleaned_data['title']
                       , person=form.cleaned_data['person'].split(",")
                       , agenda=form.cleaned_data['agenda']
                       , date=datetime.datetime.utcnow()
                       , shownotes=shownotes
                       ).save()
            # delete id's item from agendadb
            for i in range(len(list_id)):
                AgendaDB.objects.filter(id__exact=list_id[i]).delete()

        return HttpResponseRedirect('/') 
        
    else:
        raise Http404

#!/usr/bin/env python
#coding:utf-8

from django.http import HttpResponse,Http404,HttpResponseRedirect
from .models import FikanoteDB, AgendaDB, Shownote
from django.template import RequestContext
from shownoteform import ShownoteForm
from agendaform import AgendaForm
from django.shortcuts import render
import json
import datetime

def shownote(request):
    if request.method == 'GET': 
        agendas = AgendaDB.objects().order_by('-date')
        return render(request, 'edit_shownote.html', 
                      {'agendas': agendas 
                       , 'agendaform': AgendaForm()
                       , 'shownoteform': ShownoteForm() 
                       } )

    elif request.method == 'POST': 
        form = ShownoteForm(request.POST) 
        if form.is_valid(): 
            number = FikanoteDB.objects().count()+1
            # add to shownote
            shownotes = []
            list_title = request.POST.getlist('agenda_title')
            list_url = request.POST.getlist('agenda_url')
            list_id = request.POST.getlist('agenda_id')
            for i in range(len(list_title)):
                shownotes.append(Shownote(title=list_title[i], url=list_url[i]))
            FikanoteDB(number = number
                       , title=form.cleaned_data['title']
                       , person=form.cleaned_data['person'].split(",")
                       , agenda=form.cleaned_data['agenda']
                       , date=datetime.datetime.utcnow()
                       , shownotes=shownotes
                       ).save()
            # delete id's item from agendadb
            for i in range(len(list_id)):
                AgendaDB.objects.filter(id__exact=list_id[i]).delete()

        return HttpResponseRedirect('/') 
        
    else:
        raise Http404

Add HttpResponseRedirect to import