Tony Mack | f593dba | 2013-03-24 13:17:43 -0400 | [diff] [blame] | 1 | from PLC.Sites import Sites |
| 2 | from models import Site |
| 3 | |
| 4 | class SiteImporter: |
| 5 | |
| 6 | def __init__(self, importer): |
| 7 | self.importer = importer |
| 8 | self.sites = {} |
| 9 | |
| 10 | def run(self): |
| 11 | sites = Sites(self.importer.api) |
| 12 | db_sites = Site.objects.all() |
| 13 | db_site_names = [s['login_base'] for s in db_sites] |
| 14 | for site in sites: |
| 15 | if site['login_base'] not in db_site_names: |
| 16 | new_site = Site(name=site['name'], |
| 17 | site_url=site['url'], |
| 18 | enabled=site['enabled'], |
| 19 | longitude=site['longitude'], |
| 20 | latitude=site['latitude'], |
| 21 | is_public=site['is_public'], |
| 22 | abbreviated_name=site['abbreviated_name']) |
| 23 | new_site.save() |
| 24 | self.sites[site['site_id']] = site |
| 25 | |
| 26 | |
| 27 | |