Example #1
0
def ticket():
    """ view of ticket customization """
    printers = execute('wmic printer get sharename',
                       parser='\n',
                       encoding='utf-16')[1:] if os.name == 'nt' else listp()
    form = forms.Printer_f(printers, session.get('lang'))
    tc = data.Touch_store.query.first()
    pr = data.Printer.query.first()

    if form.validate_on_submit():
        if form.kind.data == 1:
            tc.n = True
            pr.value = form.value.data
            pr.active = False
            db.session.add(tc)
            db.session.add(pr)
        else:
            if form.printers.data == "00":
                flash('Error: you must have available printer, to use printed',
                      'danger')
                return redirect(url_for('cust_app.ticket'))
            f = form.printers.data
            pr.product = f
            if os.name != 'nt':
                f = f.split('_')
                pr.vendor = f[0]
                pr.product = f[1]
                pr.in_ep = int(f[2])
                pr.out_ep = int(f[3])
            tc.n = False
            pr.active = True
            pr.langu = form.langu.data
            pr.value = form.value.data
            pr.scale = form.scale.data
            db.session.add(tc)
            db.session.add(pr)
        db.session.commit()
        flash('Notice: settings have been updated .', 'info')
        return redirect(url_for('cust_app.ticket'))
    if not form.errors:
        if tc.n:
            form.kind.data = 1
        else:
            form.kind.data = 2
        form.printers.data = pr.vendor + '_' + pr.product
        form.printers.data += '_' + str(pr.in_ep) + '_' + str(pr.out_ep)
        form.langu.data = pr.langu
        form.value.data = pr.value
        form.scale.data = pr.scale
    return render_template('ticket.html',
                           navbar='#snb2',
                           page_title='Tickets',
                           vtrue=data.Vid.query.first().enable,
                           strue=data.Slides_c.query.first().status,
                           form=form,
                           hash='#da7')
Example #2
0
def alter_featured_dest():
    id = request.form['id']
    query = "SELECT d.name as dest_name, c.name as country_name, d.id, c.id, d.description, i.img_url "\
            "FROM destinations d JOIN countries c ON d.country_id = c.id "\
                                "JOIN dest_images i ON d.id = i.dest_id "\
            "WHERE d.id = {}".format(id)
    dest = execute(query)
    tags = [tag.name for tag in Destination.query.get(id).tags.all()]

    return jsonify(dest, tags)
Example #3
0
def search():
    location = request.args.get('location')
    keyword = request.args.get('keywords')

    form = SearchForm()

    base = 'SELECT d.id, d.name as name, c.name as country, i.img_url, co.name as cont '\
           'FROM destinations d JOIN dest_images i ON d.id = i.dest_id '\
                               'JOIN countries c ON d.country_id = c.id '\
                               'JOIN regions r ON c.region_id = r.id '\
                               'JOIN continents co ON r.cont_id = co.id '
    if location:
        if keyword:
            where = "JOIN dest_tags dt ON dt.dest_id = d.id "\
                    "JOIN tags t ON dt.tag_id = t.id "\
                    "WHERE (c.name = '{}' OR co.name = '{}' OR r.name = '{}') AND t.name = '{}'"\
                    .format(location, location, location, keyword)
        else:
            where = "WHERE (c.name = '{}' or co.name = '{}' OR r.name = '{}')"\
                    .format(location, location, location)
    elif keyword:
        where = "JOIN dest_tags dt ON dt.dest_id = d.id "\
                "JOIN tags t ON dt.tag_id = t.id "\
                "WHERE t.name = '{}'".format(keyword)
    else:
        where = 'ORDER BY random() LIMIT 5'
    query = text(base + where)
    dests = execute(query)

    for dest in dests:
        d = Destination.query.get(dest['id'])
        dest['Tags'] = [tag.name for tag in d.tags.all()]

    explored = [dest.id for dest in current_user.explored_dests.all()]
    favorites = [dest.id for dest in current_user.favorited_dests.all()]

    countries = [country.name for country in Country.query.all()]
    continents = [continent.name for continent in Continent.query.all()]
    regions = [region.name for region in Region.query.all()]
    locations = list(
        set(countries).union(set(list(set(continents).union(set(regions))))))

    tags = [tag.name for tag in Tag.query.all()]

    return render_template('main/search.html',
                           title="Explore | Wanderlist",
                           dests=dests,
                           locations=locations,
                           tags=tags,
                           explored=explored,
                           favorites=favorites,
                           keyword=keyword,
                           location=location,
                           form=form)
Example #4
0
def change_map(where=None):
    view = request.form['view']
    base = 'SELECT l.lat, l.lng, d.name '\
           'FROM dest_locations l JOIN destinations d on l.dest_id = d.id '
    if view == "favorites":
        where = "WHERE l.dest_id IN "\
                    "(SELECT f.dest_id "\
                    "FROM favorites f "\
                    "WHERE f.user_id = {})"\
                    .format(current_user.id)
    elif view == "explored":
        where = "WHERE l.dest_id IN "\
                    "(SELECT e.dest_id "\
                    "FROM explored e "\
                    "WHERE e.user_id = {})"\
                    .format(current_user.id)
    query = text(base + (where if where else ''))
    locations = execute(query)

    return jsonify(locations)
Example #5
0
def test_execute():
    path = absolute_path('static')

    assert sorted(execute(f'ls {path}',
                          parser='\n')) == sorted(os.listdir(path))
Example #6
0
async def execute_handler(request):
    command = request.json['command']
    response = execute(command)
    return json({'response': response})
Example #7
0
File: core.py Project: danfossi/FQM
def serial(t_id):
    """ to generate a new ticket and print it """
    form = forms.Touch_name(session.get('lang'))
    task = data.Task.query.filter_by(id=t_id).first()
    if task is None:
        flash('Error: wrong entry, something went wrong',
              'danger')
        return redirect(url_for("core.root"))
    # if it is registered ticket, will display the form and valuate it
    if not form.validate_on_submit() and data.Touch_store.query.first().n:
        ts = data.Touch_store.query.filter_by(id=0).first()
        tnumber = False
        if data.Printer.query.first().value == 2:
            tnumber = True
        return render_template("touch.html", title=ts.title, tnumber=tnumber,
                               ts=ts, done=False, bgcolor=ts.bgcolor,
                               page_title="Touch Screen - Enter name ",
                               alias=data.Aliases.query.first(),
                               a=4, dire='multimedia/', form=form)
    nm = form.name.data
    n = True if data.Touch_store.query.first().n else False

    # FIX: limit the tickets to the range of waitting tickets, prevent overflow.
    # Assigning the first office in the list
    o_id = task.least_tickets_office().id
    next_number = data.Serial.query.filter_by(office_id=o_id)\
                             .order_by(data.Serial.number.desc())\
                             .first().number + 1

    if data.Serial.query.filter_by(number=next_number, office_id=o_id).first() is None:
        if n:  # registered
            db.session.add(data.Serial(next_number, o_id, t_id, nm, True))
            db.session.commit()
        else:  # printed
            db.session.add(data.Serial(next_number, o_id, t_id, None, False))
            db.session.commit()
            # adding printer support
            q = data.Printer.query.first()
            ppt = data.Task.query.filter_by(id=t_id).first()
            oot = data.Office.query.filter_by(id=o_id).first()
            tnum = data.Serial.query.filter_by(office_id=o_id, p=False).count()
            cuticket = data.Serial.query.filter_by(office_id=o_id, p=False).first()
            tnum -= 1
            langu = data.Printer.query.first().langu
            # to solve Linux printer permissions
            if os.name == 'nt':
                # NOTE: To list all windows printers
                if execute('wmic printer get sharename', parser='\n', encoding='utf-16')[1:]:
                    if langu == 'ar':
                        print_ticket_windows_ar(
                            q.product,
                            oot.prefix + '.' + str(next_number),
                            oot.prefix + str(oot.name),
                            tnum, ppt.name,
                            oot.prefix + '.' + str(cuticket.number),
                            ip=current_app.config['LOCALADDR'])
                    else:
                        print_ticket_windows(
                            q.product,
                            oot.prefix + '.' + str(next_number),
                            oot.prefix + str(oot.name),
                            tnum, ppt.name,
                            oot.prefix + '.' + str(cuticket.number), l=langu,
                            ip=current_app.config['LOCALADDR'])
                    p = True
                else:
                    p = None
            else:
                # To Fix 1: Fail safe drivers. [FIXED]
                try:
                    p = assign(int(q.vendor), int(q.product),
                               int(q.in_ep), int(q.out_ep))
                except Exception:
                    p = None
            if p is None:
                flash('Error: you must have available printer, to use printed',
                      'danger')
                flash("Notice: make sure that printer is properly connected",
                      'info')
                if os.name == 'nt':
                    flash(
                        "Notice: Make sure to make the printer shared on the local network",
                        'info')
                elif platform == "linux" or platform == "linux2":
                    flash(
                        "Notice: Make sure to execute the command `sudo gpasswd -a $(users) lp` and reboot the system",
                        'info')
                return redirect(url_for('cust_app.ticket'))
            if os.name != 'nt':
                if langu == 'ar':
                    printit_ar(
                        p,
                        oot.prefix + '.' + str(next_number),
                        oot.prefix + str(oot.name),
                        tnum, u'' + ppt.name,
                        oot.prefix + '.' + str(cuticket.number))
                else:
                    printit(
                        p,
                        oot.prefix + '.' + str(next_number),
                        oot.prefix + str(oot.name),
                        tnum, u'' + ppt.name,
                        oot.prefix + '.' + str(cuticket.number), lang=langu)
    else:
        flash('Error: wrong entry, something went wrong',
              'danger')
        return redirect(url_for('core.root'))

    # FIX: limit the tickets to the range of waitting tickets, prevent overflow.
    limited_tickets = data.Serial.query.filter_by(p=False)\
                                       .order_by(data.Serial.timestamp)\
                                       .limit(11)

    for a in range(data.Waiting.query.count(), 11):
        for b in limited_tickets.all():
            if data.Waiting.query.filter_by(office_id=b.office_id,
                                            number=b.number, task_id=b.task_id
                                            ).first() is None:
                db.session.add(data.Waiting(b.number, b.office_id, b.task_id, nm, n))
    db.session.commit()
    return redirect(url_for("core.touch", a=1))
Example #8
0
def serial(t_id, office_id=None):
    ''' generate a new ticket and print it. '''
    def printer_failure_redirect(exception):
        flash('Error: you must have available printer, to use printed',
              'danger')
        flash('Notice: make sure that printer is properly connected', 'info')

        if os.name == 'nt':
            flash(
                'Notice: Make sure to make the printer shared on the local network',
                'info')
        elif 'linux' in platform:
            flash(
                'Notice: Make sure to execute the command `sudo gpasswd -a $(users) lp` and '
                'reboot the system', 'info')

        log_error(exception)
        return redirect(url_for('core.root'))

    form = forms.Touch_name(session.get('lang'))
    task = data.Task.get(t_id)
    office = data.Office.get(office_id)
    touch_screen_stings = data.Touch_store.query.first()
    ticket_settings = data.Printer.query.first()
    printed = not touch_screen_stings.n
    numeric_ticket_form = ticket_settings.value == 2
    name_or_number = form.name.data or None

    if not task:
        flash('Error: wrong entry, something went wrong', 'danger')
        return redirect(url_for('core.root'))

    # NOTE: if it is registered ticket, will display the form
    if not form.validate_on_submit() and not printed:
        return render_template('touch.html',
                               title=touch_screen_stings.title,
                               tnumber=numeric_ticket_form,
                               ts=touch_screen_stings,
                               bgcolor=touch_screen_stings.bgcolor,
                               a=4,
                               done=False,
                               page_title='Touch Screen - Enter name ',
                               form=form,
                               dire='multimedia/',
                               alias=data.Aliases.query.first(),
                               office_id=office_id)

    # NOTE: Incrementing the ticket number from the last generated ticket globally
    next_number = data.Serial.query.order_by(data.Serial.number.desc())\
                                   .first().number + 1
    office = office or task.least_tickets_office()

    if printed:
        try:
            current_ticket = data.Serial.all_office_tickets(
                office.id).first().number
        except Exception:
            current_ticket = None
        common_arguments = (f'{office.prefix}.{next_number}',
                            f'{office.prefix}{office.name}',
                            data.Serial.all_office_tickets(office.id).count(),
                            task.name, f'{office.prefix}.{current_ticket}')

        if os.name == 'nt':  # NOTE: Windows printing
            has_printers = bool(
                execute('wmic printer get sharename',
                        parser='\n',
                        encoding='utf-16')[1:])

            if has_printers:
                try:
                    (print_ticket_windows_ar if ticket_settings.langu == 'ar'
                     else print_ticket_windows)(
                         ticket_settings.product,
                         *common_arguments,
                         ip=current_app.config.get('LOCALADDR'),
                         l=ticket_settings.langu)
                except Exception as exception:
                    return printer_failure_redirect(exception)
        else:
            try:
                printer = assign(int(ticket_settings.vendor),
                                 int(ticket_settings.product),
                                 int(ticket_settings.in_ep),
                                 int(ticket_settings.out_ep))

                (printit_ar if ticket_settings.langu == 'ar' else printit)(
                    printer,
                    *common_arguments,
                    lang=ticket_settings.langu,
                    scale=ticket_settings.scale)
            except Exception as exception:
                return printer_failure_redirect(exception)

    db.session.add(
        data.Serial(number=next_number,
                    office_id=office.id,
                    task_id=task.id,
                    name=name_or_number,
                    n=not printed))
    db.session.commit()
    return redirect(url_for('core.touch', a=1, office_id=office_id))