Exemplo n.º 1
0
def gombfeltoltes():
    if 'logged_in' not in session or not session['logged_in']:
        return render_template('login_required.html')

    form = GombFeltoltesForm()

    print('Gombfeltoltes form: {}'.format(request.form))

    if request.method == 'POST':
        if form.validate():
            content = request.form['content']
            print('Received content: ' + content)
            log_event('gombfeltoltes called by {}'.format(session['username']))
            lemu_process_gomb_result = lemu_gombfeltoltes.process_and_upload_gomb(
                content)
            if isinstance(lemu_process_gomb_result, list):
                for msg in lemu_process_gomb_result:
                    flash(msg)
            else:
                flash('Result: ' + lemu_process_gomb_result)
        else:
            log_error('CSRF ERROR')

    return render_template('gombfeltoltes.html',
                           title='Gömb feltöltés',
                           form=form)
Exemplo n.º 2
0
def pontlista_valtozas():
    if 'logged_in' not in session or not session['logged_in']:
        log_event('pontlista_valtozas called with invalid login!')
        return render_template('login_required.html')

    if request.method == 'GET':
        orszag_id = request.args.get('orszag_id', type=int)
        limit = request.args.get('limit', default=5, type=int)

        log_event('pontlista_valtozas called by {} to {}'.format(
            session['username'], orszag_id))
        print('Received content: {}'.format(orszag_id))

        column_headers, lists = lemu_pontlista.get_pontlista_valtozas(
            orszag_id, limit=limit)
        # TODO: Error message
        #flash(result)
    else:
        log_error('Invalid call for pontlista_valtozas (not GET)')

    # TODO: Create pontlista_valtozas.html? But why if same solution will be done with pontlista.html
    return render_template('pontlista.html',
                           title='Pontlista Változás',
                           column_headers=column_headers,
                           lists=lists)
Exemplo n.º 3
0
def pontlista_feltoltes():
    if 'logged_in' not in session or not session['logged_in']:
        log_event('pontlistafeltoltes called with invalid login!')
        return render_template('login_required.html')

    form = PontlistaFeltoltesForm()
    pontlista_data_list = None

    if request.method == 'POST':
        if form.validate():
            content = request.form['content']
            print('Received content: ' + content)
            result, pontlista_data_list = lemu_pontlista_feltoltes.process_and_upload_pontlista(
                content)
            log_event('pontlista_feltoltes called')
            if isinstance(result, list):
                for msg in result:
                    flash(msg)
            else:
                flash('Result: ' + result)
        else:
            log_error('CSRF ERROR')

    return render_template('pontlistafeltoltes.html',
                           title='Pontlista feltöltés',
                           form=form,
                           pontlista_data_list=pontlista_data_list)
Exemplo n.º 4
0
def felmeresfeltoltes():
    if 'logged_in' not in session or not session['logged_in']:
        log_event('felmeresfeltoltes called with invalid login!')
        return render_template('login_required.html')

    form = FelmeresFeltoltesForm()

    if request.method == 'POST':
        if form.validate():
            content = request.form['content']
            print('Received content: ' + content)
            log_event('felmeresfeltoltes called by {}'.format(
                session['username']))
            lemu_process_result = lemu_felmeres.process_and_upload_felmeres(
                content)
            flash('Result: ' + lemu_process_result)
        else:
            log_error('CSRF ERROR')
    else:
        # First call, put default data
        form.content.data = lemu_felmeres.felmeres_default_inited()

    return render_template('felmeresfeltoltes.html',
                           title='Felmérés feltöltés',
                           form=form)
Exemplo n.º 5
0
 def test_log_log_event(self):
     """Test that log_event convenience function logs if enabled."""
     
     with LogCapture() as l:
         event = log_event("label", "message", self.user, extra=self.extra)
         m = ('eventlog', 'INFO', "0000000000000001 label (user: johndoe) - message {'key2': 'value2', 'key': 'value'}")
         l.check(m)
         event = log_event("label", "message", self.user, extra=self.extra, django_log=False)
         l.check(m)
Exemplo n.º 6
0
def pontlista():
    if 'logged_in' not in session or not session['logged_in']:
        log_event('pontlista called with invalid login!')
        return render_template('login_required.html')

    log_event('pontlista called: {}'.format(session['username']))
    column_headers, lists = lemu_pontlista.get_pontlista_interface()
    return render_template('pontlista.html',
                           title='Pontlista',
                           column_headers=column_headers,
                           lists=lists)
Exemplo n.º 7
0
def gomblistazo():
    if 'logged_in' not in session or not session['logged_in']:
        log_event('gomblistazo called with invalid login!')
        return render_template('login_required.html')

    log_event('gomblistazo called: {}'.format(session['username']))
    column_headers, lists = lemu_gomblistazo.get_gomb_list()
    return render_template('gomblistazo.html',
                           title='Gömb listázó',
                           column_headers=column_headers,
                           lists=lists)
Exemplo n.º 8
0
 def test_convenience_log_event(self):
     """Test the log_event convenience function."""
     
     event = log_event("label", "message", self.user, extra=self.extra)
     self.assertTrue(event.id)
     self.assertEqual(event.label, "label")
     self.assertEqual(event.message, "message")
     self.assertEqual(event.user, self.user)
     self.assertEqual(event.extra, self.extra)
     self.assertEqual(event.level, logging.INFO)
Exemplo n.º 9
0
def gombmegjelenito():
    if 'logged_in' not in session or not session['logged_in']:
        log_event('gombmegjelenito called with invalid login!')
        return render_template('login_required.html')

    if request.method == 'GET':
        orszag_id = request.args.get('orszag_id', type=int)
        limit = request.args.get('limit', default=5, type=int)

        log_event('gombmegjelenito called by {} to {}'.format(
            session['username'], orszag_id))
        print('Received content: {}'.format(orszag_id))
        lemu_gombkereso_result, orszaginfolist = lemu_gombkereso.gomb_kereses_interface(
            orszag_id, limit=limit)
        flash(lemu_gombkereso_result)
    else:
        log_error('Invalid call for gombmegjelenito (not GET)')

    return render_template('gombmegjelenito.html',
                           title='Gömb',
                           orszaginfolist=orszaginfolist)
Exemplo n.º 10
0
def kronika():
    if 'logged_in' not in session or not session['logged_in']:
        log_event('kronika called with invalid login!')
        return render_template('login_required.html')

    form = KronikaFeltoltesForm()

    log_event('kronika called: {}'.format(session['username']))
    kronika_column_headers, kronika_data_list = lemu_kronika.get_kronika()

    if request.method == 'POST':
        if form.validate():
            content = request.form['content']
            print('Received content: ' + content)
            result = lemu_kronika.process_and_upload_kronika(content)
            log_event('kronika uploaded')
            if isinstance(result, list):
                for msg in result:
                    flash(msg)
            else:
                flash('Result: ' + result)
        else:
            log_error('CSRF ERROR')

    return render_template('kronika.html',
                           title='Krónika',
                           form=form,
                           column_headers=kronika_column_headers,
                           data_list=kronika_data_list)
Exemplo n.º 11
0
def piac():
    if 'logged_in' not in session or not session['logged_in']:
        log_event('piac called with invalid login!')
        return render_template('login_required.html')

    form = PiacFeltoltesForm()

    log_event('piac called: {}'.format(session['username']))
    piac_column_headers, piac_data_list = lemu_piac.get_piac()

    if request.method == 'POST':
        if form.validate():
            content = request.form['content']
            print('Received content: ' + content)
            result = lemu_piac.process_and_upload_piac(content)
            log_event('piac called uploaded')
            if isinstance(result, list):
                for msg in result:
                    flash(msg)
            else:
                flash('Result: ' + result)
        else:
            log_error('CSRF ERROR')

    return render_template('piac.html',
                           title='Piac',
                           form=form,
                           piac_column_headers=piac_column_headers,
                           piac_data_list=piac_data_list)
Exemplo n.º 12
0
def felmereskereso():
    if 'logged_in' not in session or not session['logged_in']:
        log_event('felmereskereso called with invalid login!')
        return render_template('login_required.html')

    form = FelmeresKeresoForm()

    if request.method == 'POST':
        if form.validate():
            orszag_kereses = request.form['orszag_kereses']
            log_event('felmereskereso called by {} to {}'.format(
                session['username'], orszag_kereses))
            print('Received content: ' + orszag_kereses)
            lemu_felmereskereso_result, felmeres = lemu_felmeres.felmeres_kereses_interface(
                orszag_kereses)
            flash(lemu_felmereskereso_result)
            if felmeres:
                form.felmeres = felmeres
        else:
            log_error('CSRF ERROR')

    return render_template('felmereskereso.html',
                           title='Felmérés kereső',
                           form=form)
Exemplo n.º 13
0
def gombkereso():
    if 'logged_in' not in session or not session['logged_in']:
        log_event('gombkereso called with invalid login!')
        return render_template('login_required.html')

    form = GombKeresoForm()
    orszaginfolist = []  # Should be initialized for empty search page

    if request.method == 'POST':
        if form.validate():
            orszag_kereses = request.form['orszag_kereses']
            log_event('gombkereso called by {} to {}'.format(
                session['username'], orszag_kereses))
            print('Received content: ' + orszag_kereses)
            lemu_gombkereso_result, orszaginfolist = lemu_gombkereso.gomb_kereses_interface(
                orszag_kereses)
            flash(lemu_gombkereso_result)
        else:
            log_error('CSRF ERROR')

    return render_template('gombkereso.html',
                           title='Gömb kereső',
                           form=form,
                           orszaginfolist=orszaginfolist)
Exemplo n.º 14
0
def login():
    form = LoginForm()

    if form.validate_on_submit():
        if form.validate():
            # Login try
            is_successful_login, msg, user_info = user_validation(
                form.username.data, form.password.data)
            if is_successful_login:
                flash('Login requested for user {}, remember_me={}'.format(
                    form.username.data, form.remember_me.data))
                print('Successful')
                session['username'] = form.username.data
                session['logged_in'] = True
                session['user_info'] = user_info
                log_event('Logined successfully: {}'.format(
                    session['username']))
                return redirect('/index')
            else:
                print('Login error message: {}'.format(msg))
                session['logged_in'] = False
                log_event('Login failed: {} with error message: {}'.format(
                    form.username.data, msg))
                # Return with error message
                flash('Login error message: {}'.format(msg))
        else:
            msg = 'Form is invalid! Perhaps you has not typed anything to the inputs OR CSRF ERROR!'
            flash(msg)
            log_event(msg)
    elif form.submit.data:
        msg = 'Form is invalid! Perhaps you has not typed anything to the inputs OR CSRF ERROR!'
        flash(msg)
        log_event(msg)
    else:
        # Not submitted, Do nothing!
        pass

    return render_template('login.html', title='Sign In', form=form)
Exemplo n.º 15
0
def adminlog():
    if 'logged_in' not in session or not session['logged_in']:
        log_event('adminlog called with invalid login!')
        return render_template('login_required.html')
    if session['user_info'][
            'is_disabled'] or not session['user_info']['is_admin']:
        log_event('adminlog called without permission!')
        return render_template('permission_denied.html')

    log_event('adminlog called')
    actual_dir_path = os.path.dirname(os.path.realpath(__file__))
    # There is a difference cwd between local and server execution
    event_log_dir = '..' if os.path.exists(
        os.path.join(actual_dir_path, '../events.txt')) else ''
    event_log_path = 'events.txt'
    return send_from_directory(event_log_dir, event_log_path)
Exemplo n.º 16
0
def changelog():
    # 'app.send_static_file' does not work
    log_event('changelog called')
    return send_from_directory('', 'changelog.txt')