예제 #1
0
파일: views.py 프로젝트: danux/RPG-Engine
def join_quest(request, town_slug, quest_slug):
    """
    View that allows members to join quests
    """
    quest = get_object_or_404(Quest, slug=quest_slug, town__slug=town_slug)
    qs = Character.available_characters_by_user(request.user)
    
    if request.method == 'POST':
        form = QuestForm(request.POST, queryset=qs)
        if form.is_valid():
            quest.add_character(form.cleaned_data['character'])
            return HttpResponseRedirect(quest.get_absolute_url())
    else:
        form = QuestForm(queryset=qs)
    context = { 'form' : form }
    return render_to_response("game/join-quest.html", 
                              context,
                              RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: danux/RPG-Engine
def leave_quest(request, town_slug, quest_slug):
    """
    View that allows users to leave a quest
    """
    quest = get_object_or_404(Quest, slug=quest_slug, town__slug=town_slug)
    qs = Character.objects.filter(author__user=request.user,
                                  questmembership__quest=quest,
                                  questmembership__date_left__isnull=True)

    if request.method == 'POST':
        form = QuestForm(request.POST, queryset=qs)
        if form.is_valid():
            quest.remove_character(form.cleaned_data['character'])
            return HttpResponseRedirect(quest.get_absolute_url())
    else:
        form = QuestForm(queryset=qs)
    context = {'quest':quest, 'form':form}
    return render_to_response("game/leave-quest.html", 
                              context,
                              RequestContext(request))