def jam_setup(slot_id=None, room_id=None): room_form = forms.RoomForm(request.form) slot_form = forms.SlotForm(request.form) if slot_id and request.method == "GET": slot = database.get_time_slots_objects().filter(database.WorkshopSlot.slot_id == slot_id).first() slot_form.slot_time_start.default = slot.slot_time_start slot_form.slot_time_end.default = slot.slot_time_end slot_form.slot_id.default = slot.slot_id slot_form.process() elif room_id and request.method == "GET": room = database.get_workshop_rooms_objects().filter(database.WorkshopRoom.room_id == room_id).first() room_form.room_name.default = room.room_name room_form.room_capacity.default = room.room_capacity room_form.room_volunteers_needed.default = room.room_volunteers_needed room_form.room_id.default = room.room_id room_form.process() if request.method == 'POST' and (slot_form.validate()): if slot_form.slot_time_start.data < slot_form.slot_time_end.data: database.add_slot(slot_form.slot_id.data, slot_form.slot_time_start.data, slot_form.slot_time_end.data) else: flash("Error - Start time is after end time!", "danger") return redirect(('admin/jam_setup')) elif request.method == 'POST' and room_form.validate(): if not database.add_workshop_room(room_id, room_form.room_name.data, room_form.room_capacity.data, room_form.room_volunteers_needed.data): flash("Error - Unable to add new workshop room. Does a workshop already exist with that name?", "danger") return render_template('admin/jam_setup.html', form_room=room_form, form_slot=slot_form, rooms=database.get_workshop_rooms_objects(), slots=database.get_time_slots_objects())
def building(request, building_id): building = get_object_or_404(models.Building, pk=building_id, owner=request.user) # get room form and prepopulate building_id field as the current building room_form = forms.RoomForm(request, initial={'building': building_id}) return render(request, 'website/building.html', { 'building': building, 'room_form': room_form })
def room_new(request): """ Create a new room and redirect to it's building """ if request.method == 'POST': form = forms.RoomForm(request, request.POST) if form.is_valid(): # check building is owned by user if form.cleaned_data['building'].owner == request.user: room = form.save(commit=False) room.owner = request.user room.save() return HttpResponseRedirect( reverse('building', args=(form.cleaned_data['building'].id, ))) else: return render(request, 'website/room_new.html', {'form': form}) else: form = forms.RoomForm(request) return render(request, 'website/room_new.html', {'form': form})
def post(self): form = forms.RoomForm(self) if form.validate(): room = Model(owner=self.current_user._id, admins=[self.current_user._id], members=[self.current_user._id], topic='', current_users=[self.current_user._id]) form.populate_obj(room) room.token = util.generate_token(32) self.db.rooms.insert(room) self.redirect(self.reverse_url('room', room._id)) else: self.render('new.html', form=form)
def post(self): form = forms.RoomForm(self, obj=self.room) if form.validate(): form.populate_obj(self.room) self.db.rooms.save(self.room) self.memcache.set('rooms/%s' % self.room._id, self.room.items()) self.pubnub.publish({ 'channel': self.room.token, 'message': { 'type': 'topic_changed', 'content': self.room.topic, 'user_name': self.current_user.name or self.current_user.email, } }) self.redirect(self.reverse_url('room', self.room._id)) else: self.render('settings.html')
def get(self): form = forms.RoomForm(obj=self.room) if self.is_ajax: self.write(self.ui['modules']['Settings'](form=form)) else: self.render('settings.html', form=form)
def get(self): form = forms.RoomForm() self.render('new.html', form=form)