Skip to content

Commit

Permalink
Merge pull request #10 from andres-morenogr/fix/detail-pictures
Browse files Browse the repository at this point in the history
Fixing item details pictures array
  • Loading branch information
andres-morenogr authored Dec 5, 2020
2 parents 8af6ea3 + 67fb067 commit 48a2104
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ def get_city_code(string):
city_code = string.split('code')[1].split(", ")[1]
city_code = re.sub(r'[^\w\s]','', city_code)
return city_code

def get_pictures(pictures):
pictures_list = pictures.split("'")
for item in pictures_list:
if len(item) < 3: pictures_list.remove(item)
return(pictures_list)
4 changes: 2 additions & 2 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework.response import Response
from .serializers import ItemSerializer, SellerSerializer
from .models import Item, Seller
from .utilities import get_city_name, get_city_code
from .utilities import get_city_name, get_city_code, get_pictures


class SearchResponse(object):
Expand Down Expand Up @@ -74,7 +74,7 @@ def retrieve(self, request, pk):
"name": item["name"],
"brand": item["brand"],
"thumbnail": item["thumbnail"],
"pictures": item["pictures"],
"pictures": get_pictures(item["pictures"]),
"city": {"name": get_city_name(item["city"]),
"code": get_city_code(item["city"])},
"seller": seller,
Expand Down

0 comments on commit 48a2104

Please sign in to comment.