From e512841e3dcba6490fdb73809d236f7f5f347857 Mon Sep 17 00:00:00 2001
From: Rifo Genadi <rifoagenadi@gmail.com>
Date: Fri, 26 Apr 2019 02:56:33 +0700
Subject: [PATCH] Add equal operator and fix bug in remove page from admin

---
 database/database.py |  6 ++++++
 modules/admin.py     | 10 +++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/database/database.py b/database/database.py
index 635677a..6834760 100644
--- a/database/database.py
+++ b/database/database.py
@@ -43,6 +43,12 @@ class VizData(mongo.Document):
     percentage = mongo.FloatField()
     categories = mongo.ListField(mongo.StringField(), default=[])
     detail = mongo.StringField()
+    
+    def __eq__(self, other):
+        return self.id == other.id
+
+    def __str__(self):
+        return "name : " + str(self.name) + " level : " + str(self.level) + " value : " + str(self.value) + " year : " + str(self.year) + " subdata : " + str(self.subdata)
 
 class Page(mongo.Document):
     level = mongo.IntField(required=True)
diff --git a/modules/admin.py b/modules/admin.py
index 1d1588c..e8af714 100644
--- a/modules/admin.py
+++ b/modules/admin.py
@@ -30,8 +30,16 @@ def remove_page():
     data = request.get_json()
 
     admin = db.User.objects.with_id(data.get("admin_id"))
-    admin.update(pull__page_list = db.VizData.objects.with_id(data.get("page_id")))
+    # admin.update(pull__page_list = db.VizData.objects.with_id(data.get("page_id")))    
+    page = db.VizData.objects.with_id(data.get("page_id"))
     
+    idx = -1
+    for i in range(len(admin.page_list)):
+        if (page == admin.page_list[i]):
+            idx = i
+
+    admin.page_list.pop(idx)
+    admin.save()
     return jsonify({
         "status":200,
         "message":"Page removed"
-- 
GitLab