Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 3
0
def movie_search(request):
    if request.method == 'GET':
        form = MovieForm()
        director = request.GET.get('director', None)
        movie = request.GET.get('movie', None)
        dir_result = Movie.objects.filter(Q(director=director) | Q(name=movie))
        return render(request, 'movies/add_movie.html', {
            'form': form,
            'results': dir_result
        })
    else:
        form = MovieForm()
    return render(request, 'movies/add_movie.html', {'form': form})
Ejemplo n.º 4
0
def movie_add(request):
    if request.method == 'POST':
        print(request.POST)
        form = MovieForm(request.POST)

        if form.is_valid():
            movie_name = form.cleaned_data['movie_name']
            movie_genre = form.cleaned_data['movie_genre']
            movie_language = form.cleaned_data['movie_language']
            movie_price = form.cleaned_data['movie_price']
            movie_year = form.cleaned_data['movie_year']

            m = Movies(movie_name=movie_name,
                       movie_genre=movie_genre,
                       movie_language=movie_language,
                       movie_price=movie_price,
                       movie_year=movie_year)
            m.save()
            return redirect("movie_all")
    form = MovieForm()

    return render(request, 'movie_add.html', {'form': form})
Ejemplo n.º 5
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})
Ejemplo n.º 6
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})
Ejemplo n.º 7
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})
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
 def get(self, request):
     form = MovieForm()
     return render(request, 'movie_form.html', {'form': form})
Ejemplo n.º 10
0
    def get(self, request):
        form = MovieForm()

        return render(request, "movie_form.html", {"form": form})
Ejemplo n.º 11
0
	def get_context_data(self, **kwargs):
		context = super(EditMovie, self).get_context_data(**kwargs)
		context['form'] = MovieForm(instance=self.object)
		context['editing_title'] = self.object.title
		return context