Пример #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))
Пример #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))