Skip to content

Commit

Permalink
feat: dont create actionnetwork rows in test_sources as they cant be …
Browse files Browse the repository at this point in the history
…deleted
  • Loading branch information
joaquimds committed Dec 19, 2024
1 parent 83b3784 commit 3b7c3ff
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 106 deletions.
10 changes: 3 additions & 7 deletions hub/graphql/types/model_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,21 +593,17 @@ async def gss_area(self, info: Info) -> Optional[Area]:
@strawberry_django.type(models.GenericData, filters=CommonDataFilter)
class GroupedData:
label: Optional[str]
# Provide area_type if gss code is not unique (e.g. WMC and WMC23 constituencies)
area_type: Optional[str] = None
# Provide filter if gss code is not unique (e.g. WMC and WMC23 constituencies)
area_type_filter: Optional["AreaTypeFilter"] = None
gss: Optional[str]
area_data: Optional[strawberry.Private[Area]] = None
imported_data: Optional[JSON] = None
area_type_filter: Optional["AreaTypeFilter"] = None

@strawberry_django.field
async def gss_area(self, info: Info) -> Optional[Area]:
if self.area_data is not None:
return self.area_data
if self.area_type is not None:
filters = {"area_type__code": self.area_type}
else:
filters = {}
filters = self.area_type_filter.query_filter if self.area_type_filter else {}
loader = FieldDataLoaderFactory.get_loader_class(
models.Area, field="gss", filters=filters
)
Expand Down
3 changes: 2 additions & 1 deletion hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2830,7 +2830,8 @@ def get_record_id(self, record):
return record["id"]

def get_record_field(self, record, field, field_type=None):
d = record["fields"].get(str(field), None)
record_dict = record["fields"] if "fields" in record else record
d = record_dict.get(str(field), None)
if field_type == "image_field" and d is not None and len(d) > 0:
# TODO: implement image handling
# e.g. [{'id': 'attDWjeMhUfNMTqRG', 'width': 2200, 'height': 1518, 'url': 'https://v5.airtableusercontent.com/v3/u/27/27/1712044800000/CxNHcR-sBRUhrWt_54_NFA/wcYpoqFV5W_wRmVwh2RM8qs-mJkwwHkQLZuhtf7rFk5-34gILMXJeIYg9vQMcTtgSEd1dDb7lU0CrgJldTcZBN9VyaTU0IkYiw1e5PzTs8ZsOEmA6wrva7UavQCnoacL8b7yUt4ZuWWhna8wzZD2MTZC1K1C1wLkfA1UyN76ZDO-Q6WkBjgg5uZv7rtXlhj9/WL6lQJQAHKXqA9J1YIteSJ3J0Yepj69c55PducG607k'
Expand Down
6 changes: 3 additions & 3 deletions hub/parsons/action_network/action_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ def _get_generator(self, object_name, limit=None, per_page=25, filter=None):
while True:
response = self._get_page(object_name, page, per_page, filter=filter)
page = page + 1
response_list = response["_embedded"][list(response["_embedded"])[0]]
if not response_list:
return
response_list = response["_embedded"][list(response["_embedded"])[0]] or []
for item in response_list:
yield item
count = count + 1
if limit and count >= limit:
return
if len(response_list) < per_page:
return

# Advocacy Campaigns
def get_advocacy_campaigns(self, limit=None, per_page=25, page=None, filter=None):
Expand Down
Loading

0 comments on commit 3b7c3ff

Please sign in to comment.