Exemple #1
0
def add(request):
    '''
    Add new movie info
    '''  
    
    if request.method == "POST":
        form = MovieForm(request.POST, request.FILES)
        
        if form.is_valid():
            obj = form.save(commit=False)
            obj.creator = request.user
            obj.created = datetime.now()
            obj.save()
            if obj.imdb_poster:
                save_poster(obj, obj.imdb_poster)
            try:
                add_cast(obj, form.data['cast'], request.user)
            except:
	         pass
            try:
                add_genre(obj, form.data['genre'])
            except:
	         pass    
            obj.save()
            return HttpResponseRedirect(reverse("movie_item", args=[obj.slug]))
    else:
        form = MovieForm()
        
    template = 'movies/edit.html'
    data = { 'form': form, }
    
    return render_to_response(template, data , context_instance=RequestContext(request))
Exemple #2
0
def edit(request, slug):
    '''
    Edit movie info
    '''
    movie, created = Movie.objects.get_or_create(slug=slug)
    
    if request.method == "POST":
        form = MovieForm(request.POST, request.FILES, instance=movie)
        if form.is_valid():
            obj = form.save(commit=False)
            
            if obj.imdb_poster:
                save_poster(obj, obj.imdb_poster)
                add_cast(obj, form.data['cast'], request.user)
                add_genre(obj, form.data['genre'])

            obj.save()
            return HttpResponseRedirect(reverse("movie_item", args=[obj.slug]))
    else:
        form = MovieForm(instance=movie)
        
    template = 'movies/edit.html'
    data = { 'form': form, }
    
    return render_to_response(template, data , context_instance=RequestContext(request))
Exemple #3
0
 def post(self, request):
     movie = Movie()
     movie.user = request.user  # asignamos a la pelicula el usuario autenticado
     form = MovieForm(request.POST, instance=movie)
     if form.is_valid():
         movie = form.save()
         form = MovieForm()
         url = reverse('movie_detail_page', args=[movie.pk])
         message = "Movie created succesfully! "
         message += '<a href="{0}">View</a>'.format(url)
         messages.success(request, message)
     return render(request, 'movie_form.html', {'form': form})
Exemple #4
0
 def post(self, request):
     movie = Movie()
     movie.user = request.user  # Asignamos el usuario autenticado
     form = MovieForm(request.POST, instance=movie)
     if form.is_valid():
         movie = form.save()
         form = MovieForm()
         url = reverse("movie_detail_page", args=[movie.pk])
         message = "Película guardada!"
         message += "<a href='{0}'>View</a>".format(url)
         messages.success(request, message)
     return render(request, "movie_form.html", {"form": form})
Exemple #5
0
 def post(self, request):
     movie = Movie()
     movie.user = request.user
     form = MovieForm(request.POST, instance=movie)
     if form.is_valid():
         movie = form.save()
         form = MovieForm()
         url = reverse("movie_detail_page", args=[movie.pk])
         message = "Movie created successfully! "
         message += '<a href="{0}">View</a>'.format(url)
         messages.success(request, message)
     return render(request, "movie_form.html", {'form': form})
Exemple #6
0
def movie_add(request):
    error = ''
    if request.method == 'POST':
        movie_form = MovieForm(request.POST)
        if movie_form.is_valid():
            # Si el form es valido guardar la data en una variable sin pegarle a la
            # base de datos, para agregar info que esta en el request
            new_movie = movie_form.save(commit=False)
            # Agregar user desde request
            new_movie.user = request.user
            # Guardar en base de datos
            new_movie.save()
            return redirect(reverse('movies:index'))
        else:
            error = 'El formulario no es valido'
    else:
        movie_form = MovieForm()
    context = {'movie_form': movie_form, 'error': error}
    return render(request, 'movie_add.html', context)