1
0
Fork 0

Add management command to initialize data

merge-requests/68/head
Nikos Roussos 2014-10-27 20:16:38 +02:00
parent 4792756749
commit 21c2b3ce5e
3 changed files with 41 additions and 3 deletions

View File

@ -34,9 +34,13 @@ $ source ../env/satnogs/bin/activate
```
(satnogs)$ ./manage.py createsuperuser
```
7 - Run development server
7 - Push some demo data
```
(satnogs)$ ./manage.py runserver 0.0.0.0:8000
(satnogs)$ ./manage.py initialize
```
8 - Run development server
```
(satnogs)$ ./manage.py runserver
```
Your satnogs-network development instance is available in localhost:8000 . Go hack!

View File

@ -0,0 +1,34 @@
from orbit import satellite
from django.core.management.base import BaseCommand
from base.tests import ObservationFactory, StationFactory
from base.models import Satellite
class Command(BaseCommand):
help = 'Create initial fixtures'
def handle(self, *args, **options):
ObservationFactory.create_batch(20)
StationFactory.create_batch(20)
satellites = Satellite.objects.all()
for obj in satellites:
try:
sat = satellite(obj.norad_cat_id)
except:
self.stdout.write(('Satellite {} with Identifier {} does '
'not exist [deleted]').format(obj.name, obj.norad_cat_id))
obj.delete()
continue
obj.name = sat.name()
tle = sat.tle()
obj.tle0 = tle[0]
obj.tle1 = tle[1]
obj.tle2 = tle[2]
obj.save()
self.stdout.write(('Satellite {} with Identifier {} '
'found [updated]').format(obj.norad_cat_id, obj.name))

View File

@ -45,7 +45,7 @@ class StationFactory(factory.django.DjangoModelFactory):
class SatelliteFactory(factory.django.DjangoModelFactory):
"""Sattelite model factory."""
norad_cat_id = fuzzy.FuzzyInteger(1000, 8000)
norad_cat_id = fuzzy.FuzzyInteger(2000, 4000)
name = fuzzy.FuzzyText()
tle0 = fuzzy.FuzzyText()
tle1 = fuzzy.FuzzyText()