def edit_world(request,world_slug): """ Edit an existing world (this will need permissions) """ world = get_object_or_404(World,slug=world_slug) if request.POST: form = WorldForm(request.POST, instance=world) if form.is_valid(): # Don't commit the save until we've added in the fields we need to set world = form.save(commit=False) world.slug = slugify(world.title) world.save() form.save_m2m() messages.success(request, "World [worldname] saved.") return HttpResponseRedirect(reverse('world_index',args=[world.slug])) else: form = WorldForm(instance=world) # Only world creators can edit worlds if world.created_by != request.user: return HttpResponseForbidden() else: return render_to_response('worlds/world_edit.html', locals(), context_instance=RequestContext(request))
def create_world(request): """ Create a new world (this will need permissions) """ if request.POST: form = WorldForm(request.POST) if form.is_valid(): # Don't commit the save until we've added in the fields we need to set world = form.save(commit=False) world.slug = slugify(world.title) world.created_date = datetime.now() world.created_by = request.user world.save() form.save_m2m() # World creator is automatically a member. world.members.add(request.user) messages.success(request, "World [worldname] added!") return HttpResponseRedirect(reverse('world_index',args=[world.slug])) else: form = WorldForm() return render_to_response('worlds/world_create.html', locals(), context_instance=RequestContext(request))
def edit_world(request, world_slug): """ Edit an existing world (this will need permissions) """ world = get_object_or_404(World, slug=world_slug) if request.POST: form = WorldForm(request.POST, instance=world) if form.is_valid(): # Don't commit the save until we've added in the fields we need to set world = form.save(commit=False) world.slug = slugify(world.title) world.save() form.save_m2m() messages.success(request, "World [worldname] saved.") return HttpResponseRedirect(reverse("world_index", args=[world.slug])) else: form = WorldForm(instance=world) # Only world creators can edit worlds if world.created_by != request.user: return HttpResponseForbidden() else: return render_to_response("worlds/world_edit.html", locals(), context_instance=RequestContext(request))
def create_world(request): """ Create a new world (this will need permissions) """ if request.POST: form = WorldForm(request.POST) if form.is_valid(): # Don't commit the save until we've added in the fields we need to set world = form.save(commit=False) world.slug = slugify(world.title) world.created_date = datetime.now() world.created_by = request.user world.save() form.save_m2m() # World creator is automatically a member. world.members.add(request.user) messages.success(request, "World [worldname] added!") return HttpResponseRedirect(reverse("world_index", args=[world.slug])) else: form = WorldForm() return render_to_response("worlds/world_create.html", locals(), context_instance=RequestContext(request))