فهرست منبع

Added another helper function that gives all locaion ids

Mohidul Islam 5 سال پیش
والد
کامیت
084078f905
3فایلهای تغییر یافته به همراه33 افزوده شده و 1 حذف شده
  1. 14 0
      gauth/location_utils.py
  2. 18 0
      gauth/migrations/0004_auto_20191229_1033.py
  3. 1 1
      gauth/models.py

+ 14 - 0
gauth/location_utils.py

@@ -4,6 +4,17 @@ from .auth_utils import refresh_access_token
 from .models import UserModel, Location
 
 
+def get_all_location_ids():
+    locations = Location.objects.only('location_id')
+    ids = [loc.location_id for loc in locations]
+    '''
+    There is a location which we don't need to add into database.
+    It is a Medical Billing Service, That's why it is nothing to do with review. 
+    '''
+    ids.remove('5397588228065547694')
+    return ids
+
+
 def populate_locations():
     access_token, _ = refresh_access_token()
     user = User.objects.get(username='admin@ercare')
@@ -18,6 +29,9 @@ def populate_locations():
     for loc in locations:
         # loc['name'] = 'accounts/103266181421855655295/locations/8916258876770296726'
         loc_id = loc['name'].split('/')[-1]
+        location_ids = get_all_location_ids()
+        if loc_id in location_ids:
+            continue
         loc_name = loc['locationName']
         loc_website = loc['websiteUrl']
         loc_display = loc['primaryCategory']['displayName']

+ 18 - 0
gauth/migrations/0004_auto_20191229_1033.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.0 on 2019-12-29 10:33
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('gauth', '0003_location'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='location',
+            name='location_id',
+            field=models.CharField(max_length=50, unique=True),
+        ),
+    ]

+ 1 - 1
gauth/models.py

@@ -12,7 +12,7 @@ class UserModel(models.Model):
 
 
 class Location(models.Model):
-    location_id = models.CharField(max_length=50)
+    location_id = models.CharField(max_length=50, unique=True)
     location_name = models.CharField(max_length=50)
     website_url = models.URLField()
     display_name = models.CharField(max_length=50)