1
0
Fork 0

Merge pull request #143 from satnogs/fetch_data

Add site settings for fetching data
pull/144/head
Nikos Roussos 2015-07-22 15:28:53 +03:00
commit 069210e635
36 changed files with 135 additions and 41 deletions

View File

@ -0,0 +1,13 @@
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
def admin_required(function):
def wrap(request, *args, **kwargs):
if not request.user.is_authenticated():
return redirect(reverse('account_login'))
if request.user.is_superuser:
return function(request, *args, **kwargs)
else:
return redirect(reverse('base:home'))
return wrap

View File

@ -14,7 +14,7 @@ class Command(BaseCommand):
apiurl = settings.DB_API_ENDPOINT
satellites_url = "{0}satellites".format(apiurl)
transponders_url = "{0}transponders".format(apiurl)
self.stdout.write(satellites_url)
self.stdout.write("Fetching from: {0}".format(satellites_url))
try:
satellites = urllib2.urlopen(satellites_url).read()
transponders = urllib2.urlopen(transponders_url).read()
@ -26,15 +26,16 @@ class Command(BaseCommand):
name = satellite['name']
try:
sat = Satellite.objects.get(norad_cat_id=norad_cat_id)
self.stdout.write('Satellite {0} already exists'.format(norad_cat_id))
self.stdout.write('Satellite {0}-{1} already exists'.format(norad_cat_id, name))
except:
sat = Satellite(norad_cat_id=norad_cat_id, name=name)
sat.save()
self.stdout.write('Satellite {0} added'.format(norad_cat_id))
self.stdout.write('Satellite {0}-{1} added'.format(norad_cat_id, name))
for transponder in json.loads(transponders):
norad_cat_id = transponder['norad_cat_id']
uuid = transponder['uuid']
description = transponder['description']
try:
sat = Satellite.objects.get(norad_cat_id=norad_cat_id)
@ -45,9 +46,9 @@ class Command(BaseCommand):
existing_transponder = Transponder.objects.get(uuid=uuid)
existing_transponder.__dict__.update(transponder)
existing_transponder.satellite = sat
self.stdout.write('Transponder {0} updated'.format(uuid))
self.stdout.write('Transponder {0}-{1} updated'.format(uuid, description))
except Transponder.DoesNotExist:
new_transponder = Transponder.objects.create(**transponder)
new_transponder.satellite = sat
new_transponder.save()
self.stdout.write('Transponder {0} created'.format(uuid))
self.stdout.write('Transponder {0}-{1} created'.format(uuid, description))

View File

@ -7,17 +7,17 @@ urlpatterns = patterns(
url(r'^$', 'index', name='home'),
url(r'^about/$', TemplateView.as_view(template_name='base/about.html'), name='about'),
url(r'^robots\.txt$', 'robots', name='robots'),
url(r'^settings_site/$', 'settings_site', name='settings_site'),
# Observations
url(r'^observations/$', 'observations_list', name='observations_list'),
url(r'^observations/(?P<id>[0-9]+)/$', 'observation_view', name='observation_view'),
url(r'^observations/new/$', 'observation_new', name='observation_new'),
url(r'^prediction_windows/(?P<sat_id>[\w.@+-]+)/(?P<start_date>.+)/(?P<end_date>.+)/$',
'prediction_windows', name='prediction_windows'),
# Stations
url(r'^stations/$', 'stations_list', name='stations_list'),
url(r'^stations/(?P<id>[0-9]+)/$', 'station_view', name='station_view'),
url(r'^stations/edit/$', 'station_edit', name='station_edit'),
url(r'^prediction_windows/(?P<sat_id>[\w.@+-]+)/(?P<start_date>.+)/(?P<end_date>.+)/$',
'prediction_windows', name='prediction_windows'),
)

View File

@ -1,5 +1,6 @@
import ephem
from datetime import datetime, timedelta
from StringIO import StringIO
from django.conf import settings
from django.contrib import messages
@ -9,10 +10,12 @@ from django.core.urlresolvers import reverse
from django.utils.timezone import now, make_aware, utc
from django.http import JsonResponse, HttpResponseNotFound, HttpResponseServerError, HttpResponse
from django.contrib.auth.decorators import login_required
from django.core.management import call_command
from network.base.models import (Station, Transponder, Observation,
Data, Satellite, Antenna)
from network.base.forms import StationForm
from network.base.decorators import admin_required
def index(request):
@ -51,6 +54,26 @@ def robots(request):
return response
@admin_required
def settings_site(request):
"""View to render settings page."""
if request.method == 'POST':
if request.POST['fetch']:
try:
out = StringIO()
call_command('fetch_data', stdout=out)
request.session['fetch_out'] = out.getvalue()
except:
messages.error(request, 'fetch command failed.')
return redirect(reverse('base:settings_site'))
fetch_out = request.session.get('fetch_out', False)
if fetch_out:
del request.session['fetch_out']
return render(request, 'base/settings_site.html', {'fetch_data': fetch_out})
return render(request, 'base/settings_site.html')
def observations_list(request):
"""View to render Observations page."""
observations = Observation.objects.all()

View File

@ -200,6 +200,17 @@ footer {
display: none;
}
code.log {
display: none;
background-color: transparent;
}
code.log p {
background-color: black;
color: white;
padding: 5px;
}
/* Stations
==================== */

View File

@ -0,0 +1,11 @@
$( document ).ready( function(){
$('#fetchform').submit(function(){
$('button[type=submit]', this).attr('disabled', 'disabled');
$('button[type=submit]', this).text('fetching');
});
$('#fetch_log').click(function(){
$('code').toggle();
event.preventDefault();
});
});

View File

@ -3,7 +3,7 @@
{% load url from future %}
{% load crispy_forms_tags %}
{% block head_title %}Account{% endblock %}
{% block head_title %} - Account{% endblock %}
{% block content %}
<div class="container">

View File

@ -3,7 +3,7 @@
{% load url from future %}
{% load account %}
{% block head_title %}Confirm E-mail Address{% endblock %}
{% block head_title %} - Confirm E-mail Address{% endblock %}
{% block content %}
<div class="container">

View File

@ -2,7 +2,7 @@
{% load account %}
{% block head_title %}Confirm E-mail Address{% endblock %}
{% block head_title %} - Confirm E-mail Address{% endblock %}
{% block content %}
<div class="container">

View File

@ -4,7 +4,7 @@
{% load url from future %}
{% load crispy_forms_tags %}
{% block head_title %}Sign In{% endblock %}
{% block head_title %} - Sign In{% endblock %}
{% block content %}
<div class="container">

View File

@ -2,7 +2,7 @@
{% load url from future %}
{% block head_title %}Sign Out{% endblock %}
{% block head_title %} - Sign Out{% endblock %}
{% block content %}
<div class="container">

View File

@ -1,7 +1,7 @@
{% extends "account/base.html" %}
{% load crispy_forms_tags %}
{% block head_title %}Change Password{% endblock %}
{% block head_title %} - Change Password{% endblock %}
{% block content %}
<div class="container">

View File

@ -1,6 +1,6 @@
{% extends "account/base.html" %}
{% block head_title %}Delete Password{% endblock %}
{% block head_title %} - Delete Password{% endblock %}
{% block content %}
<h2>Delete Password</h2>

View File

@ -1,6 +1,6 @@
{% extends "account/base.html" %}
{% block head_title %}Password Deleted{% endblock %}
{% block head_title %} - Password Deleted{% endblock %}
{% block content %}
<h2>Password Deleted</h2>

View File

@ -3,7 +3,7 @@
{% load account %}
{% load crispy_forms_tags %}
{% block head_title %}Password Reset{% endblock %}
{% block head_title %} - Password Reset{% endblock %}
{% block content %}
<div class="container">

View File

@ -2,7 +2,7 @@
{% load account %}
{% block head_title %}Password Reset{% endblock %}
{% block head_title %} - Password Reset{% endblock %}
{% block content %}
<div class="container">

View File

@ -3,7 +3,7 @@
{% load url from future %}
{% load crispy_forms_tags %}
{% block head_title %}Change Password{% endblock %}
{% block head_title %} - Change Password{% endblock %}
{% block content %}
<div class="container">

View File

@ -1,7 +1,7 @@
{% extends "account/base.html" %}
{% load url from future %}
{% block head_title %}Change Password{% endblock %}
{% block head_title %} - Change Password{% endblock %}
{% block content %}
<div class="container">

View File

@ -3,7 +3,7 @@
{% load crispy_forms_tags %}
{% block head_title %}Set Password{% endblock %}
{% block head_title %} - Set Password{% endblock %}
{% block content %}
<div class="container">

View File

@ -3,7 +3,7 @@
{% load url from future %}
{% load crispy_forms_tags %}
{% block title %}Sign Up{% endblock title %}
{% block title %} - Sign Up{% endblock title %}
{% block content %}
<h1>Sign Up</h1>

View File

@ -2,7 +2,7 @@
{% load url from future %}
{% block head_title %}Invitation only Sign Ups{% endblock %}
{% block head_title %} - Invitation only Sign Ups{% endblock %}
{% block content %}
<div class="container">

View File

@ -1,7 +1,7 @@
{% extends "account/base.html" %}
{% block head_title %}Verify Your E-mail Address{% endblock %}
{% block head_title %} - Verify Your E-mail Address{% endblock %}
{% block content %}
<div class="container">

View File

@ -2,7 +2,7 @@
{% load url from future %}
{% block head_title %}Verify Your E-mail Address{% endblock %}
{% block head_title %} - Verify Your E-mail Address{% endblock %}
{% block content %}
<div class="container">
@ -10,7 +10,7 @@
<div class="col-md-5">
<h2>Verify Your E-mail Address</h2>
{% url 'account_email' as email_url %}
<p>This part of the site requires us to verify that
you are who you claim to be. For this purpose, we require that you
verify ownership of your e-mail address.</p>

View File

@ -1,4 +1,4 @@
{% extends "base.html" %}
{% block title %}django-avatar{% endblock %}
{% block title %} - Avatar{% endblock %}
{% block content %}{% endblock %}

View File

@ -1,4 +1,4 @@
{% load staticfiles i18n %}
{% load staticfiles %}
{% load avatar_tags %}
{% load tags %}
@ -6,7 +6,7 @@
<html lang="en" ng-app>
<head>
<meta charset="utf-8">
<title>SatNOGS - Network - {% block title %}{% endblock title %}</title>
<title>SatNOGS - Network{% block title %}{% endblock title %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'css/lib/bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'css/lib/bootstrap-theme.min.css' %}">
@ -57,6 +57,9 @@
</a>
<ul class="dropdown-menu" role="menu">
<li><a href="{% url 'users:view_user' username=request.user.username %}">My Profile</a></li>
{% if request.user.is_superuser %}
<li><a href="{% url 'base:settings_site' %}">Site Settings</a></li>
{% endif %}
<li><a href="{% url 'account_logout' %}">Logout</a></li>
</ul>
</li>

View File

@ -1,6 +1,6 @@
{% extends "base.html" %}
{% block title %}Home{% endblock %}
{% block title %} - About{% endblock %}
{% block content %}
<div class="row">

View File

@ -3,7 +3,7 @@
{% load staticfiles %}
{% load tags %}
{% block title %}Home{% endblock %}
{% block title %} - Home{% endblock %}
{% block css %}
<link rel="stylesheet" href="{% static 'css/lib/mapbox.css' %}">

View File

@ -3,7 +3,7 @@
{% load staticfiles %}
{% load tags %}
{% block title %}New Observation{% endblock %}
{% block title %} - New Observation{% endblock %}
{% block css %}
<link href="{% static 'css/lib/bootstrap-datetimepicker.min.css' %}" rel="stylesheet">

View File

@ -3,7 +3,7 @@
{% load staticfiles %}
{% block title %}Observation {{ observation.id }}{% endblock %}
{% block title %} - Observation {{ observation.id }}{% endblock %}
{% block css %}
<link rel="stylesheet" href="{% static 'css/lib/spinner.css' %}">

View File

@ -1,7 +1,7 @@
{% extends "base.html" %}
{% load tags %}
{% block title %}Observations{% endblock %}
{% block title %} - Observations{% endblock %}
{% block content %}
<h1>

View File

@ -0,0 +1,32 @@
{% extends "base.html" %}
{% load staticfiles %}
{% block title %} - Site Settings{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-12">
<h1>Settings</h1>
<h3>Fetch Data</h3>
{% if fetch_data %}
<p>Successfully fetch data from DB.</p>
<p><a href="#" id="fetch_log">Show log</a></p>
<code class="log">{{ fetch_data|linebreaks }}</code>
{% else %}
<p>You can update all Satellites and Transponders data from DB.</p>
<form id="fetchform" method="post" class="form-horizontal" role="form" action="{% url 'base:settings_site' %}">{% csrf_token %}
<input type="hidden" name="fetch" value="true">
<button class="btn btn-primary" type="submit">Fetch</button>
</form>
{% endif %}
</div>
</div>
{% endblock content %}
{% block javascript %}
<script src="{% static 'js/settings_site.js' %}"></script>
{% endblock javascript %}

View File

@ -3,7 +3,7 @@
{% load staticfiles %}
{% block title %}Ground Station {{ station.name }}{% endblock %}
{% block title %} - Ground Station {{ station.name }}{% endblock %}
{% block css %}
<link rel="stylesheet" href="{% static 'css/lib/mapbox.css' %}">

View File

@ -2,7 +2,7 @@
{% load tags %}
{% load staticfiles %}
{% block title %}Ground Stations{% endblock %}
{% block title %} - Ground Stations{% endblock %}
{% block content %}
<h1>

View File

@ -3,7 +3,7 @@
{% load static %}
{% load tags %}
{% block title %}User: {{ user.username }}{% endblock %}
{% block title %} - User: {{ user.username }}{% endblock %}
{% block content %}
<div class="row">

View File

@ -1,7 +1,7 @@
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block title %}User: {{ user.username }}{% endblock %}
{% block title %} - User: {{ user.username }}{% endblock %}
{% block content %}
<div class="row">
@ -19,4 +19,4 @@
</form>
</div>
</div>
{% endblock %}
{% endblock %}

View File

@ -2,7 +2,7 @@
{% load static %}
{% load avatar_tags %}
{% block title %}Members{% endblock %}
{% block title %} - Members{% endblock %}
{% block content %}
<div class="row">
@ -23,4 +23,4 @@
</div>
</div>
</div>
{% endblock content %}
{% endblock content %}