def adminhome(): room_count = 0 personnel_count = 0 views = 0 freq_rooms = RoomReport.select( fn.Count(RoomReport.id).alias('count'), Room.room_name).join(Room).group_by(RoomReport.room_report).order_by( fn.Count(RoomReport.id).desc()).limit(10) freq_services = ServiceReport.select( fn.Count(ServiceReport.id).alias('count'), Service.service_name).join(Service).group_by( ServiceReport.service_report).order_by( fn.Count(ServiceReport.id).desc()).limit(10) try: room_count = int(Room.select().count()) personnel_count = int(Personnel.select().count()) views = int(RoomReport.select().count()) latest_views = RoomReport.select().order_by( RoomReport.report_date.desc()).limit(10) return render_template('admindashboard.html', room_count=room_count, personnel_count=personnel_count, views=views, latest_views=latest_views, freq_rooms=freq_rooms, freq_services=freq_services) except Exception as e: flash(e) return render_template('admindashboard.html', room_count=room_count, personnel_count=personnel_count, views=views, latest_views=latest_views, freq_rooms=freq_rooms, freq_services=freq_services)
def getrooms(): rooms = [] for room in Room.select().where(Room.location.is_null(False)).order_by( Room.room_name): if room.college is not None: rooms.append({ 'id': room.id, 'room_name': room.room_name, 'room_desc': room.room_desc, 'location': room.location.floor, 'xCoord': room.location.xcoord, 'yCoord': room.location.ycoord, 'zCoord': room.location.zcoord, 'college': room.college.college_name, }) else: rooms.append({ 'id': room.id, 'room_name': room.room_name, 'room_desc': room.room_desc, 'location': room.location.floor, 'xCoord': room.location.xcoord, 'yCoord': room.location.ycoord, 'zCoord': room.location.zcoord, }) return jsonify({ 'rooms': rooms, })
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.assigned_office.choices = [ (a.id, a.room_name) for a in Room.select().where( Room.room_type == 'Office', Room.is_active == 1).order_by( Room.room_name) ]
def locations(operation): if operation == "assign": if LocationsForm(request.form).validate_on_submit(): location = request.form['location_name'] room = request.form['room_name'] query = Room.update(location=location, is_active=1).where(Room.id == room) query.execute() query = RoomLocation.update(occupied=1).where( RoomLocation.id == location) query.execute() val = Room.get(Room.id == room) return jsonify({ 'location_id': val.location.id, 'location_name': val.location.location_name, 'room_name': val.room_name, 'room_id': val.id, 'room_type': val.room_type, }) elif operation == "delete": location = RoomLocation.get(RoomLocation.id == request.form['id']) print(location.id) try: room = Room.get(Room.location == location.id) query = room.update(location=None, is_active=0).where(Room.id == room.id) query.execute() query = RoomLocation.update(occupied=0).where( RoomLocation.id == location.id) query.execute() return jsonify({ 'location_name': location.location_name, 'location_id': location.id, 'room_name': room.room_name, 'room_id': room.id, 'room_type': room.room_type, 'empty': 1, }) except Exception as e: return jsonify({ 'location_name': location.location_name, 'location_id': location.id, 'empty': 0, })
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.location_name.choices = [ (a.id, a.location_name) for a in RoomLocation.select().where(RoomLocation.occupied == 0) ] self.room_name.choices = [ (a.id, a.room_name) for a in Room.select().where(Room.is_active == 0) ]
def adminrooms(): room_create_form = RoomsForm(request.form) room_edit_form = RoomsForm(request.form) location_form = LocationsForm(request.form) active = None try: rooms = Room.select().order_by(Room.is_active) locations = RoomLocation.select().order_by(RoomLocation.id) return render_template('adminrooms.html', room_create_form=room_create_form, rooms=rooms, room_edit_form=room_edit_form, locations=locations, location_form=location_form, active=active) except Exception as e: flash(e) return render_template('adminrooms.html', room_create_form=room_create_form, room_edit_form=room_edit_form, locations=locations, location_form=location_form, active=active)
def crudroom(operation): if operation == "create": if RoomsForm(request.form).validate_on_submit(): room_name = request.form['room_name'] room_desc = request.form['room_desc'] room_type = request.form['room_type'] college = request.form['college'] status = "Inactive" if college != "0": room = Room.create(room_name=room_name, room_desc=room_desc, college=college, room_type=room_type) else: room = Room.create(room_name=room_name, room_desc=room_desc, room_type=room_type) return jsonify({ 'id': room.id, 'room_name': room.room_name, 'room_type': room.room_type, 'status': status, }) elif operation == "get": try: room = Room.get(Room.id == request.form['id']) college = 0 if room.college is not None: college = room.college.id return jsonify({ 'id': room.id, 'room_name': room.room_name, 'room_desc': room.room_desc, 'room_type': room.room_type, 'college': college, }) except Exception as e: flash(e) elif operation == "getall": rooms = [] try: for room in Room.select().where(Room.is_active == 0): rooms.append({ 'id': room.id, 'room_name': room.room_name, }) return jsonify(rooms) except Exception as e: flash(e) elif operation == "edit": location_id = 0 location_name = None if request.form['college'] == "0": query = Room.update( room_name=request.form['room_name'], room_desc=request.form['room_desc'], college=None, ).where(Room.id == request.form['id']) else: query = Room.update(room_name=request.form['room_name'], room_desc=request.form['room_desc'], college=request.form['college']).where( Room.id == request.form['id']) query.execute() room = Room.get(Room.id == request.form['id']) if room.is_active == 1: location_id = room.location.id location_name = room.location.location_name print(location_id, location_name) status = 'Inactive' if room.is_active: status = 'Active' return jsonify({ 'room_name': room.room_name, 'room_type': room.room_type, 'status': status, 'location_id': location_id, 'location_name': location_name, }) elif operation == "delete": room = Room.get(Room.id == request.form['id']) location_id = 0 location_name = None location = 0 if room.location is not None: location = room.id location_id = room.location.id location_name = room.location.location_name query = RoomLocation.update(occupied=0).where( RoomLocation.id == room.location.id) query.execute() room.delete_instance() return jsonify({ 'room_id': location, 'location_id': location_id, 'location_name': location_name }) return 'asdasd'
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.service.choices = [(a.id, a.service_name) for a in Service.select()] self.room.choices = [(a.id, a.room_name) for a in Room.select().where( Room.room_type == "Office", Room.is_active == 1)]