Ejemplo n.º 1
0
def table_update(request, table_pk):
    data = at_tagging(request)
    table = get_object_or_404(models.Table, pk=table_pk)
    if table.user == request.user:
        form = forms.TableForm(instance=table)
        formset = forms.TableOptionFormSet(instance=table)
        if request.method == 'POST':
            form = forms.TableForm(request.POST, instance=table)
            formset = forms.TableOptionFormSet(request.POST, instance=table)
            if form.is_valid() and formset.is_valid():
                form.save()
                options = formset.save(commit=False)
                for option in options:
                    option.table = table
                    option.save()
                for option in formset.deleted_objects:
                    option.delete()
                messages.add_message(
                    request, messages.SUCCESS,
                    "Updated table: {}".format(form.cleaned_data['name']))
                return HttpResponseRedirect(table.get_absolute_url())
    else:
        raise Http404
    data['form'] = form
    data['formset'] = formset
    data['table'] = table
    return render(request, 'tables/table_form.html', data)
Ejemplo n.º 2
0
def chapter_update(request, campaign_pk, chapter_pk):
    chapter = get_object_or_404(models.Chapter,
                                pk=chapter_pk,
                                campaign_id=campaign_pk)
    if chapter.user == request.user:
        data = at_tagging(request)
        sections = models.Section.objects.filter(chapter=chapter)
        form = forms.ChapterForm(instance=chapter)
        section_forms = forms.SectionInlineFormSet(
            queryset=form.instance.section_set.all())
        if request.method == 'POST':
            form = forms.ChapterForm(request.POST, instance=chapter)
            section_forms = forms.SectionInlineFormSet(
                request.POST, queryset=form.instance.section_set.all())
            if form.is_valid() and section_forms.is_valid():
                form.save()
                sections = section_forms.save(commit=False)
                for section in sections:
                    section.chapter = chapter
                    section.user = request.user
                    section.save()
                for section in section_forms.deleted_objects:
                    section.delete()
                messages.add_message(
                    request, messages.SUCCESS,
                    "Updated chapter: {}".format(form.cleaned_data['title']))
                return HttpResponseRedirect(chapter.get_absolute_url())
    else:
        raise Http404
    data['campaign'] = chapter.campaign
    data['chapter'] = chapter
    data['sections'] = sections
    data['form'] = form
    data['formset'] = section_forms
    return render(request, 'campaign/chapter_form.html', data)
Ejemplo n.º 3
0
 def get(self, request, *args, **kwargs):
     campaign = get_object_or_404(models.Campaign, pk=kwargs['campaign_pk'])
     if campaign.user == request.user:
         data = at_tagging(request)
         data['campaign'] = campaign
         data['form'] = forms.ChapterForm()
         data['chapter_number'] = utils.get_next_order(campaign)
         return render(request, 'campaign/chapter_form.html', data)
     raise Http404
Ejemplo n.º 4
0
def player_create(request):
    data = at_tagging(request)
    form = forms.PlayerForm()
    if request.method == 'POST':
        form = forms.PlayerForm(request.POST)
        if form.is_valid():
            player = form.save(commit=False)
            player.user = request.user
            player.save()
            messages.add_message(request, messages.SUCCESS, "Player created!")
            return HttpResponseRedirect(player.get_absolute_url())
    data['form'] = form
    return render(request, 'characters/player_form.html', data)
Ejemplo n.º 5
0
def npc_create(request):
    data = at_tagging(request)
    form = forms.NPCForm()
    if request.method == 'POST':
        form = forms.NPCForm(request.POST)
        if form.is_valid():
            npc = form.save(commit=False)
            npc.user = request.user
            npc.save()
            messages.add_message(request, messages.SUCCESS, "NPC created!")
            return HttpResponseRedirect(npc.get_absolute_url())
    data['form'] = form
    return render(request, 'characters/npc_form.html', data)
Ejemplo n.º 6
0
def item_create(request):
    data = at_tagging(request)
    form = forms.ItemForm()
    if request.method == 'POST':
        form = forms.ItemForm(request.POST)
        if form.is_valid():
            item = form.save(commit=False)
            item.user = request.user
            item.save()
            messages.add_message(request, messages.SUCCESS,
                                 "Item/spell created!")
            return HttpResponseRedirect(item.get_absolute_url())
    data['form'] = form
    return render(request, 'items/item_form.html', data)
Ejemplo n.º 7
0
def location_create(request, world_pk, location_pk=None):
    data = at_tagging(request)
    world = get_object_or_404(models.World, pk=world_pk)
    if world.user == request.user:
        initial = {'world': world}
        if location_pk:
            parent_location = get_object_or_404(models.Location,
                                                pk=location_pk)
            initial['parent_location'] = parent_location
        form = forms.LocationForm(request.user.pk,
                                  world_pk,
                                  location_pk,
                                  initial=initial)
        if request.method == 'POST':
            form = forms.LocationForm(request.user.pk,
                                      world_pk,
                                      location_pk,
                                      request.POST,
                                      request.FILES,
                                      initial=initial)
            if form.is_valid():
                location = form.save(commit=False)
                if location_pk:
                    if parent_location.user == request.user:
                        location.parent = parent_location
                location.user = request.user

                if form.cleaned_data['image']:
                    image_validity_check = image_is_valid(request, form)
                    if image_validity_check == True:
                        location.image = form.cleaned_data['image']
                    elif image_validity_check == "bad size":
                        return redirect('/error/image-size/')
                    elif image_validity_check == "bad type":
                        return redirect('/error/image-type/')

                location.world = world
                location.save()
                messages.add_message(request, messages.SUCCESS,
                                     "Location created!")
                return HttpResponseRedirect(location.get_absolute_url())
    else:
        raise Http404
    data['world'] = world
    data['form'] = form
    return render(request, 'locations/location_form.html', data)
Ejemplo n.º 8
0
def player_update(request, player_pk):
    data = at_tagging(request)
    player = get_object_or_404(models.Player, pk=player_pk)
    if player.user == request.user:
        form = forms.PlayerForm(instance=player)
        if request.method == 'POST':
            form = forms.PlayerForm(instance=player, data=request.POST)
            if form.is_valid():
                form.save()
                messages.add_message(request, messages.SUCCESS,
                                     "Updated player")
                return HttpResponseRedirect(player.get_absolute_url())
    else:
        raise Http404
    data['player'] = player
    data['form'] = form
    return render(request, 'characters/player_form.html', data)
Ejemplo n.º 9
0
def item_update(request, item_pk):
    data = at_tagging(request)
    item = get_object_or_404(models.Item, pk=item_pk)
    if item.user == request.user:
        form = forms.ItemForm(instance=item)
        if request.method == 'POST':
            form = forms.ItemForm(instance=item, data=request.POST)
            if form.is_valid():
                form.save()
                messages.add_message(
                    request, messages.SUCCESS,
                    "Updated item/spell: {}".format(form.cleaned_data['name']))
                return HttpResponseRedirect(item.get_absolute_url())
    else:
        raise Http404
    data['form'] = form
    data['item'] = item
    return render(request, 'items/item_form.html', data)
Ejemplo n.º 10
0
def npc_update(request, npc_pk):
    data = at_tagging(request)
    npc = get_object_or_404(models.NPC, pk=npc_pk)
    if npc.user == request.user:
        form = forms.NPCForm(instance=npc)
        if request.method == 'POST':
            form = forms.NPCForm(instance=npc, data=request.POST)
            if form.is_valid():
                form.save()
                messages.add_message(
                    request, messages.SUCCESS,
                    "Updated NPC: {}".format(form.cleaned_data['name']))
                return HttpResponseRedirect(npc.get_absolute_url())
    else:
        raise Http404
    data['npc'] = npc
    data['form'] = form
    return render(request, 'characters/npc_form.html', data)
Ejemplo n.º 11
0
def monster_update(request, monster_pk):
    data = at_tagging(request)
    monster = get_object_or_404(models.Monster, pk=monster_pk)
    if monster.user == request.user:
        form = forms.MonsterForm(instance=monster)
        if request.method == 'POST':
            form = forms.MonsterForm(instance=monster, data=request.POST)
            if form.is_valid():
                form.save()
                messages.add_message(
                    request, messages.SUCCESS,
                    "Updated monster: {}".format(form.cleaned_data['name']))
                return HttpResponseRedirect(monster.get_absolute_url())
    else:
        raise Http404
    data['monster'] = monster
    data['form'] = form
    return render(request, 'characters/monster_form.html', data)
Ejemplo n.º 12
0
def world_update(request, world_pk):
    data = at_tagging(request)
    world = get_object_or_404(models.World, pk=world_pk)
    if world.user == request.user:
        form = forms.WorldForm(instance=world)
        location_forms = forms.LocationInlineFormSet(
            queryset=form.instance.location_set.all())
        if request.method == 'POST':
            form = forms.WorldForm(request.POST, request.FILES, instance=world)
            location_forms = forms.LocationInlineFormSet(
                request.POST,
                request.FILES,
                queryset=form.instance.location_set.all())
            if form.is_valid() and location_forms.is_valid():

                if form.cleaned_data['image']:
                    image_validity_check = image_is_valid(request, form)
                    if image_validity_check == True:
                        pass
                    elif image_validity_check == "bad size":
                        return redirect('/error/image-size/')
                    elif image_validity_check == "bad type":
                        return redirect('/error/image-type/')

                form.save()
                locations = location_forms.save(commit=False)
                for location in locations:
                    location.world = world
                    location.user = request.user
                    location.save()
                for location in location_forms.deleted_objects:
                    location.delete()
                messages.add_message(
                    request, messages.SUCCESS,
                    "Updated world: {}".format(form.cleaned_data['name']))
                return HttpResponseRedirect(world.get_absolute_url())
    else:
        raise Http404
    data['world'] = world
    data['form'] = form
    data['formset'] = location_forms
    return render(request, 'locations/world_form.html', data)
Ejemplo n.º 13
0
def world_create(request):
    data = at_tagging(request)
    form = forms.WorldForm()
    if request.method == 'POST':
        form = forms.WorldForm(request.POST, request.FILES)
        if form.is_valid():
            world = form.save(commit=False)
            world.user = request.user
            if form.cleaned_data['image']:
                image_validity_check = image_is_valid(request, form)
                if image_validity_check == True:
                    world.image = form.cleaned_data['image']
                elif image_validity_check == "bad size":
                    return redirect('/error/image-size/')
                elif image_validity_check == "bad type":
                    return redirect('/error/image-type/')
            world.save()
            messages.add_message(request, messages.SUCCESS, "World created!")
            return HttpResponseRedirect(world.get_absolute_url())
    data['form'] = form
    return render(request, 'locations/world_form.html', data)
Ejemplo n.º 14
0
def table_create(request):
    data = at_tagging(request)
    form = forms.TableForm()
    formset = forms.TableOptionFormSet()
    if request.method == 'POST':
        form = forms.TableForm(request.POST)
        formset = forms.TableOptionFormSet(request.POST)
        if form.is_valid() and formset.is_valid():
            table = form.save(commit=False)
            table.user = request.user
            table.save()

            options = formset.save(commit=False)
            for option in options:
                option.table = table
                option.save()

            messages.add_message(request, messages.SUCCESS, "Table created!")
            return HttpResponseRedirect(table.get_absolute_url())
    data['form'] = form
    data['formset'] = formset
    return render(request, 'tables/table_form.html', data)
Ejemplo n.º 15
0
def section_update(request, campaign_pk, chapter_pk, section_pk):
    section = get_object_or_404(models.Section,
                                pk=section_pk,
                                chapter_id=chapter_pk,
                                campaign_id=campaign_pk)
    if section.user == request.user:
        data = at_tagging(request)
        form = forms.SectionForm(instance=section)
        if request.method == 'POST':
            form = forms.SectionForm(instance=section, data=request.POST)
            if form.is_valid():
                form.save()
                messages.add_message(
                    request, messages.SUCCESS,
                    "Updated section: {}".format(form.cleaned_data['title']))
                return HttpResponseRedirect(section.get_absolute_url())
    else:
        raise Http404
    data['form'] = form
    data['campaign'] = section.chapter.campaign
    data['chapter'] = section.chapter
    data['section'] = section
    return render(request, 'campaign/section_form.html', data)
Ejemplo n.º 16
0
def location_update(request, location_pk):
    data = at_tagging(request)
    location = get_object_or_404(models.Location, pk=location_pk)
    if location.user == request.user:
        form = forms.LocationForm(request.user.pk,
                                  location.world.pk,
                                  location_pk,
                                  instance=location)
        if request.method == 'POST':
            form = forms.LocationForm(request.user.pk,
                                      location.world.pk,
                                      location_pk,
                                      request.POST,
                                      request.FILES,
                                      instance=location)
            if form.is_valid():

                if form.cleaned_data['image']:
                    image_validity_check = image_is_valid(request, form)
                    if image_validity_check == True:
                        pass
                    elif image_validity_check == "bad size":
                        return redirect('/error/image-size/')
                    elif image_validity_check == "bad type":
                        return redirect('/error/image-type/')

                form.save()
                messages.add_message(
                    request, messages.SUCCESS,
                    "Updated location: {}".format(form.cleaned_data['name']))
                return HttpResponseRedirect(location.get_absolute_url())
    else:
        raise Http404
    data['location'] = location
    data['world'] = location.world
    data['form'] = form
    return render(request, 'locations/location_form.html', data)