diff --git a/ubottu/bugtracker/views.py b/ubottu/bugtracker/views.py index aeb4afe..ba4b2d1 100644 --- a/ubottu/bugtracker/views.py +++ b/ubottu/bugtracker/views.py @@ -9,8 +9,7 @@ from geopy.geocoders import Nominatim from timezonefinder import TimezoneFinder from datetime import datetime from rest_framework import status -#from launchpadlib.launchpad import Launchpad -from .launchpad_singleton import get_launchpad +from launchpad.launchpad_singleton import get_launchpad import pytz import json import requests diff --git a/ubottu/factoids/serializers.py b/ubottu/factoids/serializers.py index 9c72538..9243d41 100644 --- a/ubottu/factoids/serializers.py +++ b/ubottu/factoids/serializers.py @@ -7,9 +7,10 @@ from launchpad.utils import fetch_group_members class FactSerializer(serializers.ModelSerializer): author_name = serializers.SerializerMethodField() value = serializers.SerializerMethodField() + user_ids = serializers.SerializerMethodField() class Meta: model = Fact - fields = ['id', 'name', 'value', 'ftype', 'author_name', 'create_date', 'change_date', 'popularity'] + fields = ['id', 'name', 'user_ids', 'value', 'ftype', 'author_name', 'create_date', 'change_date', 'popularity'] def get_author_name(self, obj): # Assuming the author field can be null @@ -18,15 +19,32 @@ class FactSerializer(serializers.ModelSerializer): def get_value(self, obj): value = obj.value # The original text with placeholders launchpad_group_pattern = r'\{launchpad_group\.([^}]+)\}' - matches = re.findall(launchpad_group_pattern, value) + matches = re.findall(launchpad_group_pattern, obj.value) if not matches: return value group_name = matches[0] + if group_name.endswith('.mentions'): + return value.replace('{launchpad_group.' + group_name + '}', '') members = fetch_group_members(group_name) - if members is None: + if not isinstance(members, dict): return value if 'mxids' in members: - return value.replace( '{launchpad_group.' + group_name + '}', 'https://matrix.to/#/' + ' https://matrix.to/#/'.join(members['mxids'])) + return value.replace( '{launchpad_group.' + group_name + '}', ' '.join(members['mxids'])) + return False + - return value + def get_user_ids(self, obj): + value = obj.value.replace('.mentions', '') + launchpad_group_pattern = r'\{launchpad_group\.([^}]+)\}' + matches = re.findall(launchpad_group_pattern, value) + if not matches: + return {} + group_name = matches[0] + members = fetch_group_members(group_name) + if not members: + return {} + if 'mxids' in members: + return members['mxids'] + + return {} diff --git a/ubottu/bugtracker/launchpad_singleton.py b/ubottu/launchpad/launchpad_singleton.py similarity index 100% rename from ubottu/bugtracker/launchpad_singleton.py rename to ubottu/launchpad/launchpad_singleton.py diff --git a/ubottu/launchpad/views.py b/ubottu/launchpad/views.py index f45b501..6272393 100644 --- a/ubottu/launchpad/views.py +++ b/ubottu/launchpad/views.py @@ -7,7 +7,7 @@ from django.utils.decorators import method_decorator from django.views.decorators.cache import cache_page from datetime import datetime from rest_framework import status -from bugtracker.launchpad_singleton import get_launchpad +from .launchpad_singleton import get_launchpad from .utils import fetch_group_members # Adjust the import path as necessary import pytz import json