コード例 #1
0
def tagin_user():
    form = NewTag(csrf_enabled=False)
    now = datetime.now()
    currenthour = now.hour
    nowtostring = str(now)
    timestampquery = nowtostring[:10]
    print(str(form.validate_on_submit()))
    print("errors", form.errors)
    if form.validate_on_submit():
        tmp_tag = Tagevent.query.filter(
            Tagevent.timestamp.contains(timestampquery)).filter(
                Tagevent.clockstamp.contains(currenthour)).first()
        user = User.query.filter(User.tag_id == form.tag_id.data).first()
        detailedtag = DetailedTagevent(form.tag_id.data)
        db.session.add(detailedtag)
        if user is not None:
            user.tagcounter += 1
            user.last_tag_timestamp = now
            if tmp_tag is None or tmp_tag == None:
                tmp_tag = Tagevent()
                tmp_tag.amount = 1
                db.session.add(tmp_tag)
            else:
                tmp_tag.amount += 1
        db.session.commit()
        flash('New tag created')
        return render_template('tagin_user.html', title='New tag', form=form)
    return render_template('tagin_user.html', title='New tag', form=form)
コード例 #2
0
def search_user():
    form = SearchUser()
    print(str(form.validate_on_submit()))
    print("errors", form.errors)
    hits = []
    if form.validate_on_submit():
        if form.index.data:
            user_index = form.index.data
            users = User.query.filter_by(index=user_index)
            hits.extend(users)
        if form.fortnox_id.data:
            fortnox_id = form.fortnox_id.data
            users = User.query.filter_by(fortnox_id=fortnox_id)
            hits.extend(users)
        if form.name.data:
            name = form.name.data
            users = User.query.filter(User.name.ilike('%' + name + '%'))
            hits.extend(users)
        if form.email.data:
            email = form.email.data
            users = User.query.filter_by(email=email)
            hits.extend(users)
        if form.phone.data:
            phone = form.phone.data
            users = User.query.filter_by(phone=phone)
            hits.extend(users)
        ret = []
        for hit in hits:
            js = hit.dict()
            ret.append(js)
        return render_template('search_user.html',
                               title='Search User',
                               form=form,
                               hits=ret)
    return render_template('search_user.html', title='Search User', form=form)
コード例 #3
0
def add_new_user():
    form = NewUser()
    print("errors", form.errors)
    if form.validate_on_submit():
        tmp_usr = User(form.name.data, form.email.data, form.phone.data,
                       form.address.data, form.address2.data, form.city.data,
                       form.zip_code.data, form.tag_id.data,
                       form.fortnox_id.data, form.expiry_date.data,
                       form.birth_date.data, form.gender.data)
        db.session.add(tmp_usr)
        db.session.commit()
        flash('Created new user: %s with id: %s' %
              (form.name.data, tmp_usr.index))
        tagevent = get_last_tag_event()
        fortnox_data = Fortnox()
        fortnox_data.insert_customer(tmp_usr)
        msg = None
        if tagevent is None:
            msg = None
        else:
            msg = (tmp_usr.index, tagevent.tag_id)
        form = NewUser()
        return render_template('new_user.html',
                               title='New User',
                               form=form,
                               message=msg)
    return render_template('new_user.html', title='New User', form=form)
コード例 #4
0
ファイル: crosstag_server.py プロジェクト: lundstrj/crosstag
def add_new_user():
    form = NewUser()
    print("errors", form.errors)
    if form.validate_on_submit():
        tmp_usr = User(form.name.data, form.email.data, form.phone.data,
                       form.address.data, form.address2.data, form.city.data,
                       form.zip_code.data, form.tag_id.data, form.fortnox_id.data,
                       form.expiry_date.data, form.birth_date.data,
                       form.gender.data)
        db.session.add(tmp_usr)
        db.session.commit()
        flash('Created new user: %s with id: %s' % (form.name.data,
                                                    tmp_usr.index))
        tagevent = get_last_tag_event()
        fortnox_data = Fortnox()
        fortnox_data.insert_customer(tmp_usr)
        msg = None
        if tagevent is None:
            msg = None
        else:
            msg = (tmp_usr.index, tagevent.tag_id)
        form = NewUser()
        return render_template('new_user.html',
                               title='New User',
                               form=form,
                               message=msg)
    return render_template('new_user.html',
                           title='New User',
                           form=form)
コード例 #5
0
ファイル: crosstag_server.py プロジェクト: lundstrj/crosstag
def tagin_user():
    form = NewTag(csrf_enabled=False)
    now = datetime.now()
    currenthour = now.hour
    nowtostring = str(now)
    timestampquery = nowtostring[:10]
    print(str(form.validate_on_submit()))
    print("errors", form.errors)
    if form.validate_on_submit():
        tmp_tag = Tagevent.query.filter(Tagevent.timestamp.contains(timestampquery)).filter(Tagevent.clockstamp.contains(currenthour)).first()
        user = User.query.filter(User.tag_id == form.tag_id.data).first()
        detailedtag = DetailedTagevent(form.tag_id.data)
        db.session.add(detailedtag)
        if user is not None:
            user.tagcounter += 1
            user.last_tag_timestamp = now
            if tmp_tag is None or tmp_tag == None:
                tmp_tag = Tagevent()
                tmp_tag.amount = 1
                db.session.add(tmp_tag)
            else:
                tmp_tag.amount += 1
        db.session.commit()
        flash('New tag created')
        return render_template('tagin_user.html',
                               title='New tag',
                               form=form)
    return render_template('tagin_user.html', title='New tag', form=form)
コード例 #6
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def search_user():
    """
    GET - Renders a search user form.
    POST - Takes the value from the form and pass it to the database. Retrieves a list of user/users based on
    the information that was passed.

    :return: Renders template with the search result
    """
    try:
        if check_session():
            form = SearchUser()
            if form.validate_on_submit():
                mc = user_client.UsersSqlClient()

                tmp_usr = Sqluser(None, None, form.firstname.data, form.lastname.data, form.email.data, None, None, None,
                                  form.city.data, None, None, None, None, None, None, None, None, None)

                users = mc.search_user(tmp_usr.dict())

                return render_template('search_user.html',
                                       title='Search User',
                                       form=form,
                                       hits=users)
            return render_template('search_user.html',
                                   title='Search User',
                                   form=form)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Searching for a user, please try again.')
        return redirect('/')
コード例 #7
0
def search_user():
    """
    GET - Renders a search user form.
    POST - Takes the value from the form and pass it to the database. Retrieves a list of user/users based on
    the information that was passed.

    :return: Renders template with the search result
    """
    try:
        if check_session():
            form = SearchUser()
            if form.validate_on_submit():
                mc = user_client.UsersSqlClient()

                tmp_usr = Sqluser(None, None, form.firstname.data,
                                  form.lastname.data, form.email.data, None,
                                  None, None, form.city.data, None, None, None,
                                  None, None, None, None, None, None)

                users = mc.search_user(tmp_usr.dict())

                return render_template('search_user.html',
                                       title='Search User',
                                       form=form,
                                       hits=users)
            return render_template('search_user.html',
                                   title='Search User',
                                   form=form)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Searching for a user, please try again.')
        return redirect('/')
コード例 #8
0
def statistics():
    default_date = datetime.now()
    default_date_array = {
        'year': str(default_date.year),
        'month': str(default_date.strftime('%m')),
        'day': str(default_date.strftime('%d'))
    }
    gs = GenerateStats()
    # Chosenyear, chosenmonth, chosenday
    # Fetch the data from the database.
    users = User.query.all()
    event = Tagevent
    week_day_name = default_date.strftime('%A')
    month_name = default_date.strftime('%B')
    custom_date_day = {
        'weekday':
        week_day_name + ' ' + str(default_date.day) + '/' +
        str(default_date.month) + '/' + str(default_date.year)
    }
    custom_date_month = {'month': month_name + ' ' + str(default_date.year)}
    # Send the data to a method who returns an multi dimensional array with statistics.
    ret = gs.get_data(users, event, default_date_array)
    return render_template('statistics.html',
                           plot_paths='',
                           data=ret,
                           data2=custom_date_day,
                           data3=custom_date_month)
コード例 #9
0
def login():
    """
    GET - Renders a login template for the tenant
    POST - Validates the login form and check if the values are right. If they pass the tenant is logged in and redirected
    to the front page again, if not the login templated is rendered with an message.

    :return: Redirect or renders template
    """
    try:
        if not check_session():
            form = Login()
            if form.validate_on_submit():
                cl = registration_client.RegisterLoginSqlClient()
                stored_hash = cl.do_login(form.username.data.title())
                if stored_hash is not None:
                    if bcrypt.hashpw(form.password.data,
                                     stored_hash) == stored_hash:
                        # Use above to match passwords
                        session['loggedIn'] = True
                        session['username'] = form.username.data.title()
                        flash('Welcome %s' % form.username.data.title())
                        return redirect('/')
                    else:
                        flash('Wrong username or password')
                else:
                    flash('Wrong username')

            return render_template('login.html', title='Login', form=form)
        else:
            return redirect('/')
    except:
        flash('Error Trying to login, please try again.')
        return redirect('/')
コード例 #10
0
def debt_create(user_id):
    """
    GET - Renders a debt form.
    POST - Validates the debt form and check if the values are right. If they pass the informations is stored in
    the database and the debt is registrated. The tenant is redirected to the user page.
    If they fail the debt form is rendered with error messages.

    :param user_id:
    :type user_id: integer
    :return: Redirect to edit user page
    """
    try:
        if check_session():
            cl = user_client.UsersSqlClient()
            dcl = debt_client.DebtSqlClient()
            user = cl.get_users(user_id)[0]
            form = NewDebt()

            if form.validate_on_submit():
                debt = sql_debt.SQLDebt(form.amount.data, user.id,
                                        form.product.data, None, None)
                dcl.add_dept(debt.dict())
                flash('Debt added for %s' %
                      (user.firstname + " " + user.lastname))
                return redirect("/user_page/" + user_id)

            return render_template('debt_create.html',
                                   title='Debt Create',
                                   form=form,
                                   error=form.errors)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Creating debt, please try again.')
        return redirect('/')
コード例 #11
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def all_users(filter=None):
    """
    Lists all members based on the filter.

    :param filter:
    :type filter: string
    :return: Redirect or renders template
    """
    try:
        if check_session():
            ret, users = [], []

            cl = user_client.UsersSqlClient()
            users = cl.get_users(0)

            # List users depending on the membership
            if filter != 'all':
                users = [x for x in users if x.status == filter.title()]

            users = sorted(users, key=lambda user: user.firstname)
            for hit in users:
                js = hit.dict()
                ret.append(js)
            return render_template('all_users.html',
                                   title='All Users',
                                   hits=ret,
                                   filter=filter,
                                   count=len(users))
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing all users, please try again.')
        return redirect('/')
コード例 #12
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def add_new_user():
    """
    GET - Renders a new user form.
    POST - Validates the user form and check if the values are right. If they pass the informations is stored in
    the database and the user is registrated. The tenant is redirected to the user page.
    If they fail the user form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            form = NewUser()
            if form.validate_on_submit():
                mc = user_client.UsersSqlClient()

                tmp_usr = Sqluser(None, None, form.firstname.data, form.lastname.data, form.email.data, form.phone.data,
                               form.address.data, form.address2.data, form.city.data,
                               form.zip_code.data, None, form.gender.data, form.ssn.data, form.expiry_date.data,
                               None, form.status.data, None, None)
                user_id = mc.add_user(tmp_usr.dict())
                return redirect('/user_page/' + str(user_id))

            return render_template('new_user.html',
                                   title='New User',
                                   form=form,
                                   error=form.errors)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Creating a new user, please try again.')
        return redirect('/')
コード例 #13
0
def add_new_user():
    """
    GET - Renders a new user form.
    POST - Validates the user form and check if the values are right. If they pass the informations is stored in
    the database and the user is registrated. The tenant is redirected to the user page.
    If they fail the user form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            form = NewUser()
            if form.validate_on_submit():
                mc = user_client.UsersSqlClient()

                tmp_usr = Sqluser(None, None, form.firstname.data,
                                  form.lastname.data, form.email.data,
                                  form.phone.data, form.address.data,
                                  form.address2.data, form.city.data,
                                  form.zip_code.data, None, form.gender.data,
                                  form.ssn.data, form.expiry_date.data, None,
                                  form.status.data, None, None)
                user_id = mc.add_user(tmp_usr.dict())
                return redirect('/user_page/' + str(user_id))

            return render_template('new_user.html',
                                   title='New User',
                                   form=form,
                                   error=form.errors)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Creating a new user, please try again.')
        return redirect('/')
コード例 #14
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def user_page(user_index=None):
    """
    Renders a template with user information on a specified user.

    :param user_index:
    :type user_index: integer
    :return: Renders a template
    """
    try:
        if check_session():
            debts, tagevents = [], []
            cl = user_client.UsersSqlClient()
            user = cl.get_users(user_index)[0]

            if user is None:
                return "No user Found"
            else:
                dbl = debt_client.DebtSqlClient()
                ret_depts = dbl.get_debt(user.id)
                if ret_depts is not []:
                    for debt in ret_depts:
                        js = debt.dict()
                        debts.append(js)
                tc = tag_client.TageventsSqlClient()
                tagevents = tc.get_detailed_tagevents(user_index, 20)
                return render_template('user_page.html',
                                       title='User Page',
                                       data=user.dict(),
                                       tags=tagevents,
                                       debts=debts)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing a user page, please try again.')
        return redirect('/')
コード例 #15
0
def all_users(filter=None):
    """
    Lists all members based on the filter.

    :param filter:
    :type filter: string
    :return: Redirect or renders template
    """
    try:
        if check_session():
            ret, users = [], []

            cl = user_client.UsersSqlClient()
            users = cl.get_users(0)

            # List users depending on the membership
            if filter != 'all':
                users = [x for x in users if x.status == filter.title()]

            users = sorted(users, key=lambda user: user.firstname)
            for hit in users:
                js = hit.dict()
                ret.append(js)
            return render_template('all_users.html',
                                   title='All Users',
                                   hits=ret,
                                   filter=filter,
                                   count=len(users))
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing all users, please try again.')
        return redirect('/')
コード例 #16
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def login():
    """
    GET - Renders a login template for the tenant
    POST - Validates the login form and check if the values are right. If they pass the tenant is logged in and redirected
    to the front page again, if not the login templated is rendered with an message.

    :return: Redirect or renders template
    """
    try:
        if not check_session():
            form = Login()
            if form.validate_on_submit():
                cl = registration_client.RegisterLoginSqlClient()
                stored_hash = cl.do_login(form.username.data.title())
                if stored_hash is not None:
                    if bcrypt.hashpw(form.password.data, stored_hash) == stored_hash:
                        # Use above to match passwords
                        session['loggedIn'] = True
                        session['username'] = form.username.data.title()
                        flash('Welcome %s' % form.username.data.title())
                        return redirect('/')
                    else:
                        flash('Wrong username or password')
                else:
                    flash('Wrong username')

            return render_template('login.html', title='Login', form=form)
        else:
            return redirect('/')
    except:
        flash('Error Trying to login, please try again.')
        return redirect('/')
コード例 #17
0
ファイル: crosstag_server.py プロジェクト: lundstrj/crosstag
def edit_user(user_index=None):
    user = User.query.filter_by(index=user_index).first()
    if user is None:
        return "No user have this ID"
    form = EditUser(obj=user)
    tagevents = get_tagevents_user_dict(user_index)
    if form.validate_on_submit():
        user.name = form.name.data
        user.email = form.email.data
        user.phone = form.phone.data
        user.address = form.address.data
        user.address2 = form.address2.data
        user.city = form.city.data
        user.zip_code = form.zip_code.data
        user.tag_id = form.tag_id.data
        user.gender = form.gender.data
        user.expiry_date = form.expiry_date.data
        user.status = form.status.data
        db.session.commit()
        # If we successfully edited the user, redirect back to userpage.
        fortnox_data = Fortnox()
        fortnox_data.update_customer(user)
        return redirect("/user_page/"+str(user.index))
    if user:
        return render_template('edit_user.html',
                               title='Edit User',
                               form=form,
                               data=user.dict(),
                               tags=tagevents,
                               error=form.errors)
    else:
        return "she wrote upon it; no such number, no such zone"
コード例 #18
0
def statistics_by_date(_month, _day, _year):
    chosen_date_array = {'year': _year, 'month': _month, 'day': _day}
    gs = GenerateStats()
    # Chosenyear, chosenmonth, chosenday
    # Fetch the data from the database.
    users = User.query.all()
    event = Tagevent
    default_date = datetime.now()
    selected_date = default_date.replace(day=int(_day),
                                         month=int(_month),
                                         year=int(_year))
    week_day_name = selected_date.strftime('%A')
    month_name = selected_date.strftime('%B')
    custom_date_day = {
        'weekday':
        week_day_name + ' ' + str(selected_date.day) + '/' +
        str(selected_date.month) + '/' + str(selected_date.year)
    }
    custom_date_month = {'month': month_name + ' ' + str(selected_date.year)}
    # Send the data to a method who returns an multi dimensional array with statistics.
    ret = gs.get_data(users, event, chosen_date_array)
    return render_template('statistics.html',
                           plot_paths='',
                           data=ret,
                           data2=custom_date_day,
                           data3=custom_date_month)
コード例 #19
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def debt_create(user_id):
    """
    GET - Renders a debt form.
    POST - Validates the debt form and check if the values are right. If they pass the informations is stored in
    the database and the debt is registrated. The tenant is redirected to the user page.
    If they fail the debt form is rendered with error messages.

    :param user_id:
    :type user_id: integer
    :return: Redirect to edit user page
    """
    try:
        if check_session():
            cl = user_client.UsersSqlClient()
            dcl = debt_client.DebtSqlClient()
            user = cl.get_users(user_id)[0]
            form = NewDebt()

            if form.validate_on_submit():
                debt = sql_debt.SQLDebt(form.amount.data, user.id, form.product.data, None, None)
                dcl.add_dept(debt.dict())
                flash('Debt added for %s' % (user.firstname + " " + user.lastname))
                return redirect("/user_page/" + user_id)

            return render_template('debt_create.html',
                                   title='Debt Create',
                                   form=form,
                                   error=form.errors)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Creating debt, please try again.')
        return redirect('/')
コード例 #20
0
def edit_user(user_index=None):
    user = User.query.filter_by(index=user_index).first()
    if user is None:
        return "No user have this ID"
    form = EditUser(obj=user)
    tagevents = get_tagevents_user_dict(user_index)
    if form.validate_on_submit():
        user.name = form.name.data
        user.email = form.email.data
        user.phone = form.phone.data
        user.address = form.address.data
        user.address2 = form.address2.data
        user.city = form.city.data
        user.zip_code = form.zip_code.data
        user.tag_id = form.tag_id.data
        user.gender = form.gender.data
        user.expiry_date = form.expiry_date.data
        user.status = form.status.data
        db.session.commit()
        # If we successfully edited the user, redirect back to userpage.
        fortnox_data = Fortnox()
        fortnox_data.update_customer(user)
        return redirect("/user_page/" + str(user.index))
    if user:
        return render_template('edit_user.html',
                               title='Edit User',
                               form=form,
                               data=user.dict(),
                               tags=tagevents,
                               error=form.errors)
    else:
        return "she wrote upon it; no such number, no such zone"
コード例 #21
0
def user_page(user_index=None):
    """
    Renders a template with user information on a specified user.

    :param user_index:
    :type user_index: integer
    :return: Renders a template
    """
    try:
        if check_session():
            debts, tagevents = [], []
            cl = user_client.UsersSqlClient()
            user = cl.get_users(user_index)[0]

            if user is None:
                return "No user Found"
            else:
                dbl = debt_client.DebtSqlClient()
                ret_depts = dbl.get_debt(user.id)
                if ret_depts is not []:
                    for debt in ret_depts:
                        js = debt.dict()
                        debts.append(js)
                tc = tag_client.TageventsSqlClient()
                tagevents = tc.get_detailed_tagevents(user_index, 20)
                return render_template('user_page.html',
                                       title='User Page',
                                       data=user.dict(),
                                       tags=tagevents,
                                       debts=debts)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing a user page, please try again.')
        return redirect('/')
コード例 #22
0
ファイル: crosstag_server.py プロジェクト: lundstrj/crosstag
def debt_delete_confirm(id):
    debts = Debt.query.filter_by(id=id).first()
    users = User.query.filter_by(index=debts.uid).first()

    return render_template('debt_delete_confirm.html',
                           title='Delete',
                           hits=debts,
                           hits2=users)
コード例 #23
0
def debt_delete_confirm(id):
    debts = Debt.query.filter_by(id=id).first()
    users = User.query.filter_by(index=debts.uid).first()

    return render_template('debt_delete_confirm.html',
                           title='Delete',
                           hits=debts,
                           hits2=users)
コード例 #24
0
def settings():
    """
    GET - Renders a settings form with tenant information
    POST - Validates the settings form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is redirected to the front page.
    If they fail the settings form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            clt = update_tenant_client.UpdateTenantInformationSqlClient()
            current_tenant = clt.get_tenants(session['username'])[0]

            if current_tenant is None:
                return "No user have this ID"

            form = EditTenant(obj=current_tenant)
            if form.validate_on_submit():
                # Get Tenants password for confirmation
                cl = registration_client.RegisterLoginSqlClient()
                stored_hash = cl.do_login(session['username'])

                if stored_hash is not None:
                    hashed_pass = bcrypt.hashpw(form.password.data,
                                                stored_hash)
                    if hashed_pass == stored_hash:
                        # Saves new pass from form
                        hashed_new_pass = form.new_password.data
                        # if the new pass is not empty, hash it
                        if hashed_new_pass is not '':
                            hashed_new_pass = bcrypt.hashpw(
                                hashed_new_pass, bcrypt.gensalt())

                        tenant = {
                            'id': current_tenant.id,
                            'password': hashed_pass,
                            'new_password': hashed_new_pass,
                            'active_fortnox': form.active_fortnox.data,
                            'image': form.image.data,
                            'background_color': form.background_color.data
                        }
                        clt.update_tenant_information(tenant)
                        flash('Gym information changed')
                        return redirect('/')
                    else:
                        flash('Wrong password, could not save changes')

            return render_template('settings.html',
                                   title='Settings Tab',
                                   form=form,
                                   data=current_tenant.dict(),
                                   error=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error Updating information, please try again.')
        return redirect('/')
コード例 #25
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def index():
    """
    Render index template if the user is logged in, if not the user is redirected to the login page

    :return: render template or redirect
    """
    if check_session():
        return render_template('index.html')
    else:
        return redirect('/login')
コード例 #26
0
def all_tagevents():
    ret = []
    events = Tagevent.query.all()
    for hit in events:
        js = hit.dict()
        ret.append(js)
    ret.reverse()
    return render_template('all_tagevents.html',
                           title='All Tagevents',
                           hits=ret)
コード例 #27
0
def index():
    """
    Render index template if the user is logged in, if not the user is redirected to the login page

    :return: render template or redirect
    """
    if check_session():
        return render_template('index.html')
    else:
        return redirect('/login')
コード例 #28
0
ファイル: crosstag_server.py プロジェクト: lundstrj/crosstag
def all_tagevents():
    ret = []
    events = Tagevent.query.all()
    for hit in events:
        js = hit.dict()
        ret.append(js)
    ret.reverse()
    return render_template('all_tagevents.html',
                           title='All Tagevents',
                           hits=ret)
コード例 #29
0
def statistics_by_date(_month, _day, _year):
    """
    Renders statistic from the database on the specified date from the params.
    1. Tags by hour
    2. Tags by day
    3. Tags by month
    4. Number of genders in database
    5. Number of tags by gender
    6. Number of age groups in database

    :param _month:
    :param _day:
    :param _year:
    :type _month: string
    :type _day: string
    :type _year: string
    :return: Render template for statistic
    """
    try:
        if check_session():
            chosen_date_array = {'year': _year, 'month': _month, 'day': _day}
            gs = GenerateStats()

            ucl = user_client.UsersSqlClient()
            tcl = tag_client.TageventsSqlClient()
            users = ucl.get_users()
            tagevents = tcl.get_statistic_tagevents()

            default_date = datetime.now()
            selected_date = default_date.replace(day=int(_day),
                                                 month=int(_month),
                                                 year=int(_year))
            week_day_name = selected_date.strftime('%A')
            month_name = selected_date.strftime('%B')
            custom_date_day = {
                'weekday':
                week_day_name + ' ' + str(selected_date.day) + '/' +
                str(selected_date.month) + '/' + str(selected_date.year)
            }

            custom_date_month = {
                'month': month_name + ' ' + str(selected_date.year)
            }
            # Send the data to a method who returns an multi dimensional array with statistics.
            ret = gs.get_data(users, tagevents, chosen_date_array)
            return render_template('statistics.html',
                                   plot_paths='',
                                   data=ret,
                                   data2=custom_date_day,
                                   data3=custom_date_month)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error showing statistic, please try again.')
        return redirect('/')
コード例 #30
0
def general_information():
    """
    GET - Renders a settings form with general information.
    POST - Validates the settings form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is redirected to the front page.
    If they fail the settings form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            clt = update_tenant_client.UpdateTenantInformationSqlClient()
            current_tenant = clt.get_tenants(session['username'])[0]

            if current_tenant is None:
                return "No user have this ID"

            form = EditGeneralInformation(obj=current_tenant)

            if form.validate_on_submit():
                # Get Tenants password for confirmation
                cl = registration_client.RegisterLoginSqlClient()
                stored_hash = cl.do_login(session['username'])

                if stored_hash is not None:
                    hashed_pass = bcrypt.hashpw(form.password.data,
                                                stored_hash)
                    if hashed_pass == stored_hash:
                        tenant = {
                            'id': current_tenant.id,
                            'password': hashed_pass,
                            'gym_name': form.gym_name.data,
                            'address': form.address.data,
                            'phone': form.phone.data,
                            'zip_code': form.zip_code.data,
                            'city': form.city.data,
                            'email': form.email.data
                        }
                        clt.update_tenant_general_information(tenant)
                        flash('Gym information changed')
                        return redirect('/')
                    else:
                        flash('Wrong password, could not save changes')

            return render_template('general_information.html',
                                   title='General Information Tab',
                                   form=form,
                                   data=current_tenant.dict(),
                                   error=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error Updating general information, please try again.')
        return redirect('/')
コード例 #31
0
def edit_user(user_index=None):
    """
    GET - Renders a edit user form.
    POST - Validates the user form and check if the values are right. If they pass the information is stored in
    the database and the user is updated. The tenant is redirected to the user page.
    If they fail the edit user form is rendered with error messages.

    :param user_index:
    :type user_index: integer
    :return: Renders a template
    """
    try:
        if check_session():
            cl = user_client.UsersSqlClient()
            user = cl.get_users(user_index)[0]

            if user is None:
                return "No user have this ID"

            form = EditUser(obj=user)
            if form.validate_on_submit():
                user.firstname = form.firstname.data
                user.lastname = form.lastname.data
                user.email = form.email.data
                user.phone = form.phone.data
                user.address = form.address.data
                user.address2 = form.address2.data
                user.city = form.city.data
                user.zip_code = form.zip_code.data
                user.tag_id = form.tag_id.data
                user.gender = form.gender.data
                user.expiry_date = form.expiry_date.data
                user.status = form.status.data

                cl.update_user(user.dict())
                # Not in use at this point. Will be a future feature..
                # If we successfully edited the user, redirect back to userpage.
                # fortnox_data = Fortnox()
                # fortnox_data.update_customer(user)
                return redirect("/user_page/" + str(user.id))

            if user:
                return render_template('edit_user.html',
                                       title='Edit User',
                                       form=form,
                                       data=user.dict(),
                                       error=form.errors)
            else:
                return "she wrote upon it; no such number, no such zone"
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Editing a user, please try again.')
        return redirect('/')
コード例 #32
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def edit_user(user_index=None):
    """
    GET - Renders a edit user form.
    POST - Validates the user form and check if the values are right. If they pass the information is stored in
    the database and the user is updated. The tenant is redirected to the user page.
    If they fail the edit user form is rendered with error messages.

    :param user_index:
    :type user_index: integer
    :return: Renders a template
    """
    try:
        if check_session():
            cl = user_client.UsersSqlClient()
            user = cl.get_users(user_index)[0]

            if user is None:
                return "No user have this ID"

            form = EditUser(obj=user)
            if form.validate_on_submit():
                user.firstname = form.firstname.data
                user.lastname = form.lastname.data
                user.email = form.email.data
                user.phone = form.phone.data
                user.address = form.address.data
                user.address2 = form.address2.data
                user.city = form.city.data
                user.zip_code = form.zip_code.data
                user.tag_id = form.tag_id.data
                user.gender = form.gender.data
                user.expiry_date = form.expiry_date.data
                user.status = form.status.data

                cl.update_user(user.dict())
                # Not in use at this point. Will be a future feature..
                # If we successfully edited the user, redirect back to userpage.
                # fortnox_data = Fortnox()
                # fortnox_data.update_customer(user)
                return redirect("/user_page/"+str(user.id))

            if user:
                return render_template('edit_user.html',
                                       title='Edit User',
                                       form=form,
                                       data=user.dict(),
                                       error=form.errors)
            else:
                return "she wrote upon it; no such number, no such zone"
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Editing a user, please try again.')
        return redirect('/')
コード例 #33
0
def user_page(user_index=None):
    user = User.query.filter_by(index=user_index).first()
    debts = Debt.query.filter_by(uid=user.index)
    if user is None:
        return "No user Found"
    else:
        tagevents = get_tagevents_user_dict(user_index)
        return render_template('user_page.html',
                               title='User Page',
                               data=user.dict(),
                               tags=tagevents,
                               debts=debts)
コード例 #34
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def settings():
    """
    GET - Renders a settings form with tenant information
    POST - Validates the settings form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is redirected to the front page.
    If they fail the settings form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            clt = update_tenant_client.UpdateTenantInformationSqlClient()
            current_tenant = clt.get_tenants(session['username'])[0]

            if current_tenant is None:
                return "No user have this ID"

            form = EditTenant(obj=current_tenant)
            if form.validate_on_submit():
                # Get Tenants password for confirmation
                cl = registration_client.RegisterLoginSqlClient()
                stored_hash = cl.do_login(session['username'])

                if stored_hash is not None:
                    hashed_pass = bcrypt.hashpw(form.password.data, stored_hash)
                    if hashed_pass == stored_hash:
                        # Saves new pass from form
                        hashed_new_pass = form.new_password.data
                        # if the new pass is not empty, hash it
                        if hashed_new_pass is not '':
                            hashed_new_pass = bcrypt.hashpw(hashed_new_pass, bcrypt.gensalt())

                        tenant = {'id': current_tenant.id,
                                  'password': hashed_pass,
                                  'new_password': hashed_new_pass,
                                  'active_fortnox': form.active_fortnox.data,
                                  'image': form.image.data,
                                  'background_color': form.background_color.data}
                        clt.update_tenant_information(tenant)
                        flash('Gym information changed')
                        return redirect('/')
                    else:
                        flash('Wrong password, could not save changes')

            return render_template('settings.html', title='Settings Tab',
                                   form=form,
                                   data=current_tenant.dict(),
                                   error=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error Updating information, please try again.')
        return redirect('/')
コード例 #35
0
def debt_check():
    debts = Debt.query.all()
    users = User.query.all()
    debt_and_user_array = []
    multi_array = []
    for debt in debts:
        for user in users:
            if debt.uid == user.index:
                debt_and_user_array = {'debt': debt, 'user': user}
                multi_array.append(debt_and_user_array)

    return render_template('debt_check.html', title='Check', hits=multi_array)
コード例 #36
0
ファイル: crosstag_server.py プロジェクト: lundstrj/crosstag
def user_page(user_index=None):
    user = User.query.filter_by(index=user_index).first()
    debts = Debt.query.filter_by(uid=user.index)
    if user is None:
        return "No user Found"
    else:
        tagevents = get_tagevents_user_dict(user_index)
        return render_template('user_page.html',
                               title='User Page',
                               data=user.dict(),
                               tags=tagevents,
                               debts=debts)
コード例 #37
0
ファイル: crosstag_server.py プロジェクト: lundstrj/crosstag
def debt_check():
    debts = Debt.query.all()
    users = User.query.all()
    debt_and_user_array = []
    multi_array = []
    for debt in debts:
        for user in users:
            if debt.uid == user.index:
                debt_and_user_array = {'debt': debt, 'user': user}
                multi_array.append(debt_and_user_array)

    return render_template('debt_check.html',
                           title='Check',
                           hits=multi_array)
コード例 #38
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def general_information():
    """
    GET - Renders a settings form with general information.
    POST - Validates the settings form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is redirected to the front page.
    If they fail the settings form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            clt = update_tenant_client.UpdateTenantInformationSqlClient()
            current_tenant = clt.get_tenants(session['username'])[0]

            if current_tenant is None:
                return "No user have this ID"

            form = EditGeneralInformation(obj=current_tenant)

            if form.validate_on_submit():
                # Get Tenants password for confirmation
                cl = registration_client.RegisterLoginSqlClient()
                stored_hash = cl.do_login(session['username'])

                if stored_hash is not None:
                    hashed_pass = bcrypt.hashpw(form.password.data, stored_hash)
                    if hashed_pass == stored_hash:
                        tenant = {'id': current_tenant.id,
                                  'password': hashed_pass,
                                  'gym_name': form.gym_name.data,
                                  'address': form.address.data,
                                  'phone': form.phone.data,
                                  'zip_code': form.zip_code.data,
                                  'city': form.city.data,
                                  'email': form.email.data}
                        clt.update_tenant_general_information(tenant)
                        flash('Gym information changed')
                        return redirect('/')
                    else:
                        flash('Wrong password, could not save changes')

            return render_template('general_information.html', title='General Information Tab',
                                   form=form,
                                   data=current_tenant.dict(),
                                   error=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error Updating general information, please try again.')
        return redirect('/')
コード例 #39
0
def registration():
    """
    GET - Renders a registration form.
    POST - Validates the login form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is registrated and is redirected to the front page.
    If they fail the registration form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if not check_session():
            form = Register()
            if form.validate_on_submit():
                # TODO: Remove temporally disabled registration, 2 lines below
                flash('Registration is temporarily disabled.')
                return redirect('/')
                '''
                # 1 Get password from form
                password = form.password.data.encode('utf-8')
                # 2 Hash the password
                hashed_password = bcrypt.hashpw(password, bcrypt.gensalt())
                # 3 Save the Tenant in the db
                registered_tenant = {'username': form.username.data.title(),
                                     'password': hashed_password,
                                     'active_fortnox': form.active_fortnox.data,
                                     'gym_name': form.gym_name.data,
                                     'address': form.address.data,
                                     'phone': form.phone.data,
                                     'zip_code': form.zip_code.data,
                                     'city': form.city.data,
                                     'email': form.email.data,
                                     'pass': registration_client.cfg.TENANT_PASSWORD + form.username.data.title()}

                cl = registration_client.RegisterLoginSqlClient()
                if cl.do_registration(registered_tenant):
                    flash('Registration done, you can now log in')
                    return redirect('/')
                else:
                    flash('Username already exists')
                '''

            return render_template('register.html',
                                   title='Register new Tenant',
                                   form=form,
                                   errors=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error when trying to register, please try again.')
        return redirect('/')
コード例 #40
0
ファイル: crosstag_server.py プロジェクト: lundstrj/crosstag
def search_user():
    form = SearchUser()
    print(str(form.validate_on_submit()))
    print("errors", form.errors)
    hits = []
    if form.validate_on_submit():
        if form.index.data:
            user_index = form.index.data
            users = User.query.filter_by(index=user_index)
            hits.extend(users)
        if form.fortnox_id.data:
            fortnox_id = form.fortnox_id.data
            users = User.query.filter_by(fortnox_id=fortnox_id)
            hits.extend(users)
        if form.name.data:
            name = form.name.data
            users = User.query.filter(User.name.ilike('%' + name + '%'))
            hits.extend(users)
        if form.email.data:
            email = form.email.data
            users = User.query.filter_by(email=email)
            hits.extend(users)
        if form.phone.data:
            phone = form.phone.data
            users = User.query.filter_by(phone=phone)
            hits.extend(users)
        ret = []
        for hit in hits:
            js = hit.dict()
            ret.append(js)
        return render_template('search_user.html',
                               title='Search User',
                               form=form,
                               hits=ret)
    return render_template('search_user.html',
                           title='Search User',
                           form=form)
コード例 #41
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def statistics_by_date(_month, _day, _year):
    """
    Renders statistic from the database on the specified date from the params.
    1. Tags by hour
    2. Tags by day
    3. Tags by month
    4. Number of genders in database
    5. Number of tags by gender
    6. Number of age groups in database

    :param _month:
    :param _day:
    :param _year:
    :type _month: string
    :type _day: string
    :type _year: string
    :return: Render template for statistic
    """
    try:
        if check_session():
            chosen_date_array = {'year': _year, 'month': _month, 'day': _day}
            gs = GenerateStats()

            ucl = user_client.UsersSqlClient()
            tcl = tag_client.TageventsSqlClient()
            users = ucl.get_users()
            tagevents = tcl.get_statistic_tagevents()

            default_date = datetime.now()
            selected_date = default_date.replace(day=int(_day), month=int(_month), year=int(_year))
            week_day_name = selected_date.strftime('%A')
            month_name = selected_date.strftime('%B')
            custom_date_day = {'weekday': week_day_name + ' ' + str(selected_date.day)
                                          + '/' + str(selected_date.month)
                                          + '/' + str(selected_date.year)}

            custom_date_month = {'month': month_name + ' ' + str(selected_date.year)}
            # Send the data to a method who returns an multi dimensional array with statistics.
            ret = gs.get_data(users, tagevents, chosen_date_array)
            return render_template('statistics.html',
                                   plot_paths='',
                                   data=ret,
                                   data2=custom_date_day,
                                   data3=custom_date_month)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error showing statistic, please try again.')
        return redirect('/')
コード例 #42
0
def statistics():
    """
    Renders statistic from the database on todays date.
    1. Tags by hour
    2. Tags by day
    3. Tags by month
    4. Number of genders in database
    5. Number of tags by gender
    6. Number of age groups in database

    :return: Render template for statistic
    """
    try:
        if check_session():
            default_date = datetime.now()
            default_date_array = {
                'year': str(default_date.year),
                'month': str(default_date.strftime('%m')),
                'day': str(default_date.strftime('%d'))
            }
            gs = GenerateStats()

            ucl = user_client.UsersSqlClient()
            tcl = tag_client.TageventsSqlClient()
            users = ucl.get_users()
            tagevents = tcl.get_statistic_tagevents()
            week_day_name = default_date.strftime('%A')
            month_name = default_date.strftime('%B')
            custom_date_day = {
                'weekday':
                week_day_name + ' ' + str(default_date.day) + '/' +
                str(default_date.month) + '/' + str(default_date.year)
            }
            custom_date_month = {
                'month': month_name + ' ' + str(default_date.year)
            }
            # Send the data to a method who returns an multi dimensional array with statistics.
            ret = gs.get_data(users, tagevents, default_date_array)
            return render_template('statistics.html',
                                   plot_paths='',
                                   data=ret,
                                   data2=custom_date_day,
                                   data3=custom_date_month)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error showing statistic, please try again.')
        return redirect('/')
コード例 #43
0
ファイル: crosstag_server.py プロジェクト: lundstrj/crosstag
def debt_create(id_test):
    user = User.query.filter_by(index=id_test).first()
    form = NewDebt()
    test = datetime.now()
    print("errors", form.errors)
    if form.validate_on_submit():
        tmp_debt = Debt(form.amount.data, user.index, form.product.data, test)
        db.session.add(tmp_debt)
        db.session.commit()
        flash('Created new debt: %s for member %s' % (form.amount.data,
                                                      user.name))
        return redirect("/user_page/"+id_test)
    return render_template('debt_create.html',
                           title='Debt Create',
                           form=form,
                           error=form.errors)
コード例 #44
0
def debt_create(id_test):
    user = User.query.filter_by(index=id_test).first()
    form = NewDebt()
    test = datetime.now()
    print("errors", form.errors)
    if form.validate_on_submit():
        tmp_debt = Debt(form.amount.data, user.index, form.product.data, test)
        db.session.add(tmp_debt)
        db.session.commit()
        flash('Created new debt: %s for member %s' %
              (form.amount.data, user.name))
        return redirect("/user_page/" + id_test)
    return render_template('debt_create.html',
                           title='Debt Create',
                           form=form,
                           error=form.errors)
コード例 #45
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def registration():
    """
    GET - Renders a registration form.
    POST - Validates the login form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is registrated and is redirected to the front page.
    If they fail the registration form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if not check_session():
            form = Register()
            if form.validate_on_submit():
                # TODO: Remove temporally disabled registration, 2 lines below
                flash('Registration is temporarily disabled.')
                return redirect('/')
                '''
                # 1 Get password from form
                password = form.password.data.encode('utf-8')
                # 2 Hash the password
                hashed_password = bcrypt.hashpw(password, bcrypt.gensalt())
                # 3 Save the Tenant in the db
                registered_tenant = {'username': form.username.data.title(),
                                     'password': hashed_password,
                                     'active_fortnox': form.active_fortnox.data,
                                     'gym_name': form.gym_name.data,
                                     'address': form.address.data,
                                     'phone': form.phone.data,
                                     'zip_code': form.zip_code.data,
                                     'city': form.city.data,
                                     'email': form.email.data,
                                     'pass': registration_client.cfg.TENANT_PASSWORD + form.username.data.title()}

                cl = registration_client.RegisterLoginSqlClient()
                if cl.do_registration(registered_tenant):
                    flash('Registration done, you can now log in')
                    return redirect('/')
                else:
                    flash('Username already exists')
                '''

            return render_template('register.html', title='Register new Tenant', form=form, errors=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error when trying to register, please try again.')
        return redirect('/')
コード例 #46
0
def last_tagins():
    ret = []
    events = DetailedTagevent.query.all()[-10:]
    for hit in events:
        js = hit.dict()
        tag = js['tag_id']
        try:
            user = get_user_data_tag_dict(tag)
            js['user_index'] = user["index"]
            js['user_name'] = user['name']
        except:
            js['user_index'] = None
            js['user_name'] = "No user connected to this tag"
        ret.append(js)
    ret.reverse()
    return render_template('last_tagevents.html',
                           title='Last Tagins',
                           hits=ret)
コード例 #47
0
def all_users(filter=None):
    ret = []
    counter = 0
    # Lists all users
    if filter == "all":
        users = User.query.order_by("expiry_date desc").all()
    # List users depending on the membership
    elif filter:
        users = User.query.filter(User.status == filter.title())
    for hit in users:
        counter += 1
        js = hit.dict()
        ret.append(js)
    return render_template('all_users.html',
                           title='All Users',
                           hits=ret,
                           filter=filter,
                           count=counter)
コード例 #48
0
ファイル: crosstag_server.py プロジェクト: lundstrj/crosstag
def last_tagins():
    ret = []
    events = DetailedTagevent.query.all()[-10:]
    for hit in events:
        js = hit.dict()
        tag = js['tag_id']
        try:
            user = get_user_data_tag_dict(tag)
            js['user_index'] = user["index"]
            js['user_name'] = user['name']
        except:
            js['user_index'] = None
            js['user_name'] = "No user connected to this tag"
        ret.append(js)
    ret.reverse()
    return render_template('last_tagevents.html',
                           title='Last Tagins',
                           hits=ret)
コード例 #49
0
def last_tagins():
    """
    Lists the last tagins. At the moment ( 2016-05-19 ) it is the last 10 tags, but this will be changeable

    :return: Redirect or renders template
    """
    try:
        if check_session():
            ret = []
            cl = tag_client.TageventsSqlClient()
            detailed_tagevents = cl.get_detailed_tagevents(0, 10)
            return render_template('last_tagevents.html',
                                   title='Last Tagins',
                                   hits=detailed_tagevents)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error showing last tagins, please try again.')
        return redirect('/')
コード例 #50
0
def debt_check():
    """
    Renders a template with a list of all users with debts

    :return: Renders template with a list of users
    """
    try:
        if check_session():
            dcl = debt_client.DebtSqlClient()
            debt_array = dcl.get_debt()

            return render_template('debt_check.html',
                                   title='Check',
                                   hits=debt_array)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing debt, please try again.')
        return redirect('/')
コード例 #51
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def debt_check():
    """
    Renders a template with a list of all users with debts

    :return: Renders template with a list of users
    """
    try:
        if check_session():
            dcl = debt_client.DebtSqlClient()
            debt_array = dcl.get_debt()

            return render_template('debt_check.html',
                                   title='Check',
                                   hits=debt_array)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing debt, please try again.')
        return redirect('/')
コード例 #52
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def last_tagins():
    """
    Lists the last tagins. At the moment ( 2016-05-19 ) it is the last 10 tags, but this will be changeable

    :return: Redirect or renders template
    """
    try:
        if check_session():
            ret = []
            cl = tag_client.TageventsSqlClient()
            detailed_tagevents = cl.get_detailed_tagevents(0, 10)
            return render_template('last_tagevents.html',
                                   title='Last Tagins',
                                   hits=detailed_tagevents)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error showing last tagins, please try again.')
        return redirect('/')
コード例 #53
0
def all_users(filter=None):
    ret = []
    counter = 0
    users = []
    # Lists all users
    if filter == "all":
        users = User.query.order_by("expiry_date desc").all()
    # List users depending on the membership
    elif filter:
        users = User.query.filter(User.status == filter.title())
    for hit in users:
        counter += 1
        js = hit.dict()
        ret.append(js)
    return render_template('all_users.html',
                           title='All Users',
                           hits=ret,
                           filter=filter,
                           count=counter)
コード例 #54
0
ファイル: crosstag_server.py プロジェクト: lundstrj/crosstag
def statistics_by_date(_month, _day, _year):
    chosen_date_array = {'year': _year, 'month': _month, 'day': _day}
    gs = GenerateStats()
    # Chosenyear, chosenmonth, chosenday
    # Fetch the data from the database.
    users = User.query.all()
    event = Tagevent
    default_date = datetime.now()
    selected_date = default_date.replace(day=int(_day), month=int(_month), year=int(_year))
    week_day_name = selected_date.strftime('%A')
    month_name = selected_date.strftime('%B')
    custom_date_day = {'weekday': week_day_name + ' ' + str(selected_date.day) + '/' + str(selected_date.month) + '/' + str(selected_date.year)}
    custom_date_month = {'month': month_name + ' ' + str(selected_date.year)}
    # Send the data to a method who returns an multi dimensional array with statistics.
    ret = gs.get_data(users, event, chosen_date_array)
    return render_template('statistics.html',
                           plot_paths='',
                           data=ret,
                           data2=custom_date_day,
                           data3=custom_date_month)
コード例 #55
0
def inactive_check():
    """
    Renders a template with a list of all users that have not tagged in for the last 2 weeks

    :return: Renders template with a user list
    """
    try:
        if check_session():
            ret = []
            mc = user_client.UsersSqlClient()
            users = mc.get_inactive_users()

            return render_template('inactive_check.html',
                                   title='Inactive Members',
                                   hits=users)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing Inactive Users, please try again.')
        return redirect('/')
コード例 #56
0
ファイル: crosstag_server.py プロジェクト: lundstrj/crosstag
def statistics():
    default_date = datetime.now()
    default_date_array = {'year': str(default_date.year), 'month': str(default_date.strftime('%m')), 'day':str(default_date.strftime('%d'))}
    gs = GenerateStats()
    # Chosenyear, chosenmonth, chosenday
    # Fetch the data from the database.
    users = User.query.all()
    event = Tagevent
    week_day_name = default_date.strftime('%A')
    month_name = default_date.strftime('%B')
    custom_date_day = {'weekday': week_day_name + ' ' + str(default_date.day) + '/' + str(default_date.month) + '/' +
                       str(default_date.year)}
    custom_date_month = {'month': month_name + ' ' + str(default_date.year)}
    # Send the data to a method who returns an multi dimensional array with statistics.
    ret = gs.get_data(users, event, default_date_array)
    return render_template('statistics.html',
                           plot_paths='',
                           data=ret,
                           data2=custom_date_day,
                           data3=custom_date_month)
コード例 #57
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def statistics():
    """
    Renders statistic from the database on todays date.
    1. Tags by hour
    2. Tags by day
    3. Tags by month
    4. Number of genders in database
    5. Number of tags by gender
    6. Number of age groups in database

    :return: Render template for statistic
    """
    try:
        if check_session():
            default_date = datetime.now()
            default_date_array = {'year': str(default_date.year),
                                  'month': str(default_date.strftime('%m')),
                                  'day':str(default_date.strftime('%d'))}
            gs = GenerateStats()

            ucl = user_client.UsersSqlClient()
            tcl = tag_client.TageventsSqlClient()
            users = ucl.get_users()
            tagevents = tcl.get_statistic_tagevents()
            week_day_name = default_date.strftime('%A')
            month_name = default_date.strftime('%B')
            custom_date_day = {'weekday': week_day_name + ' ' + str(default_date.day) + '/' + str(default_date.month) + '/' +
                               str(default_date.year)}
            custom_date_month = {'month': month_name + ' ' + str(default_date.year)}
            # Send the data to a method who returns an multi dimensional array with statistics.
            ret = gs.get_data(users, tagevents, default_date_array)
            return render_template('statistics.html',
                                   plot_paths='',
                                   data=ret,
                                   data2=custom_date_day,
                                   data3=custom_date_month)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error showing statistic, please try again.')
        return redirect('/')
コード例 #58
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def fortnox_information():
    """
    GET - Renders a settings form for fortnox information
    POST - Validates the settings form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is redirected to the front page.
    If they fail the settings form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            form = EditFortnoxInformation()
            return render_template('fortnox_information.html', title='Settings Tab',
                                   form=form,
                                   data='',
                                   error=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error Updating fortnox information, please try again.')
        return redirect('/')
コード例 #59
0
ファイル: crosstag_server.py プロジェクト: ej222pj/crosstag
def inactive_check():
    """
    Renders a template with a list of all users that have not tagged in for the last 2 weeks

    :return: Renders template with a user list
    """
    try:
        if check_session():
            ret = []
            mc = user_client.UsersSqlClient()
            users = mc.get_inactive_users()


            return render_template('inactive_check.html',
                                   title='Inactive Members',
                                   hits=users)
        else:
            return redirect_not_logged_in()
    except:
        flash('Error Showing Inactive Users, please try again.')
        return redirect('/')
コード例 #60
0
def fortnox_information():
    """
    GET - Renders a settings form for fortnox information
    POST - Validates the settings form and check if the values are right. If they pass the informations is stored in
    the database and the tenant is redirected to the front page.
    If they fail the settings form is rendered with error messages.

    :return: Redirect or renders template
    """
    try:
        if check_session():
            form = EditFortnoxInformation()
            return render_template('fortnox_information.html',
                                   title='Settings Tab',
                                   form=form,
                                   data='',
                                   error=form.errors)
        else:
            return redirect('/')
    except:
        flash('Error Updating fortnox information, please try again.')
        return redirect('/')