def check_name_uniqueness(self, data):
        name = data.get('name')
        if not name:
            return True
        search_type = self.tactic_widget.get_search_type()

        if not search_type and self.sobject:
            search_type = self.sobject.info.get('pipeline_code')
            search_type = tc.server_start().build_search_type(search_type)

        if name and search_type:
            filters = [('name', name)]
            existing = tc.server_start().query(search_type, filters)

            if self.get_view() == 'edit':
                # check if we editing and leaved the same name, not warn about uniqueness
                if self.init_data.get('name') == name:
                    existing = False

            if existing:
                msb = QtGui.QMessageBox(QtGui.QMessageBox.Question, 'This Name already used!',
                                        "Do you want to use this name anyway?",
                                        QtGui.QMessageBox.NoButton, self)
                msb.addButton("Yes", QtGui.QMessageBox.YesRole)
                msb.addButton("No", QtGui.QMessageBox.NoRole)
                msb.exec_()
                reply = msb.buttonRole(msb.clickedButton())

                if reply == QtGui.QMessageBox.YesRole:
                    return True
                elif reply == QtGui.QMessageBox.NoRole:
                    return False

            return True
示例#2
0
    def subscriptions_query(self):
        import collections

        stub = tc.server_start()

        all_sobjects = tc.query_tab_names(True)

        filters = [('login', env.Env.get_user()),
                   ('project_code', env.Env.get_project())]

        subscriptions = stub.query('sthpw/subscription', filters)

        spl = collections.defaultdict(list)

        for sub in subscriptions:
            split = stub.split_search_key(sub['message_code'])
            spl[split[0]].append(split[1])

        parents = collections.defaultdict(list)
        for key, values in spl.iteritems():
            parents[key.split('?')[0]] = \
                tc.get_sobjects(sobjects_list=stub.query(key, [('code', values)]), get_snapshots=False)

        pprint(all_sobjects)
        pprint(dict(parents))

        # print(stub.get_parent('cgshort/shot?project=the_pirate&code=SHOT00001'))

        server = tc.server_start()
        expr = "@GET(cgshort/shot.cgshort/scenes.code)"
        result = server.eval(expr)
        pprint(result)
        pprint(stub.query('cgshort/shot', [('scenes_code', 'SCENES00001')]))
    def subscriptions_query(self):
        import collections

        stub = tc.server_start()

        all_sobjects = tc.query_tab_names(True)

        filters = [('login', env.Env.get_user()), ('project_code', env.Env.get_project())]

        subscriptions = stub.query('sthpw/subscription', filters)

        spl = collections.defaultdict(list)

        for sub in subscriptions:
            split = stub.split_search_key(sub['message_code'])
            spl[split[0]].append(split[1])

        parents = collections.defaultdict(list)
        for key, values in spl.iteritems():
            parents[key.split('?')[0]] = \
                tc.get_sobjects(sobjects_list=stub.query(key, [('code', values)]), get_snapshots=False)

        pprint(all_sobjects)
        pprint(dict(parents))

        # print(stub.get_parent('cgshort/shot?project=the_pirate&code=SHOT00001'))

        server = tc.server_start()
        expr = "@GET(cgshort/shot.cgshort/scenes.code)"
        result = server.eval(expr)
        pprint(result)
        pprint(stub.query('cgshort/shot', [('scenes_code', 'SCENES00001')]))
    def add_item(self):
        """
        Adding s object item
        :return: None
        """
        image = self.previewImageLineEdit.text()
        name = self.nameLineEdit.text()
        description = self.descriptionTextEdit.toPlainText()
        keywords = self.keywordsTextEdit.toPlainText()
        if name:
            filters = [('name', name)]
            existing = tc.server_start().query(self.tab_name, filters)
            if existing:
                msb = QtGui.QMessageBox(QtGui.QMessageBox.Question, 'This Name already used!',
                                        "Do you want to use this name anyway?",
                                        QtGui.QMessageBox.NoButton, self)
                msb.addButton("Yes", QtGui.QMessageBox.YesRole)
                msb.addButton("No", QtGui.QMessageBox.NoRole)
                msb.exec_()
                reply = msb.buttonRole(msb.clickedButton())

                if reply == QtGui.QMessageBox.YesRole:
                    sobject = tc.create_sobject(name, description, keywords, self.tab_name)
                    if image:
                        snapshot = tc.create_snapshot(sobject['__search_key__'], 'icon')
                        tc.checkin_icon(snapshot['__search_key__'], image)
                    self.close()
                elif reply == QtGui.QMessageBox.NoRole:
                    pass
            else:
                sobject = tc.create_sobject(name, description, keywords, self.tab_name)
                if image:
                    snapshot = tc.create_snapshot(sobject['__search_key__'], 'icon')
                    tc.checkin_icon(snapshot['code'], image)
                self.close()
示例#5
0
    def run_script(self):

        code = self.scriptTextEdit.toPlainText()
        code_dict = {
            'code': code
        }

        result = tc.server_start().execute_python_script('', kwargs=code_dict)
        import pprint
        if not result['info']['spt_ret_val']:
            self.stackTraceTextEdit.setText(str(result['status']))
        else:
            self.stackTraceTextEdit.setText(pprint.pformat(result['info']['spt_ret_val']))
    def dynamic_query(self, limit=0, offset=0):

        filters = []
        order_bys = ['timestamp desc']
        columns = []
        sobjects_list = tc.server_start().query(self.current_stype, filters, columns, order_bys, limit=limit, offset=offset)
        print self.current_stype
        print sobjects_list
        print filters
        all_process = self.context_items[self.current_stype]
        sobjects = tc.get_sobjects(all_process, sobjects_list)

        return sobjects
    def run_script(self):

        code = self.scriptTextEdit.toPlainText()
        code_dict = {
            'code': code
        }

        result = tc.server_start().execute_python_script('', kwargs=code_dict)
        import pprint
        if not result['info']['spt_ret_val']:
            self.stackTraceTextEdit.setText(str(result['status']))
        else:
            self.stackTraceTextEdit.setText(pprint.pformat(result['info']['spt_ret_val']))
    def check_name_uniqueness(self, data):
        name = data.get('name')
        if not name:
            return True
        search_type = self.tactic_widget.get_search_type()

        if not search_type and self.sobject:
            search_type = tc.server_start().split_search_key(
                self.sobject.get_search_key())
            search_type = search_type[0]

        if name and search_type:
            filters = [('name', name)]
            existing = tc.server_start().query(search_type, filters)

            if self.get_view() == 'edit':
                # check if we editing and leaved the same name, not warn about uniqueness
                if self.init_data.get('name') == name:
                    existing = False

            if existing:
                msb = QtGui.QMessageBox(
                    QtGui.QMessageBox.Question, 'This Name already used!',
                    "Do you want to use this name anyway?",
                    QtGui.QMessageBox.NoButton, self)
                msb.addButton("Yes", QtGui.QMessageBox.YesRole)
                msb.addButton("No", QtGui.QMessageBox.NoRole)
                msb.exec_()
                reply = msb.buttonRole(msb.clickedButton())

                if reply == QtGui.QMessageBox.YesRole:
                    return True
                elif reply == QtGui.QMessageBox.NoRole:
                    return False

            return True
    def add_child_sobjects(self):
        if not self.info['is_expanded']:

            self.info['is_expanded'] = True

            server = tc.server_start()
            built_process = server.build_search_type(self.child.get('from'), self.project.info.get('code'))

            child_code = None

            relationship = self.child.get('relationship')
            if relationship:
                if relationship == 'search_type':
                    child_code = 'search_code'
                elif relationship == 'code':
                    child_code = '{0}_code'.format(self.child.get('to').split('/')[-1])

            if not child_code:
                child_code = self.child.get('from_col')

            filters = [(child_code, self.sobject.info.get('code'))]

            assets = server.query(built_process, filters)

            if self.stype.pipeline:
                process = []
                for pipe in self.stype.pipeline.values():
                    process.extend(pipe.process.keys())
            else:
                process = []

            sobjects = tc.get_sobjects(process, assets, project_code=self.project.info.get('code'))
            stype = self.stype
            sobject_item_widget = self.get_parent_item_widget()

            for sobject in sobjects.itervalues():
                item_info = {
                    'relates_to': self.info['relates_to'],
                    'is_expanded': False,
                }
                gf.add_sobject_item(
                    self.tree_item,
                    self.parent_ui,
                    sobject,
                    stype,
                    item_info,
                    ignore_dict=sobject_item_widget.ignore_dict
                )
示例#10
0
    def dynamic_query(self, limit=0, offset=0):

        filters = []
        order_bys = ['timestamp desc']
        columns = []
        sobjects_list = tc.server_start().query(self.current_stype,
                                                filters,
                                                columns,
                                                order_bys,
                                                limit=limit,
                                                offset=offset)
        print self.current_stype
        print sobjects_list
        print filters
        all_process = self.context_items[self.current_stype]
        sobjects = tc.get_sobjects(all_process, sobjects_list)

        return sobjects
    def __init__(self, stype, item=None, view='insert', parent=None):
        super(self.__class__, self).__init__(parent=parent)
        #TODO get title from within
        self.settings = QtCore.QSettings('{0}/settings/{1}/{2}/{3}/main_ui_config.ini'.format(
            env_mode.get_current_path(),
            env_mode.get_node(),
            env_server.get_cur_srv_preset(),
            env_mode.get_mode()),
            QtCore.QSettings.IniFormat)

        self.parent_ui = parent

        self.item = item
        self.stype = stype
        self.search_type = self.stype.info.get('code')

        self.view = view

        self.search_key = None
        self.parent_search_key = None
        if self.item:
            self.search_key = self.item.get_search_key()
            self.parent_search_key = self.item.get_parent_search_key()

        kwargs_edit = {
            'args': {
                'input_prefix': 'edit',
                'search_key': self.search_key,
                'parent_key': self.parent_search_key,
                'view': 'edit',
            },
            'search_type': self.search_type,
        }

        kwargs_insert = {
            'args': {
                'mode': 'insert',
                'input_prefix': 'insert',
                'parent_key': self.parent_search_key,
                'search_type': self.search_type,
                'view': 'insert',
            },
            'search_type': self.search_type,
        }

        if self.view == 'edit':
            kwargs = kwargs_edit
        else:
            kwargs = kwargs_insert

        code = tq.prepare_serverside_script(tq.query_EditWdg, kwargs, return_dict=True)
        result = tc.server_start().execute_python_script('', kwargs=code)
        result_dict = json.loads(result['info']['spt_ret_val'])

        input_widgets_list = []
        if self.item:
            result_dict['EditWdg']['sobject'] = self.item.get_sobject()
            result_dict['EditWdg']['parent_sobject'] = self.item.get_parent_sobject()

        tactic_edit_widget = tw.TacticEditWdg(result_dict['EditWdg'])

        self.edit_window = twc.QtTacticEditWidget(
            tactic_widget=tactic_edit_widget,
            qt_widgets=input_widgets_list,
            parent=self
        )

        for widget_dict in result_dict['InputWidgets']:
            tactic_widget_name = tw.get_widget_name(widget_dict['class_name'], 'input')

            widget_dict['sobject'] = result_dict['EditWdg'].get('sobject')
            widget_dict['parent_sobject'] = result_dict['EditWdg'].get('parent_sobject')

            if not tactic_widget_name:
                tactic_widget_name = 'TacticCurrentCheckboxWdg'

            tactic_widget = getattr(tw, tactic_widget_name)
            qt_widget = getattr(twc, 'Q{0}'.format(tactic_widget_name))

            widget_dict['stype'] = self.stype

            tactic_widget_instance = tactic_widget(options_dict=widget_dict)
            qt_widget_instance = qt_widget(tactic_widget=tactic_widget_instance, parent=self.edit_window)

            input_widgets_list.append(qt_widget_instance)

        self.grid_layout = QtGui.QGridLayout(self)
        self.grid_layout.addWidget(self.edit_window)
        self.setSizeGripEnabled(True)
        self.set_title()

        self.readSettings()
示例#12
0
    def __init__(self,
                 stype,
                 parent_stype=None,
                 item=None,
                 view='insert',
                 search_key=None,
                 parent=None):
        super(self.__class__, self).__init__(parent=parent)

        # TODO get title from within
        self.settings = QtCore.QSettings(
            '{0}/settings/{1}/{2}/{3}/main_ui_config.ini'.format(
                env_mode.get_current_path(), env_mode.get_node(),
                env_server.get_cur_srv_preset(), env_mode.get_mode()),
            QtCore.QSettings.IniFormat)

        self.item = item
        self.stype = stype
        self.parent_stype = parent_stype
        self.search_type = self.stype.info.get('code')

        self.view = view

        self.search_key = search_key
        self.parent_search_key = None

        if self.item:
            if not search_key:
                self.search_key = self.item.get_search_key()
            self.parent_search_key = self.item.get_parent_search_key()

        kwargs_edit = {
            'args': {
                'input_prefix': 'edit',
                'search_key': self.search_key,
                'parent_key': self.parent_search_key,
                'view': 'edit',
            },
            'search_type': self.search_type,
        }

        kwargs_insert = {
            'args': {
                'mode': 'insert',
                'input_prefix': 'insert',
                'parent_key': self.parent_search_key,
                'search_type': self.search_type,
                'view': 'insert',
            },
            'search_type': self.search_type,
        }

        if self.view == 'edit':
            kwargs = kwargs_edit
        else:
            kwargs = kwargs_insert

        code = tq.prepare_serverside_script(tq.query_EditWdg,
                                            kwargs,
                                            return_dict=True)
        # print code['code']
        result = tc.server_start().execute_python_script('', kwargs=code)
        result_dict = json.loads(result['info']['spt_ret_val'])

        input_widgets_list = []
        if self.item:
            result_dict['EditWdg']['sobject'] = self.item.get_sobject()
            result_dict['EditWdg'][
                'parent_sobject'] = self.item.get_parent_sobject()

        tactic_edit_widget = tw.TacticEditWdg(result_dict['EditWdg'])

        self.edit_window = twc.QtTacticEditWidget(
            tactic_widget=tactic_edit_widget,
            qt_widgets=input_widgets_list,
            stype=self.stype,
            parent=self)

        for widget_dict in result_dict['InputWidgets']:
            tactic_widget_name = tw.get_widget_name(widget_dict['class_name'],
                                                    'input')

            widget_dict['sobject'] = result_dict['EditWdg'].get('sobject')
            widget_dict['parent_sobject'] = result_dict['EditWdg'].get(
                'parent_sobject')

            if not tactic_widget_name:
                tactic_widget_name = 'TacticCurrentCheckboxWdg'

            tactic_widget = getattr(tw, tactic_widget_name)
            qt_widget = getattr(twc, 'Q{0}'.format(tactic_widget_name))

            widget_dict['stype'] = self.stype

            tactic_widget_instance = tactic_widget(options_dict=widget_dict)
            qt_widget_instance = qt_widget(
                tactic_widget=tactic_widget_instance, parent=self.edit_window)

            input_widgets_list.append(qt_widget_instance)

        self.grid_layout = QtGui.QGridLayout(self)
        self.grid_layout.addWidget(self.edit_window)
        self.setSizeGripEnabled(True)
        self.set_title()
示例#13
0
 def commit(self, data):
     # TODO make with threads
     if self.view == 'edit':
         return tc.server_start().update(self.get_search_key(), data)
     else:
         return tc.server_start().insert(self.get_search_type(), data, parent_key=self.get_parent_search_key())