#41 Fix tags not deleting when links are deleted

Merged
getty merged 2 commits from getty/gr/fix-deletion into getty/master 4 years ago
5 changed files with 17 additions and 4 deletions
  1. 1 1
      lc/app.py
  2. 4 0
      lc/model.py
  3. 1 0
      scripts/populate.py
  4. 1 1
      stubs/peewee.py
  5. 10 2
      tasks.py

+ 1 - 1
lc/app.py

@@ -198,7 +198,7 @@ class GetLink(Endpoint):
 
     def api_delete(self, user: str, link_id: str):
         u = self.require_authentication(user)
-        u.get_link(int(link_id)).delete_instance()
+        u.get_link(int(link_id)).full_delete()
         return self.api_ok(u.base_url())
 
     def html(self, user: str, link_id: str):

+ 4 - 0
lc/model.py

@@ -313,6 +313,10 @@ class Link(Model):
             for ht in HasTag().select(Tag.name).join(Tag).where(HasTag.link == self)
         ]
 
+    def full_delete(self):
+        self.delete_instance(recursive=True)
+        Tag.clean()
+
 
 class Tag(Model):
     """

+ 1 - 0
scripts/populate.py

@@ -8,6 +8,7 @@ import lc.request as r
 
 
 def main():
+    c.app.init_db()
     m.create_tables()
 
     u = m.User.get_or_none(name="gdritter")

+ 1 - 1
stubs/peewee.py

@@ -33,7 +33,7 @@ class Model:
     def save(self):
         pass
 
-    def delete_instance(self) -> Any:
+    def delete_instance(self, recursive: bool = False) -> Any:
         pass
 
     @classmethod

+ 10 - 2
tasks.py

@@ -65,9 +65,17 @@ def checkfmt(c):
 
 
 @task
-def populate(c):
+def populate(c, port=8080, host="127.0.0.1"):
     """Populate the test database with fake-ish data"""
-    c.run("PYTHONPATH=$(pwd) poetry run python3 ./scripts/populate.py")
+    c.run(
+        "PYTHONPATH=$(pwd) poetry run python3 ./scripts/populate.py",
+        env={
+            "FLASK_APP": "lament-configuration.py",
+            "LC_APP_PATH": f"http://{host}:{port}",
+            "LC_DB_PATH": "test.db",
+            "LC_SECRET_KEY": "TESTING_KEY",
+        },
+    )
 
 
 @task