1
0
Fork 0

Move Station edit template out of modal

* Add help blocks as placeholders
merge-requests/475/head
Nikos Roussos 2018-03-16 14:18:48 +02:00
parent 78472c4df4
commit 565f64f35b
No known key found for this signature in database
GPG Key ID: BADFF1767BA7C8E1
10 changed files with 178 additions and 160 deletions

View File

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-03-16 12:16
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('base', '0035_auto_20180307_1527'),
]
operations = [
migrations.AlterField(
model_name='station',
name='description',
field=models.TextField(blank=True, help_text=b'Max 500 characters', max_length=500),
),
migrations.AlterField(
model_name='station',
name='lat',
field=models.FloatField(help_text=b'eg. 38.01697', validators=[django.core.validators.MaxValueValidator(90), django.core.validators.MinValueValidator(-90)]),
),
migrations.AlterField(
model_name='station',
name='lng',
field=models.FloatField(help_text=b'eg. 23.7314', validators=[django.core.validators.MaxValueValidator(180), django.core.validators.MinValueValidator(-180)]),
),
]

View File

@ -127,10 +127,10 @@ class Station(models.Model):
name = models.CharField(max_length=45)
image = models.ImageField(upload_to='ground_stations', blank=True)
alt = models.PositiveIntegerField(help_text='In meters above ground')
lat = models.FloatField(validators=[MaxValueValidator(90),
MinValueValidator(-90)])
lng = models.FloatField(validators=[MaxValueValidator(180),
MinValueValidator(-180)])
lat = models.FloatField(validators=[MaxValueValidator(90), MinValueValidator(-90)],
help_text='eg. 38.01697')
lng = models.FloatField(validators=[MaxValueValidator(180), MinValueValidator(-180)],
help_text='eg. 23.7314')
qthlocator = models.CharField(max_length=255, blank=True)
location = models.CharField(max_length=255, blank=True)
antenna = models.ManyToManyField(Antenna, blank=True,
@ -146,7 +146,7 @@ class Station(models.Model):
uuid = models.CharField(db_index=True, max_length=100, blank=True)
rig = models.ForeignKey(Rig, related_name='ground_stations',
on_delete=models.SET_NULL, null=True, blank=True)
description = models.TextField(max_length=500, blank=True)
description = models.TextField(max_length=500, blank=True, help_text='Max 500 characters')
class Meta:
ordering = ['-status']

View File

@ -32,6 +32,7 @@ base_urlpatterns = ([
url(r'^stations/(?P<id>[0-9]+)/$', views.station_view, name='station_view'),
url(r'^stations/(?P<id>[0-9]+)/delete/$', views.station_delete, name='station_delete'),
url(r'^stations/edit/$', views.station_edit, name='station_edit'),
url(r'^stations/edit/(?P<id>[0-9]+)/$', views.station_edit, name='station_edit'),
url(r'^stations_all/$', views.StationAllView.as_view({'get': 'list'}), name='stations_all'),
# Satellites

View File

@ -13,7 +13,6 @@ from django.http import JsonResponse, HttpResponseNotFound, HttpResponseServerEr
from django.shortcuts import get_object_or_404, render, redirect
from django.utils.timezone import now, make_aware, utc
from django.utils.text import slugify
from django.views.decorators.http import require_POST
from django.views.generic import ListView
from rest_framework import serializers, viewsets
@ -681,28 +680,40 @@ def pass_predictions(request, id):
return JsonResponse(data, safe=False)
@require_POST
def station_edit(request):
def station_edit(request, id=None):
"""Edit or add a single station."""
if request.POST['id']:
pk = request.POST.get('id')
station = get_object_or_404(Station, id=pk, owner=request.user)
form = StationForm(request.POST, request.FILES, instance=station)
station = None
antennas = Antenna.objects.all()
rigs = Rig.objects.all()
if id:
station = get_object_or_404(Station, id=id, owner=request.user)
if request.method == 'POST':
if station:
form = StationForm(request.POST, request.FILES, instance=station)
else:
form = StationForm(request.POST, request.FILES)
if form.is_valid():
f = form.save(commit=False)
if not station:
f.testing = True
f.owner = request.user
f.save()
form.save_m2m()
messages.success(request, 'Ground Station saved successfully.')
return redirect(reverse('base:station_view', kwargs={'id': f.id}))
else:
messages.error(request, ('Your Ground Station submission has some '
'errors. {0}').format(form.errors))
return render(request, 'base/station_edit.html',
{'form': form, 'station': station, 'antennas': antennas, 'rigs': rigs})
else:
pk = False
form = StationForm(request.POST, request.FILES)
if form.is_valid():
f = form.save(commit=False)
if not pk:
f.testing = True
f.owner = request.user
f.save()
form.save_m2m()
messages.success(request, 'Successfully saved Ground Station.')
return redirect(reverse('base:station_view', kwargs={'id': f.id}))
else:
messages.error(request, 'Your Station submission had some errors.{0}'.format(form.errors))
return redirect(reverse('users:view_user', kwargs={'username': request.user.username}))
if station:
form = StationForm(instance=station)
else:
form = StationForm()
return render(request, 'base/station_edit.html',
{'form': form, 'station': station, 'antennas': antennas, 'rigs': rigs})
@login_required

View File

@ -194,7 +194,7 @@ span.datetime-time {
.station-edit-image {
width: 200px;
float: right;
margin: 5px 0;
}
.alert-error > .errorlist {

View File

@ -0,0 +1,103 @@
{% extends "base.html" %}
{% load tags %}
{% load staticfiles %}
{% block title %}{% if station %} - Edit Ground Station {{ station.name }}{% else %} - Add Ground Station{% endif %}{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-6">
<h2>
{% if station %}
Edit: {{ station.id }} - {{ station.name }}
{% else %}
Add Ground Station
{% endif %}
</h2>
</div>
</div>
<div class="row">
<div class="col-md-8">
<form role="form" enctype="multipart/form-data" method="post">{% csrf_token %}
<div class="form-group">
<label for="name" class="control-label">Name</label>
<input value="{{ form.name.value|default_if_none:"" }}" id="name" type="text" class="form-control" name="name" required>
</div>
<div class="form-group">
<label for="image" class="control-label">Image</label>
<input id="image" type="file" name="image">
{% if form.image.value %}
<img src="{{ MEDIA_URL }}{{ form.image.value }}"
class="station-edit-image">
{% endif %}
</div>
<div class="form-group">
<label for="alt" class="control-label">Altitude</label>
<input value="{{ form.alt.value|default_if_none:"" }}" id="alt" type="number" class="form-control" name="alt" placeholder="{{ form.alt.help_text }}" required>
</div>
<div class="form-group">
<label for="lat" class="control-label">Latitude</label>
<input value="{{ form.lat.value|default_if_none:"" }}" id="lat" type="text" class="form-control" name="lat" placeholder="{{ form.lat.help_text }}" required>
</div>
<div class="form-group">
<label for="lng" class="control-label">Longtitude</label>
<input value="{{ form.lng.value|default_if_none:"" }}" id="lng" type="text" class="form-control" name="lng" placeholder="{{ form.lng.help_text }}" required>
</div>
<div class="form-group">
<label for="qthlocator" class="control-label">QTH Locator</label>
<input class="form-control"
id="qthlocator"
type="text"
name="qthlocator"
value="{{ form.qthlocator.value|default_if_none:"" }}"
readonly>
</div>
<div class="form-group">
<label for="horizon" class="control-label">Minimum Horizon</label>
<input value="{{ form.horizon.value|default_if_none:"" }}" id="horizon" type="number" class="form-control" name="horizon" placeholder="{{ form.horizon.help_text }}">
</div>
<div class="form-group">
<label for="antennas" class="control-label">Antennas</label>
<select multiple class="form-control" name="antenna">
{% for antenna in antennas %}
<option value="{{ antenna.id }}" {% if antenna in station.antenna.all %}selected{% endif %}>
{{ antenna.band}} {{ antenna.get_antenna_type_display }} | {{ antenna.frequency|frq }} - {{ antenna.frequency_max|frq }}
</option>
{% endfor %}
</select>
<span class="help-block">{{ form.antenna.help_text|safe }}</span>
</div>
{% if rigs %}
<div class="form-group">
<label for="rig" class="control-label">Rig</label>
<select class="form-control" name="rig">
<option value="" selected>---</option>
{% for rig in rigs %}
<option value="{{ rig.id }}" {% ifequal station.rig rig %}selected{% endifequal %}>
{{ rig }}
</option>
{% endfor %}
</select>
</div>
{% endif %}
<div class="form-group">
<label for="description" class="control-label">Description</label>
<textarea class="form-control" value="{{ form.description.value|default_if_none:"" }}"
id="description" rows="3" maxlength="500" placeholder="{{ form.description.help_text }}"></textarea>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" name="testing" {% if form.testing.value %}checked="True"{% endif %} {% if not station.id %}disabled{% endif %}>
Testing?
<span class="glyphicon glyphicon-question-sign" aria-hidden="true" data-toggle="tooltip"
title="Make sure you Station is performing well for a period of time before you lift the Testing flag"></span>
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
{% endblock %}

View File

@ -26,10 +26,10 @@
<div class="col-md-6 text-right">
<h2>
{% if request.user == station.owner %}
<button class="btn btn-primary" data-toggle="modal" data-target="#StationModal">
<a class="btn btn-primary" href="{% url 'base:station_edit' id=station.id %}">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Edit
</button>
</a>
<a class="btn btn-danger" id="station-delete" href="{% url 'base:station_delete' id=station.id %}">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
Delete
@ -256,10 +256,6 @@
</div>
</div>
{% if request.user == station.owner %}
<!-- Station Modal -->
{% include 'includes/station_edit.html' %}
{% endif %}
{% include 'includes/satellite.html' %}
{% include 'includes/legend.html' %}
{% endblock content %}

View File

@ -7,9 +7,6 @@
{% block content %}
<h1>
Ground Stations
{% if user.is_authenticated %}
<button class="btn btn-primary pull-right" data-toggle="modal" data-target="#StationModal">New Ground Station</button>
{% endif %}
</h1>
<div class="row">
@ -94,9 +91,6 @@
</table>
</div>
</div>
<!-- Station Modal -->
{% include 'includes/station_edit.html' %}
{% endblock content %}
{% block javascript %}

View File

@ -1,118 +0,0 @@
{% load tags %}
<div class="modal fade" id="StationModal" tabindex="-1" role="dialog" aria-labelledby="StationModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="StationModal">Edit Ground Station</h4>
</div>
<form class="form-horizontal"
role="form"
enctype="multipart/form-data"
method="post"
action="{% url 'base:station_edit' %}">{% csrf_token %}
<div class="modal-body">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input value="{{ form.name.value|default_if_none:"" }}" id="name" type="text" class="form-control" name="name" placeholder="Name" required>
</div>
</div>
<div class="form-group">
<label for="image" class="col-sm-2 control-label">Image</label>
<div class="col-sm-10">
<input id="image" type="file" name="image">
{% if form.image.value %}
<img src="{{ MEDIA_URL }}{{ form.image.value }}"
class="station-edit-image">
{% endif %}
</div>
</div>
<div class="form-group">
<label for="alt" class="col-sm-2 control-label">Altitude</label>
<div class="col-sm-10">
<input value="{{ form.alt.value|default_if_none:"" }}" id="alt" type="number" class="form-control" name="alt" placeholder="Altitude" required>
<span class="help-block">{{ form.alt.help_text }}</span>
</div>
</div>
<div class="form-group">
<label for="lat" class="col-sm-2 control-label">Latitude</label>
<div class="col-sm-10">
<input value="{{ form.lat.value|default_if_none:"" }}" id="lat" type="text" class="form-control" name="lat" placeholder="Latitude" required>
</div>
</div>
<div class="form-group">
<label for="lng" class="col-sm-2 control-label">Longtitude</label>
<div class="col-sm-10">
<input value="{{ form.lng.value|default_if_none:"" }}" id="lng" type="text" class="form-control" name="lng" placeholder="Longtitude" required>
</div>
</div>
<div class="form-group">
<label for="qthlocator" class="col-sm-2 control-label">QTH Locator</label>
<div class="col-sm-10">
<input class="form-control"
id="qthlocator"
type="text"
name="qthlocator"
value="{{ form.qthlocator.value|default_if_none:"Geocoded gridsquare" }}"
readonly>
</div>
</div>
<div class="form-group">
<label for="horizon" class="col-sm-2 control-label">Minimum Horizon</label>
<div class="col-sm-10">
<input value="{{ form.horizon.value }}" id="horizon" type="number" class="form-control" name="horizon" placeholder="Minimum horizon for passes, default 10">
<span class="help-block">{{ form.horizon.help_text }}</span>
</div>
</div>
<div class="form-group">
<label for="antennas" class="col-sm-2 control-label">Antennas</label>
<div class="col-sm-10">
<select multiple class="form-control" name="antenna">
{% for antenna in antennas %}
<option value="{{ antenna.id }}" {% if antenna in station.antenna.all %}selected{% endif %}>
{{ antenna.band}} {{ antenna.get_antenna_type_display }} | {{ antenna.frequency|frq }} - {{ antenna.frequency_max|frq }}
</option>
{% endfor %}
</select>
<span class="help-block">{{ form.antenna.help_text|safe }}</span>
</div>
</div>
<div class="form-group">
<label for="rig" class="col-sm-2 control-label">Rig</label>
<div class="col-sm-10">
<select class="form-control" name="rig">
<option value="" selected>---</option>
{% for rig in rigs %}
<option value="{{ rig.id }}" {% ifequal station.rig rig %}selected{% endifequal %}>
{{ rig }}
</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label for="description" class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<input value="{{ form.description.value|default_if_none:"" }}" id="description" type="text" class="form-control" name="description" maxlength="500" placeholder="Max 500 characters">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<input type="checkbox" name="testing" {% if form.testing.value %}checked="True"{% endif %} {% if not station.id %}disabled{% endif %}>
Testing?
</div>
</div>
</div>
</div>
<div class="modal-footer">
<input type="hidden" name="id" value="{{ station.id }}">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>

View File

@ -122,9 +122,9 @@
{% if user == request.user %}
<div class="row">
<div class="col-md-12">
<button class="btn btn-default" data-toggle="modal" data-target="#StationModal">Add Ground Station</button>
<!-- Station Modal -->
{% include 'includes/station_edit.html' %}
<a class="btn btn-default" href="{% url 'base:station_edit' %}">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add Ground Station
</a>
</div>
</div>
{% endif %}