File tree Expand file tree Collapse file tree 4 files changed +16
-5
lines changed Expand file tree Collapse file tree 4 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -129,8 +129,8 @@ def check_exists(cls, **kwargs):
129
129
result = cls .query .filter_by (** kwargs ).count ()
130
130
131
131
if result > 0 :
132
- return False
133
- return True
132
+ return True
133
+ return False
134
134
135
135
@classmethod
136
136
def get_by_id (cls , id ):
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ def __repr__(self):
21
21
return f"<Tag { self .name } >"
22
22
23
23
24
+
24
25
class ProjectTag (ModelMixin ):
25
26
__tablename__ = "project_tag"
26
27
Original file line number Diff line number Diff line change 6
6
from app .models .project_users import ProjectFollowers
7
7
8
8
9
-
10
9
class ProjectListSchema (Schema ):
11
10
id = fields .UUID (dump_only = True )
12
11
name = fields .String ()
@@ -69,7 +68,6 @@ class ProjectSchema(Schema):
69
68
tags_remove = fields .List (fields .String , load_only = True )
70
69
71
70
def get_is_following (self , obj ):
72
- # Assuming current_user is available in the view context
73
71
current_user_id = get_jwt_identity ()
74
72
current_user = User .get_by_id (current_user_id )
75
73
return obj .is_followed_by (current_user )
@@ -84,4 +82,4 @@ def get_prometheus_url(self, obj):
84
82
return obj .cluster .prometheus_url
85
83
86
84
def get_followers_count (self , obj ):
87
- return ProjectFollowers .count (project_id = obj .id )
85
+ return ProjectFollowers .count (project_id = obj .id )
Original file line number Diff line number Diff line change 1
1
from app .schemas .project import ProjectIndexSchema
2
2
from app .schemas .project_users import UserRoleSchema
3
3
from marshmallow import Schema , fields
4
+ from flask_jwt_extended import get_jwt_identity
5
+ from app .models .user import User
6
+ from app .models .tags import TagFollowers
7
+
8
+
4
9
class TagListSchema (Schema ):
5
10
id = fields .UUID (dump_only = True )
6
11
name = fields .String (required = True )
7
12
is_super_tag = fields .Boolean ()
8
13
14
+
9
15
class TagSchema (Schema ):
10
16
11
17
id = fields .UUID (dump_only = True )
12
18
name = fields .String (required = True )
13
19
is_super_tag = fields .Boolean ()
14
20
date_created = fields .Date (dump_only = True )
15
21
projects_count = fields .Method ("get_projects_count" , dump_only = True )
22
+ is_following = fields .Method ("get_is_following" , dump_only = True )
16
23
17
24
def get_projects_count (self , obj ):
18
25
return len (obj .projects )
19
26
27
+ def get_is_following (self , obj ):
28
+ current_user_id = get_jwt_identity ()
29
+ tag_id = obj .id
30
+ return TagFollowers .check_exists (user_id = current_user_id , tag_id = tag_id )
31
+
20
32
21
33
class TagsProjectsSchema (TagSchema ):
22
34
name = fields .Method ("get_name" , dump_only = True )
You can’t perform that action at this time.
0 commit comments