def add_note(self, creator_id, note_text, score=0, image_data=None): _note = Note.create(entity_id=self.entity_id, creator_id=creator_id, note_text=note_text, score=score, image_data=image_data) _note_info = self.__load_note_info_from_cache() if _note_info != None: _note_info['note_count'] += 1 _note_info['note_id_list'].append(_note.note_id) self.__reset_note_info_to_cache(_note_info) _creator = User(creator_id) _creator.update_user_entity_note_count(delta=1) _basic_info = self.__read_basic_info() if _basic_info.has_key('creator_id') and _basic_info[ 'creator_id'] != None and _basic_info['creator_id'] != int( creator_id): CreateEntityNoteMessageTask.delay( user_id=_basic_info['creator_id'], user_unread_message_count=User( _basic_info['creator_id']).get_unread_message_count(), entity_id=self.entity_id, note_id=_note.note_id, ) return _note
def addNewNote(self): name = input("Name your note or press Enter\n") if not name: for entry in self.notes: if "Note" in entry.name and re.search(r'\d', entry.name): reg = re.compile("[^0-9]") last_id = int(reg.sub('', entry.name)) if last_id > self.note_id: self.note_id = last_id self.note_id += 1 name = f"Note{self.note_id}" else: # To avoid invalid input reg = re.compile("[^a-zA-Z][^0-9]") name = reg.sub('', name) tags = input("Add some tags or press enter\n") note = Note(self.note_id, name, tags.split()) try: print("\033[37;1m") # white text note.create() except FileExistsError: print(f"Note '{name}' already exists")
def test_notes(notes_list): # print("Frequency C0: ", Note._freq_note_0()) assert Note._freq_note_0() == 440 * 2**(3 / 12) / 2**6 octave_offset = 1 # offset from numeric octave to notation for note_i in notes_list: freq = note_i['freq'] note = note_i['note_name'] octv = note_i['octave'] errv = note_i['error'] name = str(note).split('.')[-1] + str(octv) str_expected = name if errv: str_expected += " %+d cent" % errv str_expected += " %.3f Hz" % freq # print("expected: ", str_expected) ref1 = Note(freq) note_num = note + (octv + octave_offset) * 12 + errv / 100 ref2 = Note.create(note_num) for ref in (ref1, ref2): # print(ref) assert round(ref.num) == note + 12 * (octv + octave_offset) assert int(ref.octave) == octv + octave_offset assert ref.name == name, str_expected assert repr(ref) == str_expected
def _test_notification(self): sobject = SearchType.create("sthpw/notification") sobject.set_value('subject', 'TACTIC Unittest 001: a new item has been added.') sobject.set_value("event",'insert|unittest/country') sobject.commit() sobject = SearchType.create("sthpw/notification") sobject.set_value('subject', 'TACTIC Unittest 002: an item has been updated.') sobject.set_value("event",'update|unittest/country') sobject.commit() sobject = SearchType.create("sthpw/notification") sobject.set_value('subject', 'TACTIC Unittest 003: New notes added.') sobject.set_value("event",'insert|sthpw/note') sobject.commit() sobject = SearchType.create("sthpw/notification") sobject.set_value('subject', 'TACTIC Unittest 004: New task assigned.') sobject.set_value("event",'change|sthpw/task|status') sobject.commit() sobject = SearchType.create("sthpw/notification") sobject.set_value('subject', 'TACTIC Unittest 005: task status has been changed.') sobject.set_value("event",'change|sthpw/task|assigned') sobject.commit() sobject = SearchType.create("sthpw/notification") sobject.set_value('subject', 'TACTIC Unittest 006: Files are checked in.') sobject.set_value("event",'checkin|unittest/country') sobject.commit() # Item added self.clear_notification() sobject1 = SearchType.create("unittest/country") sobject1.set_value('code', 'test_update_trigger') sobject1.commit() # Updated item sobject1.set_value('code','success') sobject1.commit() # Note added Note.create(self.person, "test note2", context='default2') # Task assigned sobject = Task.create(self.person,'hi','hellotest',assigned="test assigned") # Task status changed tasks = Task.get_by_sobject(self.person) tasks[0].set_value('process','success') tasks[0].commit() # Files are checked in file_path = "./notification_test_check.txt" for i in range(0,4): file = open(file_path, 'w') file.write("whatever") file.close() checkin = FileCheckin(sobject1, file_path, "main", context='test', checkin_type='auto') checkin.execute() Trigger.call_all_triggers() if os.path.exists(file_path): os.remove(file_path)
def _test_schema(my): # prod type test prod_proj_code = "sample3d" if Project.get_by_code(prod_proj_code): prod_schema = Schema.get_by_project_code(prod_proj_code) parent_type = prod_schema.get_parent_type('prod/asset') my.assertEquals('prod/asset_library', parent_type) parent_type = prod_schema.get_parent_type('prod/sequence') my.assertEquals('prod/episode', parent_type) parent_type = prod_schema.get_parent_type('prod/shot') my.assertEquals('prod/sequence', parent_type) parent_type = prod_schema.get_parent_type('sthpw/task') my.assertEquals('*', parent_type) parent_type = prod_schema.get_parent_type('sthpw/note') my.assertEquals('*', parent_type) parent_type = prod_schema.get_parent_type('prod/render') my.assertEquals('*', parent_type) parent_type = prod_schema.get_parent_type('prod/submission') my.assertEquals('*', parent_type) schema = Schema.get_by_project_code("unittest") # create a new search_type schema.add_search_type("unittest/car", parent_type='unittest/person', commit=False) schema.add_search_type("unittest/house", parent_type='unittest/person', commit=False) parent_type = schema.get_parent_type('unittest/city') my.assertEquals('unittest/country', parent_type) # get all of the child types child_types = schema.get_child_types('unittest/person') #print "CHILD TYPES ", child_types expected = ['unittest/person_in_car', 'unittest/house'] my.assertEquals(True, expected[0] in child_types) my.assertEquals(True, expected[1] in child_types) # create a new schema that has the unittest as the parent new_schema = SearchType.create(Schema.SEARCH_TYPE) new_schema.set_value("code", "unittest/custom") new_schema_xml = ''' <schema parent='unittest'> <search_type name='unittest/account'/> <connect from='unittest/person' to='unittest/account' type='hierarchy'/> <connect from='*' to='unittest/poof' type='hierarchy'/> </schema> ''' new_schema.set_xml(new_schema_xml) # get search_types defined in this schema search_types = new_schema.get_search_types(hierarchy=False) my.assertEquals(1, len(search_types) ) # get all search_types search_types = new_schema.get_search_types() # add bunch of dummy initial tasks to the person initial_tasks = Task.add_initial_tasks(my.person, 'task') # check status_log static trigger single_task = initial_tasks[0] from pyasm.search import Search to_status = Search.eval('@GET(sthpw/status_log.to_status)', sobjects=[single_task], single=True) my.assertEquals(to_status, "Assignment") single_task.set_value('status', "Test Done") single_task.commit(triggers=True) ExpressionParser.clear_cache() to_status = Search.eval("@GET(sthpw/status_log['@ORDER_BY','id desc'].to_status)", sobjects=[single_task], single=True) my.assertEquals(to_status, "Test Done") # get tasks with get_all_children() tasks = my.person.get_all_children("sthpw/task") my.assertEquals(len(initial_tasks), len(tasks) ) # get notes with get_all_children() Note.create(my.person, "test note", context='default') Note.create(my.person, "test note2", context='default2') notes = my.person.get_all_children("sthpw/note") my.assertEquals(2, len(notes) ) #relationship schema = Schema.get() if Project.get_by_code('sample3d'): relationship = schema.get_relationship('prod/asset','sthpw/snapshot') my.assertEquals(relationship, 'search_code') #my.assertEquals(relationship, 'search_type') relationship = schema.get_relationship('prod/asset','sthpw/task') my.assertEquals(relationship, 'search_code') #my.assertEquals(relationship, 'search_type') relationship = schema.get_relationship('prod/shot','sthpw/note') my.assertEquals(relationship, 'search_code') #my.assertEquals(relationship, 'search_type') relationship = schema.get_relationship('sthpw/file','sthpw/snapshot') my.assertEquals(relationship, 'code') relationship = schema.get_relationship('sthpw/project_type','sthpw/project') my.assertEquals(relationship, 'code') relationship = schema.get_relationship('unittest/car','unittest/house') my.assertEquals(relationship, None) # test parent filter search in sample3d if Project.get_by_code('sample3d'): from pyasm.prod.biz import * Project.set_project('sample3d') shot = Shot.get_by_code('RC_001_001') if not shot: shot = Shot.create('RC_001_001', 'Some test shot') asset = SearchType.create('prod/asset') asset.set_value('code','unittest010') asset.set_value('name','unittest010') asset.commit() for x in xrange(3): ShotInstance.create(shot, asset, 'unittest_veh_001', unique=False) instances = ShotInstance.get_by_shot_and_asset(shot, asset) parent_type = 'prod/shot' parent_search = Search(parent_type) parent_search.add_filter('code','RC_001_001') search = Search('prod/shot_instance') search.add_filter('asset_code', asset.get_code()) # we want the base here sobject_type = search.get_search_type_obj().get_base_key() schema = Schema.get() relationship = schema.get_relationship(sobject_type, parent_type) parents = parent_search.get_sobjects() if parents: if relationship in ["code", "id", "search_type"]: search.add_relationship_filters(parents) sobjects = search.get_sobjects() my.assertEquals(len(instances), len(sobjects)) relationship_attrs = schema.get_relationship_attrs('sthpw/transaction_log','sthpw/sobject_log') rev_relationship_attrs = schema.get_relationship_attrs('sthpw/sobject_log','sthpw/transaction_log') for attrs in [ relationship_attrs, rev_relationship_attrs]: my.assertEquals(attrs.get('from_col'), 'transaction_log_id') my.assertEquals(attrs.get('to_col'), 'id') my.assertEquals(attrs.get('from'), 'sthpw/sobject_log') my.assertEquals(attrs.get('to'), 'sthpw/transaction_log') my.assertEquals(attrs.get('relationship'), 'id') my.assertEquals(attrs.get('disabled'), None) Project.set_project('unittest')
def _test_schema(my): # prod type test prod_proj_code = "sample3d" if Project.get_by_code(prod_proj_code): prod_schema = Schema.get_by_project_code(prod_proj_code) parent_type = prod_schema.get_parent_type('prod/asset') my.assertEquals('prod/asset_library', parent_type) parent_type = prod_schema.get_parent_type('prod/sequence') my.assertEquals('prod/episode', parent_type) parent_type = prod_schema.get_parent_type('prod/shot') my.assertEquals('prod/sequence', parent_type) parent_type = prod_schema.get_parent_type('sthpw/task') my.assertEquals('*', parent_type) parent_type = prod_schema.get_parent_type('sthpw/note') my.assertEquals('*', parent_type) parent_type = prod_schema.get_parent_type('prod/render') my.assertEquals('*', parent_type) parent_type = prod_schema.get_parent_type('prod/submission') my.assertEquals('*', parent_type) schema = Schema.get_by_project_code("unittest") # create a new search_type schema.add_search_type("unittest/car", parent_type='unittest/person', commit=False) schema.add_search_type("unittest/house", parent_type='unittest/person', commit=False) parent_type = schema.get_parent_type('unittest/city') my.assertEquals('unittest/country', parent_type) # get all of the child types child_types = schema.get_child_types('unittest/person') expected = ['unittest/person_in_car', 'unittest/house'] my.assertEquals(True, expected[0] in child_types) my.assertEquals(True, expected[1] in child_types) # create a new schema that has the unittest as the parent new_schema = SearchType.create(Schema.SEARCH_TYPE) new_schema.set_value("code", "unittest/custom") new_schema_xml = ''' <schema parent='unittest'> <search_type name='unittest/account'/> <connect from='unittest/person' to='unittest/account' type='hierarchy'/> <connect from='*' to='unittest/poof' type='hierarchy'/> </schema> ''' new_schema.set_xml(new_schema_xml) # get search_types defined in this schema search_types = new_schema.get_search_types(hierarchy=False) my.assertEquals(1, len(search_types)) # get all search_types search_types = new_schema.get_search_types() # add bunch of dummy initial tasks to the person initial_tasks = Task.add_initial_tasks(my.person, 'task') # check status_log static trigger single_task = initial_tasks[0] from pyasm.search import Search to_status = Search.eval('@GET(sthpw/status_log.to_status)', sobjects=[single_task], single=True) my.assertEquals(to_status, "Assignment") single_task.set_value('status', "Test Done") single_task.commit(triggers=True) ExpressionParser.clear_cache() to_status = Search.eval( "@GET(sthpw/status_log['@ORDER_BY','id desc'].to_status)", sobjects=[single_task], single=True) my.assertEquals(to_status, "Test Done") # get tasks with get_all_children() tasks = my.person.get_all_children("sthpw/task") my.assertEquals(len(initial_tasks), len(tasks)) # get notes with get_all_children() Note.create(my.person, "test note", context='default') Note.create(my.person, "test note2", context='default2') notes = my.person.get_all_children("sthpw/note") my.assertEquals(2, len(notes)) #relationship schema = Schema.get() if Project.get_by_code('sample3d'): relationship = schema.get_relationship('prod/asset', 'sthpw/snapshot') my.assertEquals(relationship, 'search_code') #my.assertEquals(relationship, 'search_type') relationship = schema.get_relationship('prod/asset', 'sthpw/task') my.assertEquals(relationship, 'search_code') #my.assertEquals(relationship, 'search_type') relationship = schema.get_relationship('prod/shot', 'sthpw/note') my.assertEquals(relationship, 'search_code') #my.assertEquals(relationship, 'search_type') relationship = schema.get_relationship('sthpw/file', 'sthpw/snapshot') my.assertEquals(relationship, 'code') relationship = schema.get_relationship('sthpw/project_type', 'sthpw/project') my.assertEquals(relationship, 'code') relationship = schema.get_relationship('unittest/car', 'unittest/house') my.assertEquals(relationship, None) # test parent filter search in sample3d if Project.get_by_code('sample3d'): from pyasm.prod.biz import * Project.set_project('sample3d') shot = Shot.get_by_code('RC_001_001') if not shot: shot = Shot.create('RC_001_001', 'Some test shot') asset = SearchType.create('prod/asset') asset.set_value('code', 'unittest010') asset.set_value('name', 'unittest010') asset.commit() for x in xrange(3): ShotInstance.create(shot, asset, 'unittest_veh_001', unique=False) instances = ShotInstance.get_by_shot_and_asset(shot, asset) parent_type = 'prod/shot' parent_search = Search(parent_type) parent_search.add_filter('code', 'RC_001_001') search = Search('prod/shot_instance') search.add_filter('asset_code', asset.get_code()) # we want the base here sobject_type = search.get_search_type_obj().get_base_key() schema = Schema.get() relationship = schema.get_relationship(sobject_type, parent_type) parents = parent_search.get_sobjects() if parents: if relationship in ["code", "id", "search_type"]: search.add_relationship_filters(parents) sobjects = search.get_sobjects() my.assertEquals(len(instances), len(sobjects)) relationship_attrs = schema.get_relationship_attrs( 'sthpw/transaction_log', 'sthpw/sobject_log') rev_relationship_attrs = schema.get_relationship_attrs( 'sthpw/sobject_log', 'sthpw/transaction_log') for attrs in [relationship_attrs, rev_relationship_attrs]: my.assertEquals(attrs.get('from_col'), 'transaction_log_id') my.assertEquals(attrs.get('to_col'), 'id') my.assertEquals(attrs.get('from'), 'sthpw/sobject_log') my.assertEquals(attrs.get('to'), 'sthpw/transaction_log') my.assertEquals(attrs.get('relationship'), 'id') my.assertEquals(attrs.get('disabled'), None) Project.set_project('unittest')
def _test_notification(my): sobject = SearchType.create("sthpw/notification") sobject.set_value('subject', 'TACTIC Unittest 001: a new item has been added.') sobject.set_value("event", 'insert|unittest/country') sobject.commit() sobject = SearchType.create("sthpw/notification") sobject.set_value('subject', 'TACTIC Unittest 002: an item has been updated.') sobject.set_value("event", 'update|unittest/country') sobject.commit() sobject = SearchType.create("sthpw/notification") sobject.set_value('subject', 'TACTIC Unittest 003: New notes added.') sobject.set_value("event", 'insert|sthpw/note') sobject.commit() sobject = SearchType.create("sthpw/notification") sobject.set_value('subject', 'TACTIC Unittest 004: New task assigned.') sobject.set_value("event", 'change|sthpw/task|status') sobject.commit() sobject = SearchType.create("sthpw/notification") sobject.set_value( 'subject', 'TACTIC Unittest 005: task status has been changed.') sobject.set_value("event", 'change|sthpw/task|assigned') sobject.commit() sobject = SearchType.create("sthpw/notification") sobject.set_value('subject', 'TACTIC Unittest 006: Files are checked in.') sobject.set_value("event", 'checkin|unittest/country') sobject.commit() # Item added my.clear_notification() sobject1 = SearchType.create("unittest/country") sobject1.set_value('code', 'test_update_trigger') sobject1.commit() # Updated item sobject1.set_value('code', 'success') sobject1.commit() # Note added Note.create(my.person, "test note2", context='default2') # Task assigned sobject = Task.create(my.person, 'hi', 'hellotest', assigned="test assigned") # Task status changed tasks = Task.get_by_sobject(my.person) tasks[0].set_value('process', 'success') tasks[0].commit() # Files are checked in file_path = "./notification_test_check.txt" for i in range(0, 4): file = open(file_path, 'w') file.write("whatever") file.close() checkin = FileCheckin(sobject1, file_path, "main", context='test', checkin_type='auto') checkin.execute() Trigger.call_all_triggers() if os.path.exists(file_path): os.remove(file_path)
def on_click_new_note(self, item): n = Note.create(self.catalogue.get_new_title()) self.catalogue.append(n) e = Editor(n, self.catalogue) e.show_all()