예제 #1
0
 def tag(self, _id):
     query = QtSql.QSqlQuery(\
         "select name from tags where _id=%d" % (_id, ))
     query.first()
     tag = Tag(query.value(0), "dummy_id")
     tag._id = _id
     return tag
예제 #2
0
 def tag(self, _id):
     query = QtSql.QSqlQuery(\
         "select name from tags where _id=%d" % (_id, ))
     query.first()
     tag = Tag(unicode(query.value(0).toString()), "dummy_id")
     tag._id = _id
     return tag
예제 #3
0
 def tag_from_log_entry(self, log_entry):
     # When deleting, the log entry only contains the tag's id, so we pull
     # the object from the database. This is a bit slower than just filling
     # in harmless missing keys, but it is more robust against future
     # side effects of tag deletion.
     if log_entry["type"] == EventTypes.DELETED_TAG:
         # Work around legacy logs which contain duplicate deletion events.
         if self.has_tag_with_id(log_entry["o_id"]):
             return self.tag(log_entry["o_id"], is_id_internal=False)
         else:
             # Leftover from old bug, should not reoccur.
             self.main_widget().show_information(\
         _("Deleting same tag twice during sync. Inform the developpers."))
             log_entry["name"] = "irrelevant"
             return Tag(log_entry["name"], log_entry["o_id"])
     # If we are creating a tag that will be deleted at a later stage
     # during this sync, we are missing some (irrelevant) information
     # needed to properly create a tag object.
     if "name" not in log_entry:
         log_entry["name"] = "irrelevant"
     # Create tag object.
     tag = Tag(log_entry["name"], log_entry["o_id"])
     if "extra" in log_entry:
         tag.extra_data = eval(log_entry["extra"])
     # Make sure to create _id fields as well, otherwise database
     # operations or their side effects could fail.
     if log_entry["type"] != EventTypes.ADDED_TAG:
         tag._id = self.con.execute("select _id from tags where id=?",
                                    (tag.id, )).fetchone()[0]
     return tag
예제 #4
0
 def test_tag_order(self):
     tag = Tag("a")
     self.database().add_tag(tag)
     tag = Tag("1. a")
     self.database().add_tag(tag)
     assert [tag.name for tag in self.database().tags()
             ] == ["1. a", "a", "__UNTAGGED__"]
예제 #5
0
 def test_tags(self):
     cat = Tag("test")
     self.database().add_tag(cat)
     assert self.database().get_tag_names() == [u"test"]
     cat.name = "test2"
     self.database().update_tag(cat)
     assert self.database().get_tag_names() == [u"test2"]        
예제 #6
0
 def tag_from_log_entry(self, log_entry):
     # When deleting, the log entry only contains the tag's id, so we pull
     # the object from the database. This is a bit slower than just filling
     # in harmless missing keys, but it is more robust against future
     # side effects of tag deletion.
     if log_entry["type"] == EventTypes.DELETED_TAG:           
         # Work around legacy logs which contain duplicate deletion events.
         if self.has_tag_with_id(log_entry["o_id"]):
             return self.tag(log_entry["o_id"], is_id_internal=False)
         else:
             # Leftover from old bug, should not reoccur.
             self.main_widget().show_information(\
         _("Deleting same tag twice during sync. Inform the developpers."))
             log_entry["name"] = "irrelevant"
             return Tag(log_entry["name"], log_entry["o_id"])                
     # If we are creating a tag that will be deleted at a later stage
     # during this sync, we are missing some (irrelevant) information
     # needed to properly create a tag object.
     if "name" not in log_entry:
         log_entry["name"] = "irrelevant"
     # Create tag object.
     tag = Tag(log_entry["name"], log_entry["o_id"])
     if "extra" in log_entry:
         tag.extra_data = eval(log_entry["extra"])
     # Make sure to create _id fields as well, otherwise database
     # operations or their side effects could fail.
     if log_entry["type"] != EventTypes.ADDED_TAG:
         tag._id = self.con.execute("select _id from tags where id=?",
             (tag.id, )).fetchone()[0]
     return tag
예제 #7
0
 def test_tags(self):
     tag = Tag("test")
     self.database().add_tag(tag)
     assert len(self.database().tags()) == 2
     assert self.database().tags()[0].name == u"test"
     tag.name = "test2"
     self.database().update_tag(tag)
     assert len(self.database().tags()) == 2
     assert self.database().tags()[0].name == u"test2"
예제 #8
0
 def test_tags(self):
     tag = Tag("test")
     self.database().add_tag(tag)
     assert len(self.database().tags()) == 2
     assert self.database().tags()[0].name == "test"
     tag.name = "test2"
     self.database().update_tag(tag)
     assert len(self.database().tags()) == 2
     assert self.database().tags()[0].name == "test2"
예제 #9
0
파일: SQLite.py 프로젝트: bartosh/pomni
 def get_tag(self, id, id_is_internal):
     if id_is_internal:
         sql_res = self.con.execute("select * from tags where _id=?",
                                    (id, )).fetchone()
     else:
         sql_res = self.con.execute("select * from tags where id=?",
                                    (id, )).fetchone()            
     tag = Tag(sql_res["name"], sql_res["id"])
     tag._id = sql_res["_id"]
     self._get_extra_data(sql_res, tag)
     return tag
예제 #10
0
파일: SQLite.py 프로젝트: bartosh/pomni
 def get_or_create_tag_with_name(self, name):
     sql_res = self.con.execute("""select * from tags where name=?""",
                                (name, )).fetchone()
     if sql_res:
         tag = Tag(sql_res["name"], sql_res["id"])
         tag._id = sql_res["_id"]
         self._get_extra_data(sql_res, tag)
     else:
         tag = Tag(name)
         self.add_tag(tag)
     return tag
예제 #11
0
파일: SQLite.py 프로젝트: umax/pomni
 def get_tag(self, id, id_is_internal):
     if id_is_internal:
         sql_res = self.con.execute("select * from tags where _id=?",
                                    (id, )).fetchone()
     else:
         sql_res = self.con.execute("select * from tags where id=?",
                                    (id, )).fetchone()            
     if not sql_res:
         return None
     tag = Tag(sql_res["name"], sql_res["id"])
     tag._id = sql_res["_id"]
     return tag
예제 #12
0
 def tag_from_log_entry(self, log_entry):
     # When deleting, the log entry only contains the tag's id, so we pull
     # the object from the database. This is a bit slower than just filling
     # in harmless missing fields, but it is more robust against future
     # side effects of tag deletion.
     if log_entry["type"] == EventTypes.DELETED_TAG:
         return self.get_tag(log_entry["o_id"], id_is_internal=False)
     # If we are creating a tag that will be deleted at a later stage
     # during this sync, we are missing some (irrelevant) information
     # needed to properly create a tag object.
     if "name" not in log_entry:
         log_entry["name"] = "irrelevant"
     # Create tag object. 
     tag = Tag(log_entry["name"], log_entry["o_id"])
     if "extra" in log_entry:
         tag.extra_data = eval(log_entry["extra"])
     # Make sure to create _id fields as well, otherwise database
     # operations or their side effects could fail.
     if log_entry["type"] != EventTypes.ADDED_TAG:
         tag._id = self.con.execute("select _id from tags where id=?",
             (tag.id, )).fetchone()[0]
     return tag