Skip to content

Commit

Permalink
Merge pull request #118 from dglemos/clean_comments
Browse files Browse the repository at this point in the history
Remove newline from comments
  • Loading branch information
seeta-ramaraju authored Mar 5, 2025
2 parents f9c5374 + 0894842 commit 957b28e
Showing 1 changed file with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@
from django.db import connection, IntegrityError
from django.db.models import Prefetch
import itertools

from ..models import (Panel, Attrib,
LGDPanel, LocusGenotypeDisease, LGDVariantGenccConsequence,
LGDCrossCuttingModifier, LGDPublication,
LGDPhenotype, LGDVariantType, Locus,
LGDComment, LGDVariantTypeComment, User,
LGDMolecularMechanismEvidence, CVMolecularMechanism,
OntologyTerm, Publication, LGDPhenotypeSummary,
LGDVariantTypeDescription, LGDMolecularMechanismSynopsis)

import re

from ..models import (
Panel,
Attrib,
LGDPanel,
LocusGenotypeDisease,
LGDVariantGenccConsequence,
LGDCrossCuttingModifier,
LGDPublication,
LGDPhenotype,
LGDVariantType,
Locus,
LGDComment,
LGDVariantTypeComment,
User,
LGDMolecularMechanismEvidence,
CVMolecularMechanism,
OntologyTerm,
Publication,
LGDPhenotypeSummary,
LGDVariantTypeDescription,
LGDMolecularMechanismSynopsis
)

from .publication import LGDPublicationSerializer
from .locus import LocusSerializer
Expand Down Expand Up @@ -296,9 +310,11 @@ def get_comments(self, id):
if comment.date is not None:
date = comment.date.strftime("%Y-%m-%d")

text = { 'text': comment.comment,
'date': date,
'is_public': comment.is_public }
text = {
'text': comment.comment,
'date': date,
'is_public': comment.is_public
}

# authenticated users can have access to the user name
if authenticated_user == 1:
Expand Down Expand Up @@ -410,7 +426,9 @@ def create(self, data, disease_obj, publications_list):
mechanism_support_obj = data.get('mechanism_support')

if not panels or not publications_list:
raise serializers.ValidationError({"message": f"Missing data to create the G2P record {stable_id_obj.stable_id}"})
raise serializers.ValidationError(
{"message": f"Missing data to create the G2P record {stable_id_obj.stable_id}"}
)

# Check if record (LGD) is already inserted
try:
Expand Down Expand Up @@ -757,11 +775,16 @@ def create(self, data):
lgd = self.context["lgd"]
user = self.context["user"]

# Remove newlines from comment
comment = re.sub(r"\n", " ", comment)

# Check if this comment is already linked to the G2P entry
lgd_comments = LGDComment.objects.filter(lgd_id=lgd, is_deleted=0, comment=comment)

if lgd_comments:
raise serializers.ValidationError({"message": f"Comment is already associated with {lgd.stable_id.stable_id}"})
raise serializers.ValidationError(
{"message": f"Comment is already associated with {lgd.stable_id.stable_id}"}
)

else:
try:
Expand Down

0 comments on commit 957b28e

Please sign in to comment.