Commit 1d02923f by Clinton Blackburn

Moved Country Constants to Separate File

parent 8ac02398
from iso3166 import Country
UNKNOWN_COUNTRY_CODE = u'UNKNOWN'
UNKNOWN_COUNTRY = Country(UNKNOWN_COUNTRY_CODE, None, None, None)
from iso3166 import Country
UNKNOWN_COUNTRY_CODE = u'UNKNOWN'
UNKNOWN_COUNTRY = Country(UNKNOWN_COUNTRY_CODE, None, None, None)
from django.db import models from django.db import models
from iso3166 import countries from iso3166 import countries
from analytics_data_api.constants import UNKNOWN_COUNTRY, genders from analytics_data_api.constants import country, genders
class CourseActivityWeekly(models.Model): class CourseActivityWeekly(models.Model):
...@@ -135,7 +135,7 @@ class CourseEnrollmentByCountry(BaseCourseEnrollment): ...@@ -135,7 +135,7 @@ class CourseEnrollmentByCountry(BaseCourseEnrollment):
return countries.get(self.country_code) return countries.get(self.country_code)
except (KeyError, ValueError, AttributeError): except (KeyError, ValueError, AttributeError):
# Country code is not valid ISO-3166 # Country code is not valid ISO-3166
return UNKNOWN_COUNTRY return country.UNKNOWN_COUNTRY
class Meta(BaseCourseEnrollment.Meta): class Meta(BaseCourseEnrollment.Meta):
db_table = 'course_enrollment_location_current' db_table = 'course_enrollment_location_current'
......
...@@ -3,7 +3,7 @@ from django_dynamic_fixture import G ...@@ -3,7 +3,7 @@ from django_dynamic_fixture import G
from iso3166 import countries from iso3166 import countries
from analytics_data_api.v0 import models from analytics_data_api.v0 import models
from analytics_data_api.constants import UNKNOWN_COUNTRY from analytics_data_api.constants.country import UNKNOWN_COUNTRY
class EducationLevelTests(TestCase): class EducationLevelTests(TestCase):
......
...@@ -15,7 +15,7 @@ import pytz ...@@ -15,7 +15,7 @@ import pytz
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from analytics_data_api.v0 import models from analytics_data_api.v0 import models
from analytics_data_api.constants import UNKNOWN_COUNTRY, UNKNOWN_COUNTRY_CODE, enrollment_modes from analytics_data_api.constants import country, enrollment_modes
from analytics_data_api.v0.models import CourseActivityWeekly from analytics_data_api.v0.models import CourseActivityWeekly
from analytics_data_api.v0.serializers import ProblemResponseAnswerDistributionSerializer from analytics_data_api.v0.serializers import ProblemResponseAnswerDistributionSerializer
from analytics_data_api.v0.serializers import GradeDistributionSerializer from analytics_data_api.v0.serializers import GradeDistributionSerializer
...@@ -444,16 +444,16 @@ class CourseEnrollmentByLocationViewTests(CourseEnrollmentViewTestCaseMixin, Tes ...@@ -444,16 +444,16 @@ class CourseEnrollmentByLocationViewTests(CourseEnrollmentViewTestCaseMixin, Tes
def format_as_response(self, *args): def format_as_response(self, *args):
unknown = {'course_id': None, 'count': 0, 'date': None, unknown = {'course_id': None, 'count': 0, 'date': None,
'country': {'alpha2': None, 'alpha3': None, 'name': UNKNOWN_COUNTRY_CODE}} 'country': {'alpha2': None, 'alpha3': None, 'name': country.UNKNOWN_COUNTRY_CODE}}
for arg in args: for arg in args:
if arg.country.name == UNKNOWN_COUNTRY_CODE: if arg.country.name == country.UNKNOWN_COUNTRY_CODE:
unknown['course_id'] = arg.course_id unknown['course_id'] = arg.course_id
unknown['date'] = arg.date.strftime(settings.DATE_FORMAT) unknown['date'] = arg.date.strftime(settings.DATE_FORMAT)
unknown['count'] += arg.count unknown['count'] += arg.count
unknown['created'] = arg.created.strftime(settings.DATETIME_FORMAT) unknown['created'] = arg.created.strftime(settings.DATETIME_FORMAT)
args = [arg for arg in args if arg.country != UNKNOWN_COUNTRY] args = [arg for arg in args if arg.country != country.UNKNOWN_COUNTRY]
args = sorted(args, key=lambda item: (item.date, item.course_id, item.country.alpha3)) args = sorted(args, key=lambda item: (item.date, item.course_id, item.country.alpha3))
response = [unknown] response = [unknown]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment