Exemplo n.º 1
0
    def set_selected_state(self,selected_state,initial_state):
        mainlog.debug("selected_state {}".format(selected_state))
        mainlog.debug("initial_state {}".format(initial_state))

        self.initial_state = initial_state
        self.selected_state = selected_state
        self._drawNodes(self.scene,selected_state,self.initial_state)
Exemplo n.º 2
0
    def _show_filter(self, fq):
        if fq:
            mainlog.debug("_show_filter : {}".format(fq.query))

            if fq.owner_id == user_session.user_id:
                self.query_label.setText("<b>{}</b>".format(fq.name))
            else:
                self.query_label.setText("<b>{}</b> ({})".format(
                    fq.name, fq.owner.fullname))

            self.super_filter_entry.setText(fq.query)
            self.save_filter_button.setEnabled(
                fq.owner_id == user_session.user_id)
            self.delete_filter_button.setEnabled(
                fq.owner_id == user_session.user_id)

            if fq.shared:
                self.share_filter.setCheckState(Qt.Checked)
            else:
                self.share_filter.setCheckState(Qt.Unchecked)
        else:
            mainlog.debug("_show_filter : {}".format(None))

            self.super_filter_entry.setText("")
            self.share_filter.setCheckState(Qt.Unchecked)
            self.save_filter_button.setEnabled(True)
            self.delete_filter_button.setEnabled(True)
Exemplo n.º 3
0
    def createEditor(self, parent, option, index):

        proxy = index.model().index(
            index.row(),
            index.column() - 2).data(
                Qt.UserRole)  # FIXME hardcoding columns is baaaad :-)

        if not proxy:
            return

        machines = machine_service.find_machines_for_operation_definition(
            proxy.operation_definition_id)
        editor = AutoCompleteComboBox(self, parent)
        editor.section_width = [400]

        labels = [None]  # Null machine is OK
        items = [None]
        for m in machines:
            labels.append(m.fullname)
            items.append(m.machine_id)

        mainlog.debug(labels)

        editor.make_str_model(labels, items)

        # if option:
        #     editor.setGeometry(option.rect)

        return editor
Exemplo n.º 4
0
 def __init__(self,parent):
     super(HorsePanel,self).__init__(parent)
     self._needs_refresh = True
     self._panel_visible = False
     self._panel_manager = None # Will be set when the panel is registerd in the panel manager
     self._panel_title = None # Title of the panel to be shown to the user, use the setter
     mainlog.debug( "HorsePanel.__init__()")
Exemplo n.º 5
0
def alter_data():
    # For the moment I skip this because I think that adding a role that is not
    # supported by the user session might lock people out of Horse
    # return

    import os
    import shutil

    q = session().query(Document).order_by(Document.document_id).all()
    for document in q:

        path, filename = os.path.split(document.server_location)
        new_path = documents_service._make_path_to_document(
            document.document_id, document.filename)

        mainlog.debug(u"Document {} -> filename:{} -- new_name:{}".format(
            document.document_id, document.filename, new_path))

        try:

            shutil.copy(document.server_location, new_path)
            document.server_location = new_path

        except Exception as ex:
            mainlog.error("Unable to copy !")
            mainlog.exception(ex)
            session().rollback()
            return

    session().commit()
Exemplo n.º 6
0
    def dragLeaveEvent(self, e):
        # For some reason, I don't always receive the leave event. Don't know why...

        e.accept()
        mainlog.debug("dragLeaveEvent")
        self.show_drop_zones(False)
        self._set_buttons_visible(True)
Exemplo n.º 7
0
    def _add_file(self, full_path_client: str, document_category_id=None):
        mainlog.debug(
            "document widget _add_file categ={}".format(document_category_id))
        if self._test_file_access(full_path_client):
            progress_bar = make_progress(_("Uploading"), 100)

            def progress_tracker(percent):
                progress_bar.setValue(int(percent))

            try:
                doc_id = upload_document(full_path_client, progress_tracker)
            except Exception as exc:
                progress_bar.close()
                showErrorBox(_(
                    "There was a problem while uploading the file to the server"
                ),
                             ex=exc,
                             object_name="file_upload_error")
                return

            d = self.documents_service.find_by_id(doc_id)
            doc = Document()
            doc.document_id = d.document_id
            doc.file_size = d.file_size
            doc.description = d.description
            doc.filename = d.filename
            doc.server_location = d.server_location
            doc.upload_date = d.upload_date

            if document_category_id:
                doc.document_category_id = document_category_id

            self.model.append_objects([doc])
Exemplo n.º 8
0
    def load_network_param(self):
        """ Load the network parameters. The priority is the config file first,
        then, if empty or not properly filled in, we guess it for net.cfg.
        This is for the delivery_slips side.
        :return:
        """

        ip_address = None
        try:
            f = open(os.path.join(resource_dir, "net.cfg"))
            ip_address = f.read().strip()
            f.close()
        except Exception as ex:
            mainlog.warn("net.cfg file not found, using current configuration")
            return

        # if string_represents_ip_address(ip_address):
        mainlog.debug(
            "net.cfg file was read. Server is there : {}".format(ip_address))

        if ":" in ip_address:
            host, port = ip_address.split(":")
            port = int(port)
            mainlog.debug("Address has port : {}:{}".format(host, port))
            self.set_server_network_address(host, port, overwrite=False)
        else:
            self.set_server_network_address(ip_address, overwrite=False)
Exemplo n.º 9
0
    def accept(self):
        global dao

        # FIXME I gusess it's the one below, but I must make sure
        mainlog.debug("Accept() : Current item {}".format( self.customer_select.currentIndex()))

        # if not (self.customer_select.currentIndex() == 0 and self.customer_select.list_view.currentIndex().row() == -1):

        if self.customer_select.currentIndex() >= 0:
            customer = self.customer_select.itemData( self.customer_select.currentIndex(), Qt.UserRole)
        else:
            customer = None

        if customer is None:
            msgBox = makeErrorBox(_("Please choose a customer for the new order"))
            msgBox.exec_()
            super(CreateNewOrderDialog,self).accept()
            return False

        self.customer_select.list_view.itemSelected.disconnect()
        self.customer_select.list_view.setVisible(False)
        self.customer_select = None

        self.current_customer = customer
        # self.customer_select.hide() # FIXME Very hackish. If I don't do this then the QApplication loses focus when this dialog is closed...
        #self.setFocus()
        return super(CreateNewOrderDialog,self).accept()
Exemplo n.º 10
0
    def build_client_side_rpc_request(self, func: JsonCallable, *func_params):
        assert hasattr(
            func, '_json_callable'
        ), "Function is not decorated as a JSON callable function"
        func_sig = signature(func._original_func)

        # mainlog.debug("build_client_side_rpc_request : analyzing {}".format(func))
        # if ismethod(func):
        mainlog.debug("Client calling method {}, params : {}".format(
            func._original_func.__name__, func_params))
        jsonrpc = {
            "jsonrpc":
            "2.0",
            "method":
            func.get_service_name(),
            "params":
            self.params_to_jsonable(func_sig, func.in_recursive_set,
                                    func_params),
            "id":
            1
        }
        mainlog.debug("rpc request is : {}".format(jsonrpc))

        # elif isfunction(func):
        #     mainlog.debug("Client calling function {}, params : {}".format(func._original_func.__name__, func_params))
        #     jsonrpc = {
        #         "jsonrpc": "2.0",
        #         "method": "service." + func.__name__,
        #         "params": json_caller.params_to_jsonable( func_sig, False, func.in_recursive_set, func_params),
        #         "id": 1}
        #     mainlog.debug("rpc request is : {}".format( jsonrpc))
        # else:
        #     raise Exception("Unable to guess the type of function {} maybe {} ?".format(func, type(func)))

        return jsonrpc
Exemplo n.º 11
0
    def in_process_call(self, func: JsonCallable, *func_params):
        """ Make an in process call. That is, a call that goes through JSON serialisation/deserialisation
        but without using an http connection. This is useful when testing
        serialisation.

        This shall be called from the JsonCallable decorator.

        :param func:
        :param func_params:
        :return:
        """

        assert hasattr(
            func, '_json_callable'
        ), "Function is not decorated as a JSON callable function"
        func_sig = signature(func._original_func)

        intermediate = jsonable_to_json(
            self.params_to_jsonable(func_sig, func.in_recursive_set,
                                    func_params))

        params = self.jsonable_to_params(func_sig, func.in_recursive_set,
                                         json_to_jsonable(intermediate))
        call_result = func.call_decorated(**params)

        intermediate = jsonable_to_json(
            self.return_values_to_jsonable(func_sig, func.out_recursive_set,
                                           call_result))
        mainlog.debug("in process mode : {}".format(intermediate))
        return self.jsonable_to_return_values(func_sig, func.out_recursive_set,
                                              json_to_jsonable(intermediate))
Exemplo n.º 12
0
        def __call__(self, *args, **kwargs):
            if self._call_mode == CallMode.transparent:
                mainlog.debug(
                    "JsoncCallableDecorator : transparent call transfer")
                mainlog.debug("args = {}".format(args))
                return self.call_decorated(*args, **kwargs)

            elif self._call_mode == CallMode.http:
                assert self._call_handler, "Call handler not set for http mode"
                mainlog.debug("JsoncCallableDecorator : making http call")
                rpc_request = self._call_handler.build_client_side_rpc_request(
                    self, *args)
                jsonable_res = self._call_handler.call_json_rpc_over_http(
                    rpc_request)
                mainlog.debug(
                    "JsoncCallableDecorator : making http call, result is {}".
                    format(jsonable_res))
                func_sig = signature(self._decorated_func)
                return self._call_handler.jsonable_to_return_values(
                    func_sig, self.out_recursive_set, jsonable_res['result'])

                # return self._call_handler.jsonable_to_return_values( jsonable_res)

            elif self._call_mode == CallMode.in_process:
                assert self._call_handler, "Call handler not set for in process mode"
                mainlog.debug(
                    "JsoncCallableDecorator : making in process call, params are {}"
                    .format(args))
                return self._call_handler.in_process_call(
                    self, *args, **kwargs)

            else:
                mainlog.error("Unsupported call mode {}, {}".format(
                    self._call_mode, self._call_mode == CallMode.in_process))
Exemplo n.º 13
0
def typed_values_to_jsonable(metadata: SQLAMetaData, type_, recursive_set,
                             value):
    mainlog.debug("typed_values_to_jsonable : {}, value is {}".format(
        type_, value))

    # Check fundamental types first to optimize conversion speed

    if value is None:
        return None
    elif type_ in (int, float, str, bool, sqltypes.Integer, sqltypes.Float,
                   sqltypes.String, sqltypes.Boolean):
        return value
    elif type_ == Decimal:
        return Decimal(value)
    elif type_ in (date, sqltypes.Date):
        return value.strftime("%Y-%m-%d")
    elif type_ == datetime:
        return value.strftime("%Y-%m-%dT%H:%M:%S.%f")
    elif isinstance(type_, Enum):
        return value
    elif type_ == KeyedTuplesSequence:
        return keyed_tuple_sequence_to_jsonable(metada, recursive_set, type_,
                                                value)
    elif type_ == sqlalchemy.util._collections.KeyedTuple:
        # We assume each keyed tuple only contains only jsonable values.
        # FIXME That's rather bold !

        r = value._asdict()
        # mainlog.debug(r)
        return r
    elif type_ == bytes:  # Python 3
        return base64.b64encode(value).decode('ascii')
    elif isinstance(type_, Sequence):
        # In particular, this works for Sequence[KeyedTuples]
        return [
            typed_values_to_jsonable(metadata, type_.target, recursive_set, v)
            for v in value
        ]
    elif isinstance(type_, Tuple):
        mainlog.debug("typed_values_to_jsonable : Tuple")
        assert len(type_.targets) == len(
            value
        ), "Value (of type tuple) length doesn't match prototype's length"
        return [
            typed_values_to_jsonable(metadata, type_.targets[i], recursive_set,
                                     value[i])
            for i in range(len(type_.targets))
        ]
    elif metadata.is_class_mapped(type_):
        return sqla_to_dict(metadata, type_, value, recursive_set)
    elif hasattr(type_, 'to_jsonable'):
        return type_.to_jsonable(value)
    elif isinstance(value, object):
        raise Exception(
            "Unable to transform object to jsonable : {} - {} (was it mapped ? {})"
            .format(type_, value, metadata.is_class_mapped(type_)))
        # return value.__dict__
    else:
        mainlog.warn("Unable to serialize type {}".format(type_))
        return value
Exemplo n.º 14
0
    def copy_operations_slot(self):
        mainlog.debug("copy_operations_slot")

        view = self.view
        model = self.model

        # Collect the rows indices

        rows = set()
        for ndx in view.selectedIndexes():
            if ndx.row() >= 0:
                rows.add(ndx.row())

        # There are no guarantee on the selectedIndexes order
        rows = sorted(list(rows))


        # Copy for elsewhere in Horse

        if len(rows):
            operations = []
            for row_ndx in rows:
                operation = model.object_at(row_ndx)
                mainlog.debug(operation)
                operations.append(operation)
            copy_paste_manager.copy_operations(operations)
        else:
            # If nothing to copy then we leave the copy/paste clipboard
            # as it is. So one could paste again what he copied before.
            pass
Exemplo n.º 15
0
def init_test_database():

    # My idea is that the tests run under the same database constraints
    # as production. That is, the code can only change data, not database
    # structure.

    admin_url = configuration.get("Database", "admin_url")
    client_url = configuration.get("Database", "url")

    # login, password, dbname, host, port = _extract_db_params_from_url(client_url)

    set_up_database(admin_url, client_url)
    init_db_session(admin_url)
    create_all_tables()
    disconnect_db()

    # Do client level stuff

    init_db_session(client_url, koi.db_mapping.metadata, echo_query=False)

    mainlog.debug("Initializing DB for tests")
    create_root_account()
    do_basic_inserts(do_sequence=False)
    init_sequences(session())

    add_user('dd', 'dd', 'Gandalf', 'TimeTrackModify,ModifyParameters')
    session().flush()
    session().expunge_all()
Exemplo n.º 16
0
def attribute_analysis(model):
    global attribute_analysis_cache

    if model not in attribute_analysis_cache:
        mainlog.debug("Analysing model {}".format(model))
        # Warning ! Some column properties are read only !
        fnames = [
            prop.key for prop in inspect(model).iterate_properties
            if isinstance(prop, ColumnProperty)
        ]

        single_rnames = []
        rnames = []
        for key, relation in inspect(model).relationships.items():
            if relation.uselist == False:
                single_rnames.append(key)
            else:
                rnames.append(key)

        # Order is important to rebuild composite keys (I think, not tested so far.
        # See SQLA comment for query.get operation :
        # http://docs.sqlalchemy.org/en/rel_1_0/orm/query.html#sqlalchemy.orm.query.Query.get )
        knames = [key.name for key in inspect(model).primary_key]

        mainlog.debug(
            "For model {}, I have these attributes : keys={}, fields={}".
            format(model, knames, fnames))

        attribute_analysis_cache[model] = (fnames, rnames, single_rnames,
                                           knames)

    return attribute_analysis_cache[model]
Exemplo n.º 17
0
    def dragEnterEvent(self, e: QDragEnterEvent):
        """ Only accept what looks like a file drop action
        :param e:
        :return:
        """

        if e.mimeData() and e.mimeData().hasUrls() and e.mimeData().urls(
        )[0].toString().startswith(
                "file://") and e.proposedAction() == Qt.DropAction.CopyAction:

            mainlog.debug("dragEnterEvent : I accept")
            # Attention ! The actual drop area is smaller
            # than the dragEnter area !

            e.acceptProposedAction()
            e.accept()

            # I don't use childAt because childAt will be fooled by the buttons
            # I have in this tableview (the buttons are the children of the
            # tableview, not the viewport... I guess)

            #if self.viewport().geometry().contains(e.pos()):
            self._compute_drop_zone(e.pos(), e.mimeData())
            self.show_drop_zones(True)
            self._set_buttons_visible(False)

            self.update()

        else:
            mainlog.debug("dragEnterEvent : I ignore")
            e.ignore()
Exemplo n.º 18
0
    def upload_template_document3(self, encoding_safe_filename, doc_id,
                                  uploaded_file):
        """ Create or replace a new template document.

        :param encoding_safe_filename:
        :param uploaded_file:
        :param doc_id:
        :return:
        """

        mainlog.warn("upload_template_document3 : DEPRECATED")

        doc_id = int(doc_id)

        if doc_id == 0:
            mainlog.debug("upload_template_document3 : upload")
            file_id = documents_service.save_template(uploaded_file.file,
                                                      encoding_safe_filename)
            return str(file_id)
        elif doc_id > 0:
            mainlog.debug(
                "upload_template_document3 : replace  doc_id={}".format(
                    doc_id))
            documents_service.replace_template(doc_id, uploaded_file.file,
                                               encoding_safe_filename)
            return
Exemplo n.º 19
0
    def rows_inserted(self, parent, first, last):
        mainlog.debug("rows_inserted {} {} / row_count={}/{}".format(
            first, last, self.model.rowCount(), self.model.columnCount()))
        for row in range(first, last + 1):
            self._set_widget_buttons(row)

        self.documents_list_changed.emit()
Exemplo n.º 20
0
def open_a_file_on_os(filepath):

    if filepath.endswith(".pdf"):

        pdf_cmd = configuration.get('Programs', 'pdf_viewer')
        mainlog.debug("Opening PDF {} with {}".format(filepath, pdf_cmd))
        if pdf_cmd:
            # Start our own viewer (which is way faster than acrobat)
            p1 = subprocess.Popen([pdf_cmd, filepath])
            p1.wait()
        else:
            os.startfile(filepath)

        return

    if sys.platform.startswith('darwin'):
        subprocess.call(('open', filepath))

    elif os.name == 'nt':

        if filepath.endswith(".docx"):
            import win32com.client

            # See http://stackoverflow.com/questions/26907177/key-error-while-using-cx-freeze-for-making-exe
            # word = win32com.delivery_slips.gencache.EnsureDispatch('Word.Application')
            word = win32com.client.dynamic.Dispatch('Word.Application')

            word.Visible = True
            doc = word.Documents.Open(filepath)
        else:
            os.startfile(filepath)

    elif os.name == 'posix':
        subprocess.call(('xdg-open', filepath))
Exemplo n.º 21
0
    def _open_file_dialog(self):
        # This method exists to allow the test to avoid the file dialog.
        # Automating test of QFileDialog is super complex.

        mainlog.debug("__open_file_dialog")
        return QFileDialog.getOpenFileName(self, _('Add a document'), "",
                                           "")[0]
Exemplo n.º 22
0
def p_date_in_period_expression(p):
    ''' date_in_period_expression : date_term IN period_term '''

    mainlog.debug(p[3][0])
    mainlog.debug(p[3][1])

    p[0] = and_(p[1] != None, p[1].between(p[3][0], p[3][1]))
Exemplo n.º 23
0
 def set_visibility(self, visible):
     if self._panel_visible != visible:
         self._panel_visible = visible
         if self._panel_visible and self._needs_refresh:
             mainlog.debug("Panel is being refreshed now")
             self.refresh_action()
             self._needs_refresh = False
Exemplo n.º 24
0
    def change_several_order_parts_state(self, order: Order,
                                         order_parts_states_map: dict):
        """ Set the state of one or more order parts to the give state.
        All the parts *must* belong to the given order.

        Once this is done the state of the given order is adapted
        to match the states of the parts.
        """

        if not order_parts_states_map:
            mainlog.debug("change_several_order_parts_state : nothing to do")
            return

        for state in order_parts_states_map.values():
            if state not in OrderPartStateType:
                raise DataException("Improper target state {}".format(state),
                                    DataException.IMPROPER_STATE_TRANSITION)

        mainlog.debug("change_several_order_parts_state {}".format(
            order_parts_states_map))

        for order_part in order.parts:
            if order_part in order_parts_states_map:
                # order_part.transition_state(state)
                business_computations_service.transition_part_state(
                    order_part, order_parts_states_map[order_part])

        # Adapt the order's state to its parts' states

        business_computations_service.compute_order_state_from_parts(order)
Exemplo n.º 25
0
    def completion_selected(self, ndx):
        self.completion.hide()
        self.activateWindow()
        self.setFocus(Qt.OtherFocusReason)

        t = self.text()
        cp = self.cursorPosition()
        w, start, end = word_at_point(self.text(), cp)

        action, start, end = self.replacement_area

        completion = self.completion.get_current_completion()
        if self.quote:
            completion = u"\"{}\"".format(completion)

        completion = u" {} ".format(completion)

        if action == 'rep':
            mainlog.debug("Replacing {} in |{}|={} [{},{}] by {}".format(
                w, t, self.cursorPosition(), start, end,
                self.completion.get_current_completion()))

            t_start = (t[0:start] + completion).lstrip()
            t_end = t[end + 1:len(t)]
            cp = len(t_start)
            t = t_start + t_end
        else:
            t_start = (t[0:start] + u" " + completion + u" ").lstrip()
            t_end = t[end + 1:len(t)]
            cp = len(t_start)
            t = t_start + t_end

        self.setText(t)
        self.setCursorPosition(cp)
Exemplo n.º 26
0
def p_period_function_month_term(p):
   ''' period_term : MONTH_BEFORE '''

   d = month_before(date.today())

   p[0] = ( _first_moment_of_month(d), _last_moment_of_month(d) )
   mainlog.debug(p[0])
Exemplo n.º 27
0
def init_db_session(db_url,
                    metadata=None,
                    echo_query=False,
                    autocommit=False,
                    params=dict()):
    global _config

    mainlog.debug("Init DB session " + str(db_url))

    if 'session' in _config:
        raise Exception(
            "Sorry, but you're trying ot double initialize the db session")

    db_url, params_from_url = parse_db_url(db_url)
    params = dict(list(params_from_url.items()) + list(params.items()))

    mainlog.debug("Creating engine to {} with params {}".format(
        db_url, params))
    engine = create_engine(db_url,
                           encoding='utf-8',
                           echo=echo_query,
                           poolclass=NullPool,
                           connect_args=params)

    _config['engine'] = engine

    if metadata:
        metadata.bind = engine

    # Scoped session gives us thread safety which is very important
    # in our web server (multi thread) context

    _config['session_factory'] = sessionmaker(bind=engine,
                                              autocommit=autocommit)
    _config['session'] = scoped_session(_config['session_factory'])
Exemplo n.º 28
0
def p_period_function_current_month_term(p):
   ''' period_term : CURRENT_MONTH '''

   d = date.today()
   p[0] = ( _first_moment_of_month(d), _last_moment_of_month(d) )
   mainlog.debug("CurrentMonth")
   mainlog.debug(p[0])
Exemplo n.º 29
0
    def save(self):
        mainlog.debug("EditTimeTracksDialog.save()")
        errors = self.controller.model.validate()
        if errors:
            showTableEntryErrorBox(errors)
            return False

        tt_start_time = datetime(self.edit_date.year, self.edit_date.month,
                                 self.edit_date.day, 6, 0, 0)
        edited_proxy_tts = self.controller.model.model_to_objects(
            lambda: TimetrackProxy())
        employee_id = self.current_employee_id_selected

        # for tt in edited_proxy_tts:
        #     mainlog.debug(type(tt))
        #     mainlog.debug(str(tt))

        try:
            save_proxy_timetracks(edited_proxy_tts, tt_start_time, employee_id)
            return True
        except Exception as e:
            msgBox = QMessageBox(self)
            msgBox.setIcon(QMessageBox.Critical)
            msgBox.setText("There was an error while saving your data")
            msgBox.setInformativeText(str(e))
            msgBox.setStandardButtons(QMessageBox.Ok)
            # msgBox.setDefaultButton(QMessageBox.Ok);
            ret = msgBox.exec_()
            return False
Exemplo n.º 30
0
    def contextMenuEvent(self, event):
        p = self.mapToScene(event.pos())
        item = self.scene().itemAt(p)

        if item:
            item.setSelected(True)
            selected = item.data(0)

            if hasattr(selected, "type"):
                stype = selected.type
            else:
                stype = None

            if selected is None:
                self.tar_presence_menu.move(event.globalPos())
                self.tar_presence_menu.show()
            elif isinstance(selected, TaskActionReport):
                self.tar_menu.move(event.globalPos())
                self.tar_menu.show()
            elif stype in (Task, TaskOnOperation, TaskOnNonBillable,
                           TaskOnOrder):
                self.task_menu.move(event.globalPos())
                self.task_menu.show()
            else:
                mainlog.debug(
                    "contextMenuEvent : can't do anything on {} (type={})".
                    format(selected, stype))
        else:
            self.all_menu.move(event.globalPos())
            self.all_menu.show()