bug fixes
This commit is contained in:
parent
42b030e9b1
commit
1784b0343e
4 changed files with 25 additions and 8 deletions
|
@ -9,8 +9,7 @@ from geopy.geocoders import Nominatim
|
||||||
from timezonefinder import TimezoneFinder
|
from timezonefinder import TimezoneFinder
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
#from launchpadlib.launchpad import Launchpad
|
from launchpad.launchpad_singleton import get_launchpad
|
||||||
from .launchpad_singleton import get_launchpad
|
|
||||||
import pytz
|
import pytz
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
|
@ -7,9 +7,10 @@ from launchpad.utils import fetch_group_members
|
||||||
class FactSerializer(serializers.ModelSerializer):
|
class FactSerializer(serializers.ModelSerializer):
|
||||||
author_name = serializers.SerializerMethodField()
|
author_name = serializers.SerializerMethodField()
|
||||||
value = serializers.SerializerMethodField()
|
value = serializers.SerializerMethodField()
|
||||||
|
user_ids = serializers.SerializerMethodField()
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Fact
|
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):
|
def get_author_name(self, obj):
|
||||||
# Assuming the author field can be null
|
# Assuming the author field can be null
|
||||||
|
@ -18,15 +19,32 @@ class FactSerializer(serializers.ModelSerializer):
|
||||||
def get_value(self, obj):
|
def get_value(self, obj):
|
||||||
value = obj.value # The original text with placeholders
|
value = obj.value # The original text with placeholders
|
||||||
launchpad_group_pattern = r'\{launchpad_group\.([^}]+)\}'
|
launchpad_group_pattern = r'\{launchpad_group\.([^}]+)\}'
|
||||||
matches = re.findall(launchpad_group_pattern, value)
|
matches = re.findall(launchpad_group_pattern, obj.value)
|
||||||
if not matches:
|
if not matches:
|
||||||
return value
|
return value
|
||||||
group_name = matches[0]
|
group_name = matches[0]
|
||||||
|
if group_name.endswith('.mentions'):
|
||||||
|
return value.replace('{launchpad_group.' + group_name + '}', '')
|
||||||
members = fetch_group_members(group_name)
|
members = fetch_group_members(group_name)
|
||||||
if members is None:
|
if not isinstance(members, dict):
|
||||||
return value
|
return value
|
||||||
if 'mxids' in members:
|
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 {}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.utils.decorators import method_decorator
|
||||||
from django.views.decorators.cache import cache_page
|
from django.views.decorators.cache import cache_page
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from rest_framework import status
|
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
|
from .utils import fetch_group_members # Adjust the import path as necessary
|
||||||
import pytz
|
import pytz
|
||||||
import json
|
import json
|
||||||
|
|
Loading…
Reference in a new issue