Ejemplo n.º 1
0
def savechangesfilm(request,kind,id):
	isauth = request.user.is_authenticated()
	if(isauth and request.method == 'POST'):
		message="You are logged in as " + request.user.username
		objid=request.POST['objid']
		obj = get_object_or_404(Film, pk = int(objid))
		obj.mainactors.clear()
		obj.songs.clear()	
		
		data = request.POST
		songartists = {}
		songtitles = {}
		title=''
		yearout=''	
		for key in data:
			value = data[key]
			if(key != 'trailerurl' and key != 'imageurl'):
				value = normalize(value)
			for field in obj._meta.fields:
				if(key == field.name and value):					
					obj.__setattr__(field.name , value)
				if(key.startswith('actor') and value):
					if(Actor.objects.filter(name=value)):
						actor = Actor.objects.filter(name=value)[0]
					else:
						actor = Actor(name = value)
					actor.save()	
					obj.mainactors.add(actor)
			if(key=='title'):
				title=value
			if(key=='yearout'):
				yearout=value	
			
			if(key.startswith('songtitle') and value):
				songtitles[key[9:]] = value
			if(key.startswith('songartist')):
				songartists[key[10:]] = value		

		for key in songtitles:
			title = songtitles[key]
			if (songartists[key]):
				artistname = songartists[key]
				if(Artist.objects.filter(name=artistname)):
					artist = Artist.objects.get(name=artistname)
				else:
					artist = Artist(name=artistname)
					artist.save()
				if(Song.objects.filter(title=title).filter(artist = artist)):
					song=Song.objects.filter(title=title).filter(artist = artist)[0]
				else:
					song = Song(title=title,artist=artist,postedby=request.user.username)
					song.save()
			
			else:
				if(Song.objects.filter(title=title)):
					song=Song.objects.filter(title=title)[0]
				else:
					artist = Artist.objects.filter(name='Unknown')[0]
					song = Song(title=title,artist=artist,postedby=request.user.username)
					song.save()
			
			obj.songs.add(song)

		if(title and yearout):
			if(Film.objects.filter(title=title).filter(cameouton=yearout)):
				obj2 = Film.objects.filter(title=title).filter(cameouton=yearout)[0]
				if(obj.id == obj2.id):
					obj.updatedon=datetime.datetime.now()	
					obj.cameouton=int(yearout)
					obj.save()
					return HttpResponseRedirect('/findost/' + kind + '/details/' + str(obj.id)) 	
				else:
					if(id == '0'):					
						obj.delete()
						obj = obj2
						message2 = "the movie you want to update is already in database : add your changes here"
						return render_to_response('findost/editfilmform.html', {'message' : message , 'message2' : message2, 'obj' : obj, 'isauth' : isauth}, context_instance=RequestContext(request))	
					else:
						obj = obj2
						message2 = "the movie you want to update is already in database : add your changes here"
						return render_to_response('findost/editfilmform.html', {'message' : message , 'message2' : message2, 'obj' : obj, 'isauth' : isauth}, context_instance=RequestContext(request))								
			else:
				obj.updatedon=datetime.datetime.now()		
				obj.cameouton=int(yearout)
				obj.save()
				return HttpResponseRedirect('/findost/' + kind + '/details/' + str(obj.id)) 
		else:
			if(title):
				message2="please fill in the released year"
			else:
				message2="please fill in the title"	
			return render_to_response('findost/editfilmform.html', {'message' : message, 'message2' : message2, 'obj' : obj, 'isauth' : isauth}, context_instance=RequestContext(request))	
	else:
		raise Http404
Ejemplo n.º 2
0
				i = 0
				temp = ''
				while(l[i] != "'" and i<len(l)-1):
					i=i+1
				i=i+1
				if(i<len(l)-1):
					while(l[i] != "'" and l[i] != '(' and i<len(l)-1):
						temp = temp +l[i]
						i=i+1
					songartist = temp	
			#		print ('   artist : ' + songartist)
					liartist = Artist.objects.filter(name=songartist)
					if(liartist):
						a = liartist[0]
					else :
						a = Artist(name=songartist)				
						a.save()
					lisong = Song.objects.filter(title= songtitle).filter(artist__name=a)
					if(lisong):
						s = lisong[0]
					else:
						s = Song(title=songtitle, artist = a)
						s.save()
						obj.songs.add(s)
						obj.updatedon=datetime.datetime.now()
						obj.save()
			l = f.readline()
			l=l.decode('iso-8859-1')
	except not KeyboardInterrupt:
		l = f.readline()
		l=l.decode('iso-8859-1')
Ejemplo n.º 3
0
def savechangesepisode(request,kind,id):
	isauth = request.user.is_authenticated()
	showtitle=''
	number = ''
	seasonnb= ''
	if(isauth and request.method == 'POST'):
		message="You are logged in as " + request.user.username
		objid=request.POST['objid']
		obj = get_object_or_404(Episode, pk = int(objid))
		obj.show.mainactors.clear()
		obj.songs.clear()	
	
		data = request.POST	
		songartists = {}
		songtitles = {}
			
		for key in data:
			value = data[key]
			if(key != 'imageurl'):
				value = normalize(value)
			for field in obj._meta.fields:
				if(key == field.name and value):
					obj.__setattr__(field.name , value)
			

			if(key=='showstatus' and value):
				if(value == 'True'):
					obj.show.status=True
				else:
					obj.show.status=False		
				if(key.startswith('actor') and value):
					if(Actor.objects.filter(name=value)):
						actor = Actor.objects.filter(name=value)[0]
					else:
						actor = Actor(name = value)
					actor.save()
					obj.show.mainactors.add(actor)
	
			for field in obj.show._meta.fields:	
				if(key == field.name and value):
					obj.show.__setattr__(field.name , value)	





			if(key=='number'):
				number=value
			if(key=='seasonnb'):
				seasonnb=value
			if(key=='showtitle' and value):
				obj.show.title=value
				showtitle = value


			if(key.startswith('songtitle') and value):
				songtitles[key[9:]] = value
			if(key.startswith('songartist')):
				songartists[key[10:]] = value	

		for key in songtitles:
			title = songtitles[key]
			if (songartists[key]):
				artistname = songartists[key]
				if(Artist.objects.filter(name=artistname)):
					artist = Artist.objects.get(name=artistname)
				else:
					artist = Artist(name=artistname)
					artist.save()
				if(Song.objects.filter(title=title).filter(artist = artist)):
					song=Song.objects.filter(title=title).filter(artist = artist)[0]
				else:
					song = Song(title=title,artist=artist,postedby=request.user.username)
					song.save()
			
			else:
				if(Song.objects.filter(title=title)):
					song=Song.objects.filter(title=title)[0]
				else:
					artist = Artist.objects.filter(name='Unknown')[0]
					song = Song(title=title,artist=artist,postedby=request.user.username)
					song.save()
			
			obj.songs.add(song)
		
		
			

		if(showtitle and number and seasonnb):
			if(Show.objects.filter(title=showtitle)):
				show = Show.objects.filter(title=showtitle)[0]
			else:
				show = obj.show	
			
			if(not show.nbseason or int(show.nbseason) < int(obj.seasonnb)):
				show.nbseason = obj.seasonnb
			else:
				show.nbseason = obj.seasonnb
			if(show.episode_set.filter(number=number).filter(seasonnb=seasonnb)):
				obj2 = show.episode_set.filter(number=number).filter(seasonnb=seasonnb)[0]
				if(obj.id == obj2.id):
					obj.show.save()
					obj.updatedon=datetime.datetime.now()	
					obj.save()
					return HttpResponseRedirect('/findost/' + kind + '/details/' + str(obj.id)) 	
				else:
					if(id == '0'):
						obj.show.delete()					
						obj.delete()
						obj = obj2
						message2 = "the episode you want to update is already in database : add your changes here"
						return render_to_response('findost/editepisodeform.html', {'message' : message , 'message2' : message2, 'obj' : obj, 'isauth' : isauth}, context_instance=RequestContext(request))	
					else:
						obj = obj2
						message2 = "the episode you want to update is already in database : add your changes here"
						return render_to_response('findost/editepisodeform.html', {'message' : message , 'message2' : message2, 'obj' : obj, 'isauth' : isauth}, context_instance=RequestContext(request))								
			else:
				print str(obj.show.id)				
				showtemp = obj.show
				obj.show = show
				if(Show.objects.filter(title=showtitle)):
					showtemp.delete()
				print str(obj.show.id)				
				obj.show.save()
				obj.updatedon=datetime.datetime.now()
				obj.save()
				return HttpResponseRedirect('/findost/' + kind + '/details/' + str(obj.id)) 
		
		else:
			if( not showtitle):
				message2="please fill in the Show title"
			elif (not number):
				message2="please fill in the Episode number"
			else:
				message2="please fill in the Episode Season number"						
			return render_to_response('findost/editepisodeform.html', {'message' : message, 'message2' : message2, 'obj' : obj, 'isauth' : isauth}, context_instance=RequestContext(request))	
	else:
		raise Http404