def edit(request,kind,id): newtitle = request.GET.get('title') isauth = request.user.is_authenticated() if(isauth): message = "Logged in as " + request.user.username if(kind == 'film'): if(id != '0'): obj = get_object_or_404(Film, pk = id) message2 ="Edit movie" else: obj=Film(title=newtitle, updatedon=datetime.datetime.now()) obj.save() message2 = "Fill in the information of the movie you want to add" return render_to_response('findost/editfilmform.html', {'id' : id, 'message2' : message2, 'message' : message, 'obj' : obj, 'isauth' : isauth}, context_instance=RequestContext(request)) if(kind == 'episode'): if(id != '0'): obj = get_object_or_404(Episode, pk = id) message2="Edit episode" else: obj=Episode(number=1,seasonnb=1) s = Show(title=newtitle) s.save() obj.show = s obj.updatedon=datetime.datetime.now() obj.save() message2 = "Fill in the information of the show you want to add" return render_to_response('findost/editepisodeform.html', {'id' : id, 'message':message, 'message2' : message2, 'obj' : obj, 'isauth' : isauth},context_instance=RequestContext(request)) else: raise Http404
def find_and_add_episode(l): i = 3 temp = '' while (l[i] != '"' and i<len(l)-1): temp = temp + l[i] i=i+1 if(i<len(l)-1): showtitle = temp lishow = Show.objects.filter(title=showtitle) if(lishow): show = lishow[0] else: show = Show(title=showtitle) show.save() temp = '' i=i+3 while(l[i] != ')' and l[i] != '/' and i<len(l)-1): temp = temp + l[i] i=i+1 if(i<len(l)-1): year = int(temp) date = datetime.datetime(year,01,01) temp='' i = l.index('{') + 1 while(l[i] != '(' and i<len(l)-1): temp = temp + l[i] i=i+1 if(i<len(l)-1): eptitle = temp temp = '' i = l[i:].index('#') + 1 + i while(l[i] != '.' and i<len(l)-1): temp = temp + l[i] i=i+1 if(i<len(l)-1): epseason = int(temp) temp = '' i = i+1 while(l[i] != ')' and i<len(l)-1): temp = temp + l[i] i=i+1 if(i<len(l)-1): epnum = int(temp) temp = '' liepisode = Episode.objects.filter(show__title=showtitle).filter(seasonnb=epseason).filter(number=epnum) if(liepisode): episode = liepisode[0] else: print (showtitle + " : " + eptitle + ', s' + str(epseason) + 'e' + str(epnum)) episode = Episode(title=eptitle,cameouton=date,show=show,number=epnum,seasonnb=epseason) episode.updatedon=datetime.datetime.now() episode.save() if(epseason > show.nbseason): show.nbseason = epseason show.save() return episode