Exemple #1
0
def add_film(request):
    if request.method == 'POST':
        form = AddFilmForm(request.POST, request.FILES)
        if form.is_valid():
            added_film = form.save(commit=False)
            added_film.user = request.user

            added_film.save()

            # manualy add production countries
            countries = form.cleaned_data['production_country']
            for country in countries:
                country, created = Country.objects.get_or_create(
                    country=country)
                added_film.production_country.add(country)

            # ... and actors
            actors = form.cleaned_data['actors']
            importance = 1
            for actor, role in actors:
                a = AddedCharacter(added_film=added_film,
                                   person=actor,
                                   character=role,
                                   importance=importance)
                a.save()
                importance += 1

            # ... and directors
            directors = form.cleaned_data['directors']
            for director in directors:
                added_film.directors.add(director)

            added_film.save()

            # if user has perm to accept film, do this now
            if request.user.has_perm('add_films.can_accept_added_films'):
                added_film.accept(request.user)
                message = _("Film added!")

            else:
                message = _("Film added! awaiting approval")

            request.user.message_set.create(message=message)
            return redirect("edit-added-film", id=added_film.id)

    else:
        form = AddFilmForm()

    return render_to_response(templates["ADD_FILM_MANUAL"], {
        "form": form,
    },
                              context_instance=RequestContext(request))
Exemple #2
0
def add_film( request ):
    if request.method == 'POST':
        form = AddFilmForm( request.POST, request.FILES )
        if form.is_valid():
            added_film = form.save( commit=False )
            added_film.user = request.user

            added_film.save()
            
            # manualy add production countries
            countries = form.cleaned_data['production_country']
            for country in countries:
                country, created = Country.objects.get_or_create( country=country )
                added_film.production_country.add( country )

            # ... and actors
            actors = form.cleaned_data['actors']
            importance = 1
            for actor, role in actors:
                a = AddedCharacter( added_film = added_film, person = actor, 
                                   character = role, importance = importance )
                a.save()
                importance += 1

            # ... and directors
            directors = form.cleaned_data['directors']
            for director in directors:
                added_film.directors.add( director )

            added_film.save()

            # if user has perm to accept film, do this now
            if request.user.has_perm( 'add_films.can_accept_added_films' ):
                added_film.accept( request.user )
                message = _( "Film added!" )

            else: message = _( "Film added! awaiting approval" )

            request.user.message_set.create( message=message )
            return redirect( "edit-added-film", id=added_film.id )

    else:
        form = AddFilmForm()

    return render_to_response( templates["ADD_FILM_MANUAL"], {
        "form": form,
    }, context_instance=RequestContext( request ) )
Exemple #3
0
def edit_film( request, id ):
    
    added_film = get_object_or_404( AddedFilm, id = id )
    
    moderated = added_film.moderation_status != AddedFilm.STATUS_UNKNOWN
    accepted = added_film.moderation_status == AddedFilm.STATUS_ACCEPTED
    
    form = None

    if request.user.has_perm( 'add_films.can_accept_added_films' ):
        if not moderated:
            if request.method == "POST":

                if 'reject' in request.POST: 
                    added_film.reject( request.user )
                    
                    return redirect( "moderation" )

                elif 'accept' in request.POST or \
                        'save' in request.POST:

                    form = AddFilmForm( request.POST, request.FILES, instance=added_film )
                    if form.is_valid():
                        added_film = form.save( commit=False )
                        
                        # clear and manualy add production countries
                        added_film.production_country.clear()

                        countries = form.cleaned_data['production_country']
                        for country in countries:
                            country, created = Country.objects.get_or_create( country=country )
                            added_film.production_country.add( country )
                    
                        # ... actors to
                        added_film.actors.clear()
                        
                        actors = form.cleaned_data['actors']
                        importance = 1
                        for actor, role in actors:
                            a = AddedCharacter( added_film = added_film, person = actor, 
                                               character = role, importance=importance )
                            a.save()
                            importance += 1

                        # ... and directors
                        added_film.directors.clear()
                        
                        directors = form.cleaned_data['directors']
                        for director in directors:
                            added_film.directors.add( director )

                        # at last accept this movie
                        added_film.save()
                        
                        if 'accept' in request.POST:
                            added_film.accept( request.user )

                        return redirect( "moderation" )

            else:
                form = AddFilmForm( instance=added_film )

    return render_to_response( "movies/add-movie-detail.html", {
        "added_film": added_film,
        "form": form,
        "moderated": moderated,
        "accepted": accepted
    }, context_instance=RequestContext( request ) )
Exemple #4
0
def edit_film(request, id):

    added_film = get_object_or_404(AddedFilm, id=id)

    moderated = added_film.moderation_status != AddedFilm.STATUS_UNKNOWN
    accepted = added_film.moderation_status == AddedFilm.STATUS_ACCEPTED

    form = None

    if request.user.has_perm('add_films.can_accept_added_films'):
        if not moderated:
            if request.method == "POST":

                if 'reject' in request.POST:
                    added_film.reject(request.user)

                    return redirect("moderation")

                elif 'accept' in request.POST or \
                        'save' in request.POST:

                    form = AddFilmForm(request.POST,
                                       request.FILES,
                                       instance=added_film)
                    if form.is_valid():
                        added_film = form.save(commit=False)

                        # clear and manualy add production countries
                        added_film.production_country.clear()

                        countries = form.cleaned_data['production_country']
                        for country in countries:
                            country, created = Country.objects.get_or_create(
                                country=country)
                            added_film.production_country.add(country)

                        # ... actors to
                        added_film.actors.clear()

                        actors = form.cleaned_data['actors']
                        importance = 1
                        for actor, role in actors:
                            a = AddedCharacter(added_film=added_film,
                                               person=actor,
                                               character=role,
                                               importance=importance)
                            a.save()
                            importance += 1

                        # ... and directors
                        added_film.directors.clear()

                        directors = form.cleaned_data['directors']
                        for director in directors:
                            added_film.directors.add(director)

                        # at last accept this movie
                        added_film.save()

                        if 'accept' in request.POST:
                            added_film.accept(request.user)

                        return redirect("moderation")

            else:
                form = AddFilmForm(instance=added_film)

    return render_to_response("movies/add-movie-detail.html", {
        "added_film": added_film,
        "form": form,
        "moderated": moderated,
        "accepted": accepted
    },
                              context_instance=RequestContext(request))