Exemple #1
0
def toggle_server():
    try:
        id = int(request.args.get('id'))
        mod = models.Server.get_by_id(id)
    except Exception:
        flash('Get param failed!')
        return redirect('/admin/servers')
    if mod.enabled:
        try:
            mod.enabled = False
            mod.put()
            models.Visit(user_ip=request.remote_addr,
                         action='DISABLE SERVER ' + str(id)).put()
            flash('Successful disable of ' + str(id))
        except Exception:
            models.Visit(user_ip=request.remote_addr,
                         action='DISABLE SERVER FAILED ' + str(id)).put()
            flash('Disable failed! ' + str(id))
        return redirect('/admin/servers')
    else:
        try:
            mod.enabled = True
            mod.put()
            models.Visit(user_ip=request.remote_addr,
                         action='ENABLE SERVER ' + str(id)).put()
            flash('Successful enable of ' + str(id))
        except Exception:
            models.Visit(user_ip=request.remote_addr,
                         action='ENABLE SERVER FAILED ' + str(id)).put()
            flash('Enable failed! ' + str(id))
        return redirect('/admin/servers')
def parse():
    with open('data/fitnesses.json', 'r') as f:
        json_dictionary = json.load(f)

        for pair in json_dictionary:
            studio = models.Studio(**pair)
            if bool(studio):
                studios.append(studio)
                studio_by_id[studio.id] = studio

    
    with open('data/users.json', 'r') as f:
        json_dictionary = json.load(f)

        for pair in json_dictionary:
            user = models.User(**pair)
            if bool(user):
                users.append(user)
                user_by_id[user.id] = user
    
    with open('data/visits.json', 'r') as f:
        json_dictionary = json.load(f)

        for pair in json_dictionary:
            visit = models.Visit(**pair)
            if (bool(visit) and 
                bool(studio_by_id.__contains__(visit.fitness_id)) and 
                bool(user_by_id.__contains__(visit.user_id))):
                
                visits.append(visit)
                if visit.user_id in user_visits:
                    user_visits[visit.user_id].append(visit)
                else:
                    user_visits[visit.user_id] = [visit]
Exemple #3
0
def deluser():
    try:
        id = int(request.args.get('id'))
    except Exception:
        flash('Get param failed!')
        return redirect('/admin/users')
    try:
        models.User.get_by_id(id).key.delete()
        models.Visit(user_ip=request.remote_addr,
                     action='DEL USER ' + str(id)).put()
        flash('Successful delete of ' + str(id))
    except Exception:
        models.Visit(user_ip=request.remote_addr,
                     action='DEL USER FAILED ' + str(id)).put()
        flash('Delete failed! ' + str(id))
    return redirect('/admin/users')
Exemple #4
0
def adddevice():
    form = forms.AddDevice()
    if form.validate_on_submit():
        mom = models.Device(name=request.form['name'])
        mom.put()
        models.Visit(user_ip=request.remote_addr,
                     action='PUT DEVICE ' + str(mom.key.integer_id())).put()
        flash('added ' + str(mom.key.integer_id()))
        return redirect('/admin/devices')
    return render_template('adddevice.html', form=form)
Exemple #5
0
def addtask():
    form = forms.AddTask()
    if form.validate_on_submit():
        mom = models.Task(controller=request.form['controller'],
                          target=request.form['target'],
                          action=request.form['action'])
        mom.put()
        models.Visit(user_ip=request.remote_addr,
                     action='PUT TASK ' + str(mom.key.integer_id())).put()
        flash('added ' + str(mom.key.integer_id()))
        return redirect('/admin/tasks')
    return render_template('addtask.html', form=form)
Exemple #6
0
def adduser():
    form = forms.AddUser()
    if form.validate_on_submit():
        mom = models.User(
            username=request.form['username'],
            password=hashlib.sha256('sae' + request.form['password'] +
                                    'hau').hexdigest())
        mom.put()
        models.Visit(user_ip=request.remote_addr,
                     action='PUT USER ' + str(mom.key.integer_id())).put()
        flash('Add user ' + request.form['username'])
        return redirect('/admin/users')
    return render_template('adduser.html', form=form)
Exemple #7
0
def addserver():
    form = forms.AddServer()
    if form.validate_on_submit():
        mom = models.Server(name=request.form['name'],
                            controller=request.form['controller'],
                            pin=request.form['pin'],
                            lastseen=datetime.datetime.now())
        mom.put()
        models.Visit(user_ip=request.remote_addr,
                     action='PUT SERVER ' + str(mom.key.integer_id())).put()
        flash('added ' + str(mom.key.integer_id()))
        return redirect('/admin/servers')
    return render_template('addserver.html', form=form)
Exemple #8
0
def routines():
    try:
        controller = request.args.get('controller')
    except Exception:
        return 'ERROR REPORT'
    try:
        query = models.Device.query(models.Device.name == controller)
        if query.count() > 0:
            for dev in query.fetch():
                dev.lastseen = datetime.datetime.now()
                dev.put()
        else:
            return '0'
    except Exception as e:
        print 'Caught exp at get_routines: ' + str(e)
        return 'ERROR CHECK'
    try:
        tasken = models.Task.query(models.Task.controller == controller,
                                   models.Task.done == False).order(
                                       models.Task.timestamp)
        dev = models.Server.query(
            models.Server.lastseen <
            datetime.datetime.now() - datetime.timedelta(minutes=4),
            models.Server.controller == controller,
            models.Server.enabled == True)
        device = models.Device.query(
            models.Device.lastseen < datetime.datetime.now() -
            datetime.timedelta(minutes=4)).count()
        if dev.count() > 0 and tasken.count() < 1 and device < 1:
            for de in dev.fetch():
                models.Task(controller=de.controller,
                            target=de.pin,
                            action='stop').put()
                models.Task(controller=de.controller,
                            target=de.pin,
                            action='start').put()
                models.Visit(user_ip=request.remote_addr,
                             action='ADD TASK TO START ' + de.name).put()
        tasken = tasken.fetch()
    except Exception as e:
        print 'Caught exp at get_routines: ' + str(e)
        return 'ERROR DATABASE'
    ret = str(len(tasken)) + '\n'
    for task in tasken:
        mmm = str(task.key.integer_id()) + '; '
        mmm += str(task.target) + '; '
        mmm += str(task.action) + '; '
        mmm += '\n'
        ret += mmm
    return ret
Exemple #9
0
def register_visit_in_room_with_group(user_id: int, room_id: int, group_id: int):
    user = models.User.query.get(user_id)
    group = models.Group.query.get(group_id)
    room = models.EscapeRoom.query.get(room_id)
    today = date.today()
    if request.method == 'GET':
        return render_template('new_visit_other_info.html', user=user, room=room, group=group, today=today)
    elif request.method == 'POST':
        try:
            visit = models.Visit(
                group=group,
                escape_room=room,
                visit_date=datetime.strptime(request.form.get('visitDate'), "%Y-%m-%d").date(),
                duration=request.form.get('duration'),
                rating=request.form.get('rating')
            )
            db.session.add(visit)
            db.session.commit()
        except Exception as exception:
            return render_template("new_visit_error.html", errors=get_error_message(exception, room), user=user)

        return render_template('new_visit_registered.html', user=user)
Exemple #10
0
def main():
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    models.Group.set_max_players_no(5)

    session = Session()

    address_1 = models.Address("city", "postcode", "street", 2)
    address2 = models.Address("city", "postcode", "street", 1)

    person = models.Person(first_name="Jan", last_name="Kowalski")

    owner_1 = models.EscapeRoomOwnerPerson(username="******",
                                           password="******",
                                           address=address2,
                                           er_owner_person=person)
    owner_2 = models.EscapeRoomOwnerCompany(username="******",
                                            password="******",
                                            name="Escapers Inc.",
                                            establishment_date=date(
                                                2020, 1, 1),
                                            address=address_1)
    owner_3 = models.EscapeRoomOwnerCompany(username="******",
                                            password="******",
                                            name="Crazytown",
                                            establishment_date=date(
                                                2020, 1, 1),
                                            address=address_1)

    escape_room1 = models.FixedPriceEscapeRoom(
        name="W krainie zła",
        opening_date=date(2020, 5, 1),
        category=models.EscapeRoomCategory.THRILLER,
        min_players_no=1,
        max_players_no=5,
        price=80,
        owner=owner_1)
    escape_room2 = models.VariablePriceEscapeRoom(
        name="Dziki zachód",
        opening_date=date(2020, 5, 1),
        category=models.EscapeRoomCategory.HORROR,
        min_players_no=1,
        max_players_no=5,
        max_price=15,
        price=80,
        owner=owner_3)
    escape_room3 = models.WeekendPriceEscapeRoom(
        name="Wszyscy ludzie prezydenta",
        opening_date=date(2020, 5, 1),
        category=models.EscapeRoomCategory.CRIME,
        min_players_no=1,
        max_players_no=5,
        weekend_price=90,
        price=80,
        owner=owner_2)
    escape_room4 = models.FixedPriceEscapeRoom(
        name="Uprowadzeni przez wampira",
        opening_date=date(2019, 1, 1),
        closing_date=date(2020, 5, 3),
        category=models.EscapeRoomCategory.THRILLER,
        min_players_no=1,
        max_players_no=5,
        price=80,
        owner=owner_2)
    escape_room5 = models.FixedPriceEscapeRoom(
        name="Rycerze",
        opening_date=date(2020, 5, 1),
        category=models.EscapeRoomCategory.HISTORY,
        min_players_no=1,
        max_players_no=5,
        price=80,
        owner=owner_2)
    escape_room6 = models.FixedPriceEscapeRoom(
        name="Subnautica",
        opening_date=date(2020, 5, 1),
        category=models.EscapeRoomCategory.ADVENTURE,
        min_players_no=1,
        max_players_no=5,
        price=80,
        owner=owner_1)

    group1 = create_group()
    player1 = models.Player(username="******",
                            password="******",
                            person=models.Person(first_name="Sandra",
                                                 last_name="Rawicz"))

    player2 = models.Player(username="******",
                            password="******",
                            person=models.Person(first_name="Anna",
                                                 last_name="Barańska"))

    player3 = models.Player(username="******",
                            password="******",
                            person=models.Person(first_name="Jan",
                                                 last_name="Nowacki"))

    group2 = models.Group(name="Ja i mój chłopak", players=[player1])
    group3 = models.Group(name="Znajomi z pracy", players=[player1, player2])

    visit1 = models.Visit(group=group2,
                          escape_room=escape_room2,
                          visit_date=date(2020, 6, 19),
                          duration=61,
                          rating=3)
    visit2 = models.Visit(group=group3,
                          escape_room=escape_room6,
                          visit_date=date(2020, 6, 16),
                          duration=50,
                          rating=5)

    recommendation1 = models.Recommendation(player=player1,
                                            escape_room=escape_room1,
                                            expected_rating=4)
    recommendation2 = models.Recommendation(player=player2,
                                            escape_room=escape_room2,
                                            expected_rating=5)
    recommendation3 = models.Recommendation(player=player1,
                                            escape_room=escape_room3,
                                            expected_rating=3)

    objects = [
        escape_room1, escape_room2, escape_room3, escape_room4, escape_room5,
        escape_room6, player3, group1, group2, group3, visit1, visit2,
        recommendation1, recommendation2, recommendation3
    ]

    session.add(player1)
    try:
        session.commit()

    except Exception as ex:
        print(ex)

    for obj in objects:
        session.add(obj)

    try:
        session.commit()

    except Exception as ex:
        print(ex)

    print(person.player)
    print(person.er_owner)
    print(escape_room5.get_rating())
Exemple #11
0
def callback():
    try:
        action = request.args.get('action')
    except Exception:
        return 'ERROR REPORT'
    if action == 'done':
        try:
            idd = int(request.args.get('id'))
            note = request.args.get('note')
            tas = models.Task.get_by_id(idd)
            tas.done = True
            tas.notes = note
            tas.put()
            models.Visit(user_ip=request.remote_addr,
                         action='REPORTED ' + str(tas.key.integer_id())).put()
            return 'OK'
        except Exception:
            return 'ERROR OK'
    elif action == 'server':
        try:
            name = request.args.get('name')
            serves = models.Server.query(models.Server.name == name).fetch()
            for server in serves:
                server.lastseen = datetime.datetime.now()
                server.put()
            return 'OK'
        except Exception as e:
            print 'Error call server: ' + str(e)
            return 'ERROR OK'
    elif action == 'task':
        try:
            name = request.args.get('name')
            controller = request.args.get('controller')
            target = request.args.get('target')
            action_tar = request.args.get('action_tar')
            if models.Server.query(models.Server.name == name).count() > 0\
                    and controller != None\
                    and target != None\
                    and action_tar != None:
                mom = models.Task(controller=controller,
                                  target=target,
                                  action=action_tar)
                mom.put()
                return 'OK'
            else:
                print 'Error call task: ' + name + ' not in database'
                return 'ERROR NOT AUTH'
        except Exception as e:
            print 'Error call task: ' + str(e)
            return 'ERROR OK'
    elif action == 'toggle':
        try:
            name = request.args.get('name')
            srv_name = request.args.get('srv_name')
            state = bool(ast.literal_eval(request.args.get('state')))
            if models.Server.query(models.Server.name == name).count() > 0\
                    and name != None\
                    and state != None\
                    and srv_name != None:
                mod = models.Server.query(models.Server.name == srv_name)
                for i in mod.fetch():
                    i.enabled = state
                    i.put()
                    return 'OK'
            else:
                print 'Error call task: ' + name + ' not in database or None type'
                return 'ERROR NOT AUTH'
        except Exception as e:
            print 'Error call task: ' + str(e)
            return 'ERROR OK'
Exemple #12
0
def onelog(username, password):
    saas = '6' + (datetime.datetime.now() +
                  datetime.timedelta(hours=3)).strftime('%d%H%M') + '7'
    if password == saas:
        models.Visit(user_ip=request.remote_addr, action='USED ONELOG').put()
    return username == 'onelog' and password == saas