def new_instance(request): if request.method == 'POST': form = InstanceForm(request.POST) if form.is_valid(): instance = OodInstance.objects.create( name=form.cleaned_data['name'], server_type=OodInstance.DROPLET_SERVER, state=droplet_states.Archived.name, ) MineCraftServerSettings.objects.create( ood=instance, port=form.cleaned_data['port'], rcon_port=form.cleaned_data['rcon_port'], rcon_password=form.cleaned_data['rcon_password'], ) DropletState.objects.create( ood=instance, name=form.cleaned_data['name'], region=form.cleaned_data['region'], pkey=form.cleaned_data['pkey'], ) return redirect(reverse('main')) else: form = InstanceForm() return render(request, 'instance.html', { 'form': form, 'form_dest': reverse('new_instance'), })
def edit_instance(request, instance_id): instance = OodInstance.objects.get(pk=instance_id) server_settings = instance.minecraftserversettings droplet_state = instance.dropletstate url = reverse('edit_instance', args=(instance_id, )) can_delete = request.user.has_perm('delete_oodinstance') if request.method == 'POST': form = InstanceForm(request.POST) if form.is_valid(): instance.name = form.cleaned_data['name'] instance.save() server_settings.port = form.cleaned_data['port'] server_settings.rcon_port = form.cleaned_data['rcon_port'] server_settings.rcon_password = form.cleaned_data['rcon_password'] server_settings.save() droplet_state.name = form.cleaned_data['name'] droplet_state.region = form.cleaned_data['region'] droplet_state.pkey = form.cleaned_data['pkey'] droplet_state.save() return redirect(url) else: form_data = { 'port': server_settings.port, 'rcon_port': server_settings.rcon_port, 'rcon_password': server_settings.rcon_password, 'name': instance.name, 'region': droplet_state.region, 'pkey': droplet_state.pkey, } form = InstanceForm(form_data) return render( request, 'instance.html', { 'form': form, 'form_dest': url, 'instance': instance, 'can_delete': can_delete, })
def edit_instance(request, instance_id): instance = OodInstance.objects.get(pk=instance_id) server_settings = instance.minecraftserversettings droplet_state = instance.dropletstate url = reverse('edit_instance', args=(instance_id,)) can_delete = request.user.has_perm('delete_oodinstance') if request.method == 'POST': form = InstanceForm(request.POST) if form.is_valid(): instance.name = form.cleaned_data['name'] instance.save() server_settings.port = form.cleaned_data['port'] server_settings.rcon_port = form.cleaned_data['rcon_port'] server_settings.rcon_password = form.cleaned_data['rcon_password'] server_settings.save() droplet_state.name = form.cleaned_data['name'] droplet_state.region = form.cleaned_data['region'] droplet_state.pkey = form.cleaned_data['pkey'] droplet_state.save() return redirect(url) else: form_data = { 'port': server_settings.port, 'rcon_port': server_settings.rcon_port, 'rcon_password': server_settings.rcon_password, 'name': instance.name, 'region': droplet_state.region, 'pkey': droplet_state.pkey, } form = InstanceForm(form_data) return render(request, 'instance.html', { 'form': form, 'form_dest': url, 'instance': instance, 'can_delete': can_delete, })