예제 #1
0
파일: views.py 프로젝트: jhelbert/coshare
def add_album(request):
	userprof = get_user_profile(request)
	couple = get_couple(userprof)
	name = request.POST.get('name')
	plist = Album(name=name)
	plist.save()
	if couple:
		couple.albums.add(plist)
		couple.save()
	else:
		return HttpResponse("create a couple")
	return HttpResponse('%i' % (plist.id, ))
예제 #2
0
파일: views.py 프로젝트: jhelbert/coshare
def upload(request):
	mobile = request.POST.get('mobile')
	album_id = request.POST.get('album')
	userprof = get_user_profile(request)
	try:
		delete = request.POST.get('deleted').split('|')
	except:
		delete = []
	album = None
	if album_id != -1 and album_id != None:
		print album_id
		try:
			album = Album.objects.get(id=album_id)
		except:
			album = None
	new_album_name = request.POST.get('new_album_name')
	if new_album_name:
		
		couple = get_couple(userprof)
		album = Album(name=new_album_name)
		album.save()
		couple.albums.add(album)
		couple.save()
	index = 0
	for uploaded_content in request.FILES.getlist('content'):
		if str(index) not in delete:
			print uploaded_content
			new_content = Content()
			new_content.owner = userprof
			file_content = ContentFile(uploaded_content.read()) 
			new_content.image.save(uploaded_content.name, file_content)
			# ext = uploaded_content.name[uploaded_content.name.find('.')+1:]
			ext = os.path.splitext(uploaded_content.name)[1]
			if ext in ["mov","MOV","mp4"]:
				new_content.is_video = True
			new_content.metric = int(random.random() * 6) + 8
			new_content.save()
			new_content.save()
			if album:
				album.content.add(new_content)
				album.save()
			if mobile:
				userprof.queue.content.add(new_content);
				userprof.queue.save()
		else:
			print "not uploading index:%i" % index
		index += 1

	if mobile:
		return HttpResponseRedirect('/mobile_confirm/')
	return HttpResponseRedirect('/browse/')
예제 #3
0
파일: views.py 프로젝트: jhelbert/coshare
def new_plist(request):
	print "new_plist"
	userprof = get_user_profile(request)
	print userprof
	couple = get_couple(userprof)
	print "got couple"
	name = request.POST.get('name')
	plist = Album(name=name)
	plist.save()
	if couple:
		couple.albums.add(plist)
		couple.save()
	else:
		return HttpResponse("create a couple")
	return HttpResponseRedirect('/')
예제 #4
0
파일: views.py 프로젝트: ollko/new_teach
def fotoalbums_new(request):
	# if this is a POST request we need to process the form data
	if request.method == 'POST':
        # create a form instance and populate it with data from the request:
		form = AlbumForm(request.POST,request.FILES)
		
		if form.is_valid():
			# process the data in form.cleaned_data as required
			album = form.cleaned_data['album'].lower()
			album_date = form.cleaned_data['album_date']

			a=Album(album=album,album_date=album_date)
			a.save()			
			fotos = request.FILES
			
			i=len(fotos.getlist('fotos'))-1
			current_date=timezone.now().date()
			
			while i>=0:

				foto = fotos.getlist('fotos')[i]
				published_date=current_date
				f = Foto(album =a, published_date = current_date, foto= foto)

				f.save()

				f.foto_1x_2x_3x()
				
				f.save()
				i=i-1

			# удаляем первоначальное фото большого размера:
			# f.del_initial_foto()

			return HttpResponseRedirect('/thanks/add_album/')
    # if a GET (or any other method) we'll create a blank form
	else:
		form = AlbumForm()


	return render(request,  'main/form.html', {'form': form,
					    	'title':'добавление нового альбома',
					    	'value':'добавить альбом',
					    	'enctype_atr':'multipart/form-data'
					    	})
예제 #5
0
파일: views.py 프로젝트: jhelbert/coshare
def login_user(request):
	email = request.POST.get('email')
	password = request.POST.get('password')
	user = User.objects.get(email=email)

	if user.check_password(password):
		user.backend = 'django.contrib.auth.backends.ModelBackend'
		login(request,user)
		userprof = get_user_profile(request)
		if userprof is None:
			print "no userprof"
			if user.first_name:
				queue = Album(name=user.first_name + "'s Queue")
			else:
				queue = Album(name=user.username + "'s Queue")
			queue.save()
			userprof = UserProfile(user=user,queue=queue)
			userprof.save()


		return HttpResponseRedirect('/')
	else:
		return HttpResponseRedirect('/login/')
예제 #6
0
파일: views.py 프로젝트: dproni/lyrics
def add(request):
    title = "Main Window"
    artist = Artist()
    album = Album()
    songG = Song()
    if request.method == 'POST':
        form = AddLyrics(request.POST)
        if form.is_valid():
            artistName = form.cleaned_data['artist']
            albumName = form.cleaned_data['album']

            albumPicture = form.cleaned_data['albumPicture']
            position = albumPicture.find('albums') - 1
            albumPicture = albumPicture[position:]
            print "albumPicture = %s" % (albumPicture)

            songName = form.cleaned_data['song']
            songG.lyrics = form.cleaned_data['lyrics']
            print "adding new song..."
            try:
                artist = Artist.objects.get(artist=artistName)
                print "artist %s already exist" % (artist)
            except:
                artist.artist = artistName
                artist.save()
                print "artist %s was added" % (artist)
            try:
                album = Album.objects.get(album=albumName)
                #renew album photo
                if albumPicture:
                    album.photo = albumPicture
                    album.save()
                    print "album picture renew " + albumPicture
                print "album %s is already exist" % (album)
            except:
                album.album = albumName
                album.artist = artist
                if albumPicture:
                    album.photo = albumPicture
                    print "album picture was added " + albumPicture
                album.save()
                print "album %s was added" % (album)

            # TODO: here you should implement logic for adding different translations for song
            #            try:
            #                song = Song.objects.get(song=songName)
            #                print "sadasdasds"
            #                render_to_response('song.html', {
            #                    "title": title,
            #                    "artist": song.artist,
            #                    "song" : song.song
            #                })
            #            except:

            songG.song = songName
            songG.artist = artist
            songG.album = album
            songG.save()
            print "song %s was added" % (songG)
            print "artist.id = %s, album.id = %s, song.id = %s" % (artist.id, album.id, songG.id)

            return song(request, artist.id, album.id, songG.id)

    else:
        form = AddLyrics()
    return render_to_response('add.html', {
        'form': form,
        })