Exemple #1
0
def offices(office, order_by, order_kwargs):
    ''' view and update an office. '''
    if is_operator() and not is_office_operator(office.id):
        flash('Error: operators are not allowed to access the page ', 'danger')
        return redirect(url_for('core.root'))

    form = OfficeForm(current_prefix=office.prefix)
    tickets_form = ProcessedTicketForm()
    page = request.args.get('page', 1, type=int)
    last_ticket_pulled = data.Serial.all_office_tickets(office.id)\
                                    .filter_by(p=True)\
                                    .first()
    tickets = data.Serial.all_office_tickets(office.id, order=False)\
                         .order_by(*data.Serial.ORDERS.get(order_by, []))
    pagination = tickets.paginate(page, per_page=10, error_out=False)
    office_name = remove_string_noise(form.name.data or '',
                                      lambda s: s.startswith('0'),
                                      lambda s: s[1:]) or None

    if form.validate_on_submit():
        if not office.is_valid_new_name(office_name):
            flash('Error: name is used by another one, choose another name',
                  'danger')
            return redirect(url_for('manage_app.offices', o_id=office.id))

        office = data.Office.get(office.id)  # NOTE: DB session is lost
        office.name = office_name
        office.prefix = form.prefix.data.upper()
        db.session.commit()
        flash('Notice: office has been updated. ', 'info')
        return redirect(url_for('manage_app.offices', o_id=office.id))

    form.name.data = office.name
    form.prefix.data = office.prefix.upper()

    return render_template('offices.html',
                           form=form,
                           officesp=pagination.items,
                           pagination=pagination,
                           page_title='Office : ' + office.prefix +
                           str(office.name),
                           o_id=office.id,
                           ooid=office,
                           len=len,
                           serial=tickets,
                           offices=data.Office.query,
                           tasks=data.Task,
                           users=data.User.query,
                           operators=data.Operators.query,
                           navbar='#snb1',
                           dropdown='#dropdown-lvl' + str(office.id),
                           hash='#t1' + str(office.id),
                           last_ticket_pulled=last_ticket_pulled,
                           tickets_form=tickets_form,
                           **order_kwargs)
Exemple #2
0
def serial(task, office_id=None):
    ''' generate a new ticket and print it. '''
    windows = os.name == 'nt'
    form = TouchSubmitForm()
    task = data.Task.get(task.id)
    office = data.Office.get(office_id)
    touch_screen_stings = data.Touch_store.get()
    ticket_settings = data.Printer.get()
    printed = not touch_screen_stings.n
    numeric_ticket_form = ticket_settings.value == 2
    name_or_number = remove_string_noise(form.name.data or '',
                                         lambda s: s.startswith('0'),
                                         lambda s: s[1:]) or None

    # 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)

    new_ticket, exception = data.Serial.create_new_ticket(
        task, office, name_or_number)

    if exception:
        flash('Error: you must have available printer, to use printed',
              'danger')
        flash('Notice: make sure that printer is properly connected', 'info')

        if windows:
            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'))

    return redirect(url_for('core.touch', a=1, office_id=office_id))
Exemple #3
0
def serial(task, office_id=None):
    ''' generate a new ticket and print it. '''
    windows = os.name == 'nt'
    form = TouchSubmitForm()
    task = data.Task.get(task.id)
    office = data.Office.get(office_id)
    touch_screen_stings = data.Touch_store.get()
    ticket_settings = data.Printer.get()
    settings = data.Settings.get()
    printed = not touch_screen_stings.n
    numeric_ticket_form = ticket_settings.value == 2
    name_or_number = remove_string_noise(form.name.data or '',
                                         lambda s: s.startswith('0'),
                                         lambda s: s[1:]) or None

    # 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:
        current_ticket = getattr(
            data.Serial.all_office_tickets(office.id).first(), 'number', 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}')

        try:
            if windows or settings.lp_printing:
                (print_ticket_cli_ar if ticket_settings.langu == 'ar' else
                 print_ticket_cli)(ticket_settings.name,
                                   *common_arguments,
                                   language=ticket_settings.langu,
                                   windows=windows,
                                   unix=not windows)
            else:
                printer = assign(ticket_settings.vendor,
                                 ticket_settings.product,
                                 ticket_settings.in_ep, 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:
            flash('Error: you must have available printer, to use printed',
                  'danger')
            flash('Notice: make sure that printer is properly connected',
                  'info')

            if windows:
                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'))

    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))