def edit_room(room_number): room = Room.query.filter_by(number=room_number).first_or_404() form = RoomForm(request.form, obj=room) files = {} if request.method == 'POST' and request.files: files = _pre_upload_files(request.files.getlist('room_files[]')) if form.validate_on_submit(): room.name = form.name.data room.number = form.number.data room.state = form.state.data db.session.add(room) db.session.commit() try: _add_files_to_storage(files, room) flash(u'Кабинет успешно изменен', 'success') except Exception as e: app.logger.error(e) flash(u'Произошла ошибка, кабинет не может быть изменен', 'error') finally: _clear_preloaded_files(files) return redirect('/rooms/') _clear_preloaded_files(files) return render_template('edit_room.html', form=form)
def edit_room(roomnumber): """ Edit a room """ check_admin() add_room = False room = Room.query.get_or_404(roomnumber) form = RoomForm() if form.validate_on_submit(): room.room_no = form.room_no.data, room.capacity = form.capacity.data db.session.add(room) db.session.commit() flash('You have successfully edited the role.') # redirect to the rooms page return redirect(url_for('admin.list_rooms')) form.capacity.data = room.capacity form.room_no.data = room.room_no return render_template('admin/rooms/room.html', add_room=add_room, form=form, room=room)
def edit(request, room): was_private = room.is_private if request.method == 'POST': form = RoomForm(request.POST, instance=room) if form.is_valid(): form.save(commit=False) room.save() if room.is_private and not was_private: redis = create_redis_connection() redis.publish('web_channel', 'room_private:' + str(room.id)) try: redis.hdel(redis_room_key(room.id), *redis.hkeys(redis_room_key(room.id))) except: pass return HttpResponseRedirect(request.get_full_path()) else: form = RoomForm(instance=room) response_data = { 'form' : form } if room.is_private: response_data['invited_users'] = room.invited.order_by('username').all() response_data['users'] = User.objects.exclude(pk=room.owner.id).exclude(rooms__pk=room.id).order_by('username').all() return response_data
def add_room(request): try: room = RoomForm(request.POST) rom = room.save() messages.success(request, "Room " + rom.name + " successfully added") except Exception, e: messages.error(request, "Some error occured. Please contact webops with this message: " + e.message)
def view_room(request, room_id): room_id = int(room_id) try: room = Room.objects.get(pk=room_id) except Room.DoesNotExist: return render_to_response('error.html', {'error_type': "View Room", 'error_name': str(room_id), 'error_info':"No such room"}, context_instance=RequestContext(request)) if request.method == 'POST': form = RoomForm(request.POST,instance=room) if form.is_valid(): try: form.save() except ValueError: return render_to_response('error.html', {'error_type': "Room", 'error_name': "["+form.cleaned_data['name']+"]", 'error_info':"Room name cannot be validated, most likely a non-existent room"}, context_instance=RequestContext(request)) return render_to_response('thanks.html', {'data_type': "Room", 'data_name': "["+form.cleaned_data['name']+"]"}, context_instance=RequestContext(request)) else: form = RoomForm(instance=room) links = [('/room/'+str(room_id)+'/delete/', 'Delete', True)] return render_to_response('data_entry.html', {'form': form, 'links': links, 'title': "Viewing Room: %s"%(room.name)}, context_instance=RequestContext(request))
def add_room(): form = RoomForm() files = {} if request.method == 'POST' and request.files: files = _pre_upload_files(request.files.getlist('room_files[]')) if form.validate_on_submit(): room = Room( name=form.name.data, number=int(form.number.data), state=form.state.data ) db.session.add(room) db.session.commit() try: _add_files_to_storage(files, room) flash(u'Новый кабинет успешно добавлен', 'success') except Exception as e: app.logger.error(e) flash(u'Произошла ошибка при добавлении кабинета', 'error') finally: _clear_preloaded_files(files) return redirect('/rooms/add') _clear_preloaded_files(files) return render_template('edit_room.html', form=form)
def add_room(): """ Add a room to the database """ check_admin() add_room = True form = RoomForm() if form.validate_on_submit(): room = Room(room_no=form.room_no.data, capacity=form.capacity.data) try: # add a room to the database db.session.add(room) db.session.commit() flash('You have successfully added a new room.') except: # in case room name already exists flash('Error: room has been taken') # redirect to the rooms page return redirect(url_for('admin.list_rooms')) # load room template return render_template( 'admin/rooms/room.html', add_room=add_room, form=form, )
def post(self, request): bound_form = RoomForm(request.POST) if bound_form.is_valid(): new_room = bound_form.save() print(new_room) return redirect(reverse('rooms_url')) return render(request, 'hostel/add_a_room.html', context={'form': bound_form})
def edit_rooms(request, id=None): context = {'page_title': u'Salas', 'edit_name': 'room', 'list_title': u'Baias', 'list_edit_name': 'stall', 'header_name_list': stall_list_header, 'has_back': False, 'features':get_user_features(request)} t = get_template('edit.html') room = None form = RoomForm() try: if request.method == 'POST': form = RoomForm(request.POST) if form.is_valid(): cd = form.cleaned_data room = _save_room(cd) messages.success(request, 'Sala salva com sucesso.') initial=room.__dict__ initial['syndic'] = room.syndic form = RoomForm(initial=initial) elif id: room = Room.objects.get(id=id) initial=room.__dict__ initial['syndic'] = room.syndic form = RoomForm(initial=initial) except Exception as e: log.error(e) messages.error(request, u'Ocorreu um erro ao processar a requisição, por favor tente novamente.') context = _set_room_form_context(room, form, context, request) return render_to_response('edit.html', context, context_instance=RequestContext(request))
def create_room(request, extra_context={}): """ View for creating a room. Uses a clever combination of PollForm, RoomForm and ChoiceFormSet to achieve 3-way model creation: - PollForm allows the user to specify the question - ChoiceFormSet allows the user to specify an arbitrary number of "choices" to go with the question (each one represented by its own DB object) - RoomForm gives more advanced "tweaks" for the room, for example: - period length (how long each period lasts, default is 30) - join threshold (the amount of time that a room is in lock mode before a poll begins) """ if request.method == "POST": # if the user has submitted the form, get the data from all three poll_form = PollForm(request.POST, request.FILES) choice_formset = ChoiceFormSet(request.POST, request.FILES) room_form = RoomForm(request.POST, request.FILES) if poll_form.is_valid() and choice_formset.is_valid() and room_form.is_valid(): # if all 3 forms are valid, create a new question object and save it q = Question(text=poll_form.cleaned_data['question']) q.save() # create a new poll object that points to the question, and save it p = Poll(question=q) p.save() # for every choice the user has inputted for form in choice_formset.forms: # create a new choice object, and point it at the question created earlier c = Choice(question=q, text=form.cleaned_data['choice']) c.save() # finally, create the room itself, pointing to the question object, with the creator of the # currently logged in user, and the period length & join threshold as specified in the form # data. r = Room(question=q, opened_by=request.user, controller=request.user, period_length=room_form.cleaned_data['period_length'], join_threshold=room_form.cleaned_data['join_threshold']) r.save() # redirect the user to their newly created room return HttpResponseRedirect(r.get_absolute_url()) else: # if the user has not submitted the form (i.e. wishes to fill the form in) # then initialise the 3 forms with no data poll_form = PollForm() choice_formset = ChoiceFormSet() room_form = RoomForm() # put the forms into a context dictionary (and update that with any extra context we have been given) data = {'poll_form': poll_form, 'choice_formset': choice_formset, 'room_form': room_form} data.update(extra_context) # render the page return render_to_response('rooms/room_form.html', data, context_instance=RequestContext(request))
def addRooms(): form = RoomForm() if form.validate_on_submit(): if form.room_type.data == '-1': flash("Please choose a room type.") else: print(form.room_id.data) Rooms.insert(str(form.room_id.data), str(form.room_name.data), int(form.room_type.data), int(form.capacity.data)) return redirect(url_for('viewRooms')) return render_template('addRooms.html',form=form)
def submitRoom(request): if request.method == "POST": f = RoomForm(request.POST) if f.is_valid(): newRoom = Room(name=request.POST['name'], info=request.POST['info']) newRoom.save() return HttpResponseRedirect(reverse('juakstore:roomDetail', args=(newRoom.id,))) else: return render(request, 'juakstore/room_add.html', {'form' : f}) else: return HttpResponseRedirect(reverse('juakstore:roomCreate'))
def post(self, obj_id=None): """ Post room(s) Create a new room/ Update a room --- tags: - rooms parameters: - in: path name: obj_id - in: body name: body schema: id: Room required: - number properties: number: type: integer description: room number responses: 201: description: Room created """ data = self.prepare_data() form = RoomForm(data, csrf_enabled=False) if form.validate(): if obj_id: room = Room.get_by_id(int(obj_id)) if not room: abort(404, message="Room with key ({}) not found".format(obj_id)) room.is_booked = form.is_booked.data if form.is_booked.data else room.is_booked room.put() output = self.output_fields output.update(self.resource_fields) return marshal(room, output), 200 room = Room(number=form.number.data, is_booked=form.is_booked.data) room.put() room.id = str(room.key.id()) room.put() output = self.output_fields output.update(self.resource_fields) return marshal(room, output), 201 error_data = self.prepare_errors(form.errors) raise CustomException(code=400, name='Validation Failed', data=error_data)
def editRooms(): form = RoomForm() if form.validate_on_submit(): if form.room_type.data == '-1': flash("Please choose a room type.") else: room = Rooms.query.filter_by(location=form.room_id.data).first() if room is None: flash("Room not found. Please try again") else: room.edit(form.room_id.data, form.room_name.data, int(form.room_type.data), form.capacity.data) return redirect(url_for('viewRooms')) return render_template('addRooms.html',form=form)
def create(request): if request.method == 'POST': form = RoomForm(request.POST) if form.is_valid(): room = form.save(commit=False) room.owner = request.user room.save() url = reverse('rooms.views.edit', args=[room.id]) return HttpResponseRedirect(url) else: form = RoomForm() return { 'form' : form }
def new_room(): form = RoomForm(request.form) form.city.choices = [(city.id, city.desc) for city in db.session.query(City).all()] if request.method == 'POST' and form.validate(): room = form.getObj(Room()) room.user_id = current_user.id db.session.add(room) db.session.commit() path = "rooms/room" + str(room.id) os.mkdir(path) flash('Anúncio adicionado'.decode('utf-8'), 'success') return redirect(url_for('dashboard')) return render_template('room/edit_room.html', form=form, action='Adicionar')
def enter_room(request): if request.method == 'POST': form = RoomForm(request.POST) if form.is_valid(): try: form.save() except ValueError: return render_to_response('error.html', { 'error_type': "Room", 'error_name': "[" + form.cleaned_data['name'] + "]", 'error_info': "Room name cannot be validated, most likely a duplicate room" }, context_instance=RequestContext( request)) return render_to_response( 'thanks.html', { 'data_type': "Room", 'data_name': "[" + form.cleaned_data['name'] + "]", 'data_modification': "CREATED", 'enter_again': True }, context_instance=RequestContext(request)) else: form = RoomForm() return render_to_response('data_entry.html', { 'form': form, 'title': 'Create Room' }, context_instance=RequestContext(request))
def room_password(room_id): """Show the password form. Authenticate the password for the room with id of room_id.""" # If no one is logged in, show the anon home page. if not g.user: return render_template("home-anon.html") form = RoomForm() # If conditional will return true when the form submits a response if form.validate_on_submit(): room = Room.authenticate(id=room_id, password=form.password.data) if room: return redirect(f"/room/{room.id}") flash("Invalid credentials.", 'danger') return render_template("/room/password.html", form=form)
def new_room(): form = RoomForm(request.form) print form.errors if request.method == 'POST': Name = request.form['Name'] SensorID = request.form['SensorID'] print Name, " ", SensorID if request.method == "POST" and form.validate(): new_room = Room() new_room.Name = form.Name.data new_room.SensorID = form.SensorID.data db_session.add(new_room) db_session.commit() flash('Room Added Successfully!') else: flash(form.errors) return render_template('newroom.html', form=form)
def room_create_view(room=False): if room: context = {'edit': True} for key in room.keys(): if room[key] == None: room[key] = 'None' if len(room['npc']) == 0: room['npc'].append('None') if len(room['items']) == 0: room['items'].append('None') context['items'] = room['items'] context['npc'] = room['npc'] form = RoomForm(room) else: form = RoomForm() context = {'edit': False} context['items'] = [] context['npc'] = [] template_generate.refresh_template(r'room_form.html', form=form, context=context)
def enter_room(request): if request.method == 'POST': form = RoomForm(request.POST) if form.is_valid(): try: form.save() except ValueError: return render_to_response('error.html', {'error_type': "Room",'error_name': "["+form.cleaned_data['name']+"]", 'error_info':"Room name cannot be validated, most likely a duplicate room"}, context_instance=RequestContext(request)) return render_to_response('thanks.html', {'data_type': "Room", 'data_name': "["+form.cleaned_data['name']+"]", 'data_modification': "CREATED", 'enter_again': True}, context_instance=RequestContext(request)) else: form = RoomForm() return render_to_response('data_entry.html', {'form': form, 'title': 'Create Room'}, context_instance=RequestContext(request))
def add_room(request): list_rooms = Room.objects.order_by('number') if request.POST: form = RoomForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/success/') else: form = RoomForm() args={} args.update(csrf(request)) args['form']=form args['list_rooms'] = list_rooms return render(request,'add_room.html',args)
def edit_room(id): room = db.session.query(Room).filter(Room.id == id).one() form = RoomForm(request.form, room) form.city.choices = [(city.id, city.desc) for city in db.session.query(City).all()] if request.method == 'GET': city = City.query.get(room.city_id) form.city.choices = [(city.id, city.desc) for city in db.session.query(City).filter( City.state == city.state).all()] form.populateForm(room) if request.method == 'POST' and form.validate(): room = form.getObj(room) db.session.commit() flash('Anúncio Atualizado'.decode('utf-8'), 'success') return redirect(url_for('dashboard')) return render_template('room/edit_room.html', form=form, action='Editar')
def add(): form = RoomForm() if form.validate_on_submit(): jitmeet.add(form) return redirect(url_for('jitmeet.list')) return render_template('add.html', form=form)
def edit(id): room = jitmeet.get(id) form = RoomForm(obj=room) if jitmeet.edit(form, id): return redirect(url_for('jitmeet.list')) return render_template('edit.html', form=form)
def create_room(request, extra_context={}): """ View for creating a room. Uses a clever combination of PollForm, RoomForm and ChoiceFormSet to achieve 3-way model creation: - PollForm allows the user to specify the question - ChoiceFormSet allows the user to specify an arbitrary number of "choices" to go with the question (each one represented by its own DB object) - RoomForm gives more advanced "tweaks" for the room, for example: - period length (how long each period lasts, default is 30) - join threshold (the amount of time that a room is in lock mode before a poll begins) """ if request.method == "POST": # if the user has submitted the form, get the data from all three poll_form = PollForm(request.POST, request.FILES) choice_formset = ChoiceFormSet(request.POST, request.FILES) room_form = RoomForm(request.POST, request.FILES) if poll_form.is_valid() and choice_formset.is_valid( ) and room_form.is_valid(): # if all 3 forms are valid, create a new question object and save it q = Question(text=poll_form.cleaned_data['question']) q.save() # create a new poll object that points to the question, and save it p = Poll(question=q) p.save() # for every choice the user has inputted for form in choice_formset.forms: # create a new choice object, and point it at the question created earlier c = Choice(question=q, text=form.cleaned_data['choice']) c.save() # finally, create the room itself, pointing to the question object, with the creator of the # currently logged in user, and the period length & join threshold as specified in the form # data. r = Room(question=q, opened_by=request.user, controller=request.user, period_length=room_form.cleaned_data['period_length'], join_threshold=room_form.cleaned_data['join_threshold']) r.save() # redirect the user to their newly created room return HttpResponseRedirect(r.get_absolute_url()) else: # if the user has not submitted the form (i.e. wishes to fill the form in) # then initialise the 3 forms with no data poll_form = PollForm() choice_formset = ChoiceFormSet() room_form = RoomForm() # put the forms into a context dictionary (and update that with any extra context we have been given) data = { 'poll_form': poll_form, 'choice_formset': choice_formset, 'room_form': room_form } data.update(extra_context) # render the page return render_to_response('rooms/room_form.html', data, context_instance=RequestContext(request))