Skip to content

Commit

Permalink
Add status in regionType
Browse files Browse the repository at this point in the history
  • Loading branch information
sudan45 committed Dec 4, 2024
1 parent 3e13c57 commit 2d1e66f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
19 changes: 19 additions & 0 deletions apps/geo/enums.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import graphene
from geo.models import Region

from utils.graphene.enums import (
convert_enum_to_graphene_enum,
get_enum_name_from_django_field,
)


class GeoAreaOrderingEnum(graphene.Enum):
Expand All @@ -8,3 +14,16 @@ class GeoAreaOrderingEnum(graphene.Enum):
# DESC
DESC_ID = f'-{ASC_ID}'
DESC_ADMIN_LEVEL = f'-{ASC_ADMIN_LEVEL}'


RegionStatusEnum = convert_enum_to_graphene_enum(
Region.Status, name='RegionStatusEnum'
)


enum_map = {
get_enum_name_from_django_field(field): enum
for field, enum in (
(Region.status, RegionStatusEnum),
)
}
2 changes: 2 additions & 0 deletions apps/geo/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def mutate(root, info, region_id):
error_data.append('Geo Area already generated')
elif instance.created_by != info.context.user:
error_data.append('Authorized User only update region')
elif instance.is_published == True:
error_data.append("Published Region cannot be retiggered")

if error_data:
return ReTriggeredFailedRegion(errors=[
Expand Down
5 changes: 4 additions & 1 deletion apps/geo/schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from geo.enums import RegionStatusEnum
import graphene
from graphene_django import DjangoObjectType
from graphene_django_extras import DjangoObjectField, PageGraphqlPagination
Expand Down Expand Up @@ -53,12 +54,14 @@ def get_custom_queryset(queryset, info, **kwargs):


class RegionType(DjangoObjectType, ClientIdMixin):
status = graphene.Field(RegionStatusEnum)

class Meta:
model = Region
only_fields = (
'id', 'title', 'public', 'regional_groups',
'key_figures', 'population_data', 'media_sources',
'centroid', 'is_published',
'centroid', 'is_published', 'status'
)

@staticmethod
Expand Down
6 changes: 5 additions & 1 deletion apps/geo/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ def load_geo_areas(region_id):
if not have_lock:
return False
region = Region.objects.filter(id=region_id).first()
region.status = Region.Status.INITIATED
if not region:
logger.error("Region not found", exc_info=True)
return False


try:
return_value = _load_geo_areas(region_id)
region.status = Region.Status.COMPLETED
Expand Down
9 changes: 9 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6011,6 +6011,7 @@ type RegionDetailType {
mediaSources: GenericScalar
centroid: PointScalar
clientId: ID!
status: RegionStatusEnum
adminLevels: [AdminLevelType!]!
}

Expand Down Expand Up @@ -6050,6 +6051,13 @@ input RegionProjectFilterData {
isTest: Boolean
}

enum RegionStatusEnum {
INITIATED
PENDING
COMPLETED
FAILED
}

type RegionType {
id: ID!
title: String!
Expand All @@ -6060,6 +6068,7 @@ type RegionType {
populationData: GenericScalar
mediaSources: GenericScalar
centroid: PointScalar
status: RegionStatusEnum
clientId: ID!
}

Expand Down

0 comments on commit 2d1e66f

Please sign in to comment.