Skip to content

Commit

Permalink
Merge pull request #122 from OpenUpSA/fix/save-point-without-image
Browse files Browse the repository at this point in the history
Allow images and data in points.Location to be null
  • Loading branch information
milafrerichs authored Sep 29, 2020
2 parents aa40d31 + b354a8c commit 585961d
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 2 deletions.
31 changes: 31 additions & 0 deletions tests/points/admin/test_location_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest

from django.contrib.admin.sites import AdminSite
from django.contrib.gis.geos import Point

from wazimap_ng.points.models import Location
from wazimap_ng.points.admin import LocationAdmin

from tests.points import factoryboy as points_factoryboy

@pytest.fixture()
def test_location():
point = Point(0,0)
return points_factoryboy.LocationFactory(name="Test Location", coordinates=point)

from django.urls import reverse
def test(admin_user, rf, test_location):
url = reverse("admin:points_location_add")
request = rf.get(url)
request.user = admin_user
location_admin = LocationAdmin(model=Location, admin_site=AdminSite())
location_form = location_admin.get_form(request)

form = location_form(data={
"name": test_location.name,
"coordinates": test_location.coordinates,
"category": test_location.category
})

assert "image" not in form.errors
assert "data" not in form.errors
32 changes: 32 additions & 0 deletions tests/points/factoryboy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import factory

from tests.profile.factoryboy import ProfileFactory
from wazimap_ng.points import models


class ThemeFactory(factory.django.DjangoModelFactory):
class Meta:
model = models.Theme

profile = factory.SubFactory(ProfileFactory)

class CategoryFactory(factory.django.DjangoModelFactory):
class Meta:
model = models.Category

profile = factory.SubFactory(ProfileFactory)


class LocationFactory(factory.django.DjangoModelFactory):
class Meta:
model = models.Location

category = factory.SubFactory(CategoryFactory)

class ProfileCategory(factory.django.DjangoModelFactory):
class Meta:
model = models.ProfileCategory

theme = factory.SubFactory(ThemeFactory)
category = factory.SubFactory(CategoryFactory)
profile = factory.SubFactory(ProfileFactory)
20 changes: 20 additions & 0 deletions wazimap_ng/datasets/migrations/0109_auto_20200928_2255.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 2.2.13 on 2020-09-28 22:55

import django.core.validators
from django.db import migrations, models
import wazimap_ng.datasets.models.upload


class Migration(migrations.Migration):

dependencies = [
('datasets', '0108_auto_20200805_1449'),
]

operations = [
migrations.AlterField(
model_name='datasetfile',
name='document',
field=models.FileField(help_text='\n Uploaded document should be less than 3000.0 MiB in size and \n file extensions should be one of xls, xlsx, csv.\n ', upload_to=wazimap_ng.datasets.models.upload.get_file_path, validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['xls', 'xlsx', 'csv']), wazimap_ng.datasets.models.upload.file_size]),
),
]
25 changes: 25 additions & 0 deletions wazimap_ng/points/migrations/0036_auto_20200928_2255.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.2.13 on 2020-09-28 22:55

import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
import wazimap_ng.points.models


class Migration(migrations.Migration):

dependencies = [
('points', '0035_remove_profilecategory_permission_type'),
]

operations = [
migrations.AlterField(
model_name='location',
name='data',
field=django.contrib.postgres.fields.jsonb.JSONField(default=dict),
),
migrations.AlterField(
model_name='location',
name='image',
field=models.ImageField(blank=True, help_text='Optional image for point', null=True, upload_to=wazimap_ng.points.models.get_file_path),
),
]
19 changes: 19 additions & 0 deletions wazimap_ng/points/migrations/0037_auto_20200928_2309.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.13 on 2020-09-28 23:09

import django.contrib.postgres.fields.jsonb
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('points', '0036_auto_20200928_2255'),
]

operations = [
migrations.AlterField(
model_name='location',
name='data',
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict),
),
]
5 changes: 3 additions & 2 deletions wazimap_ng/points/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ class Location(BaseModel):
name = models.CharField(max_length=255)
category = models.ForeignKey(Category, related_name="locations", on_delete=models.CASCADE, verbose_name="collection")
coordinates = models.PointField()
data = JSONField()
data = JSONField(default=dict, blank=True)
url = models.CharField(max_length=150, null=True, blank=True, help_text="Optional url for this point")
image = models.ImageField(
upload_to=get_file_path,
help_text="Optional image for point",
null=True
null=True,
blank=True
)

def __str__(self):
Expand Down

0 comments on commit 585961d

Please sign in to comment.