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
def agenda(request): if request.method == 'GET': agendas = AgendaDB.objects().order_by('-date') form = AgendaForm() return render(request, 'agenda.html', { 'agendas': agendas, 'form': form }) elif request.method == 'POST': form = AgendaForm(request.POST) if not form.is_valid(): response = json.dumps({'status': 'fail'}) # convert to JSON return HttpResponse(response, content_type="application/json") try: url = form.cleaned_data['url'] title = agendaGetTitle(url) except http.client.BadStatusLine as e: title = "UNNAMED URL" agendaItem = AgendaDB(url=url, title=title, date=datetime.datetime.utcnow()) agendaItem.save() response = json.dumps({ 'status': 'success', 'url': url, 'title': title, 'id': str(agendaItem.id) }) # convert to JSON return HttpResponse(response, content_type="application/json") elif request.method == 'DELETE': delete = QueryDict(request.body) delete_id = delete.get('id') if delete_id: AgendaDB.objects.filter(id__exact=delete_id).delete() response = json.dumps({'status': 'success'}) # convert to JSON else: response = json.dumps({'status': 'fail'}) # convert to JSON return HttpResponse(response, content_type="application/json") else: raise Http404
def agenda(request): if request.method == 'GET': agendas = AgendaDB.objects().order_by('-date') form = AgendaForm() return render(request, 'agenda.html', {'agendas': agendas, 'form': form } ) elif request.method == 'POST': form = AgendaForm(request.POST) if form.is_valid(): try: url = form.cleaned_data['url'] req = urllib2.Request(url, None, headers = { 'User-Agent' : 'Mozilla/5.0' }) soup = BeautifulSoup(urllib2.urlopen(req)) title = soup.title.string except httplib.BadStatusLine as e: title = "UNNAMED URL" agendaItem = AgendaDB(url=url, title=title, date=datetime.datetime.utcnow()) agendaItem.save() response = json.dumps({'status':'success', 'url':url, 'title':title, "id":str(agendaItem.id)}) # convert to JSON else: response = json.dumps({'status':'fail'}) # convert to JSON return HttpResponse(response, content_type="application/json") elif request.method == 'DELETE': delete = QueryDict(request.body) delete_id = delete.get('id') if delete_id : AgendaDB.objects.filter(id__exact=delete_id).delete() response = json.dumps({'status':'success'}) # convert to JSON else: response = json.dumps({'status':'fail'}) # convert to JSON return HttpResponse(response, content_type="application/json") else: raise Http404
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])) if len(shownotes) == 0: return HttpResponseRedirect('/') 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 episode(request, number) return HttpResponseRedirect('/') else: raise Http404