1
0
Fork 0

Merge pull request #92 from satnogs/defaultimg

Set a default station image
merge-requests/100/head
Nikos Roussos 2015-02-15 01:56:11 +02:00
commit 941b64090b
6 changed files with 31 additions and 3 deletions

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('base', '0013_remove_station_featured'),
]
operations = [
migrations.AlterField(
model_name='station',
name='image',
field=models.ImageField(upload_to=b'ground_stations', blank=True),
preserve_default=True,
),
]

View File

@ -1,6 +1,7 @@
from django.core.validators import MaxValueValidator, MinValueValidator from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models from django.db import models
from django.utils.timezone import now from django.utils.timezone import now
from django.conf import settings
from network.users.models import User from network.users.models import User
@ -30,7 +31,7 @@ class Station(models.Model):
"""Model for SatNOGS ground stations.""" """Model for SatNOGS ground stations."""
owner = models.ForeignKey(User) owner = models.ForeignKey(User)
name = models.CharField(max_length=45) name = models.CharField(max_length=45)
image = models.ImageField(upload_to='ground_stations') image = models.ImageField(upload_to='ground_stations', blank=True)
alt = models.PositiveIntegerField(help_text='In meters above ground') alt = models.PositiveIntegerField(help_text='In meters above ground')
lat = models.FloatField(validators=[MaxValueValidator(90), lat = models.FloatField(validators=[MaxValueValidator(90),
MinValueValidator(-90)]) MinValueValidator(-90)])
@ -45,6 +46,12 @@ class Station(models.Model):
online = models.BooleanField(default=False, online = models.BooleanField(default=False,
help_text='Is your Ground Station functional?') help_text='Is your Ground Station functional?')
def get_image(self):
if self.image and hasattr(self.image, 'url'):
return self.image.url
else:
return settings.STATION_DEFAULT_IMAGE
def __unicode__(self): def __unicode__(self):
return "%d - %s" % (self.pk, self.name) return "%d - %s" % (self.pk, self.name)

View File

@ -96,6 +96,7 @@ STATICFILES_FINDERS = (
MEDIA_ROOT = path.join(BASE_DIR, 'media') MEDIA_ROOT = path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
CRISPY_TEMPLATE_PACK = 'bootstrap3' CRISPY_TEMPLATE_PACK = 'bootstrap3'
STATION_DEFAULT_IMAGE = '/static/images/dish.png'
# App conf # App conf
ROOT_URLCONF = 'network.urls' ROOT_URLCONF = 'network.urls'

View File

@ -138,6 +138,6 @@
} }
.station-edit-image { .station-edit-image {
width: 20px; width: 200px;
float: right; float: right;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@ -77,7 +77,7 @@
{% endfor %} {% endfor %}
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<img src="{{ MEDIA_URL }}{{ station.image }}" <img src="{{ station.get_image }}"
class="station-view-image" class="station-view-image"
alt="{{ station.name }}" alt="{{ station.name }}"
title="{{ station.name }}"> title="{{ station.name }}">