Skip to content

Commit e832408

Browse files
committed
Added EuropeCountry.reports_can_be_published
1 parent 8349b5b commit e832408

File tree

4 files changed

+103
-4
lines changed

4 files changed

+103
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.2.25 on 2025-07-04 14:07
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('tigaserver_app', '0082_remove_iascore'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='europecountry',
15+
name='reports_can_be_published',
16+
field=models.BooleanField(default=True),
17+
),
18+
]

tigaserver_app/models.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,8 @@ class EuropeCountry(models.Model):
662662
pending_crisis_reports = models.IntegerField(blank=True, null=True, help_text='Number of reports in country assignable to non-supervisors')
663663
last_crisis_report_n_update = models.DateTimeField(help_text="Last time count was updated", null=True, blank=True)
664664

665+
reports_can_be_published = models.BooleanField(default=True)
666+
665667
class Meta:
666668
managed = True
667669
ordering = ['name_engl']
@@ -2069,10 +2071,7 @@ def save(self, *args, **kwargs):
20692071
getattr(self, fname) for fname in bite_fieldnames
20702072
)
20712073

2072-
if self.type not in self.PUBLISHABLE_TYPES:
2073-
self.published_at = None
2074-
2075-
if not self.is_browsable:
2074+
if (self.type not in self.PUBLISHABLE_TYPES) or (not self.is_browsable) or (self.country and not self.country.reports_can_be_published):
20762075
self.published_at = None
20772076

20782077
super(Report, self).save(*args, **kwargs)

tigaserver_app/tests/tests.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime, timedelta
2+
import pytest
23
import uuid
34

45
# Create your tests here.
@@ -2027,6 +2028,29 @@ def test_bite_is_published_on_create(self):
20272028
self.assertEqual(report.published_at, timezone.now())
20282029
self.assertEqual(report.published, True)
20292030

2031+
@time_machine.travel("2024-01-01 00:00:00", tick=False)
2032+
def test_bite_is_not_published_if_country_does_not_allow_public_on_create(self):
2033+
disabled_publish_country = EuropeCountry.objects.create(
2034+
cntr_id="RD", name_engl="Random", iso3_code="RND", fid="RD",
2035+
geom=MultiPolygon(Polygon.from_bbox((-10.0, 35.0, 3.5, 44.0))),
2036+
reports_can_be_published=False,
2037+
)
2038+
point_on_surface = disabled_publish_country.geom.point_on_surface
2039+
report = Report.objects.create(
2040+
user=TigaUser.objects.create(),
2041+
report_id='1234',
2042+
phone_upload_time=timezone.now(),
2043+
creation_time=timezone.now(),
2044+
version_time=timezone.now(),
2045+
type=Report.TYPE_BITE,
2046+
location_choice=Report.LOCATION_CURRENT,
2047+
current_location_lon=point_on_surface.x,
2048+
current_location_lat=point_on_surface.y,
2049+
)
2050+
self.assertEqual(report.country, disabled_publish_country)
2051+
self.assertIsNone(report.published_at)
2052+
self.assertEqual(report.published, False)
2053+
20302054
def test_breeding_site_with_picture_is_published_in_two_days_on_create(self):
20312055
with time_machine.travel("2024-01-01 00:00:00", tick=False) as traveller:
20322056
report = Report.objects.create(
@@ -2065,6 +2089,29 @@ def test_breeding_site_without_picture_is_published_on_create(self):
20652089
self.assertEqual(report.published_at, timezone.now())
20662090
self.assertEqual(report.published, True)
20672091

2092+
@time_machine.travel("2024-01-01 00:00:00", tick=False)
2093+
def test_breeding_site_without_picture_is_not_published_if_country_does_not_allow_public_on_create(self):
2094+
disabled_publish_country = EuropeCountry.objects.create(
2095+
cntr_id="RD", name_engl="Random", iso3_code="RND", fid="RD",
2096+
geom=MultiPolygon(Polygon.from_bbox((-10.0, 35.0, 3.5, 44.0))),
2097+
reports_can_be_published=False,
2098+
)
2099+
point_on_surface = disabled_publish_country.geom.point_on_surface
2100+
report = Report.objects.create(
2101+
user=TigaUser.objects.create(),
2102+
report_id='1234',
2103+
phone_upload_time=timezone.now(),
2104+
creation_time=timezone.now(),
2105+
version_time=timezone.now(),
2106+
type=Report.TYPE_SITE,
2107+
location_choice=Report.LOCATION_CURRENT,
2108+
current_location_lon=point_on_surface.x,
2109+
current_location_lat=point_on_surface.y,
2110+
)
2111+
self.assertEqual(report.country, disabled_publish_country)
2112+
self.assertIsNone(report.published_at)
2113+
self.assertEqual(report.published, False)
2114+
20682115
def test_adult_without_picture_is_published_on_create(self):
20692116
report = Report.objects.create(
20702117
user=TigaUser.objects.create(),
@@ -2079,6 +2126,29 @@ def test_adult_without_picture_is_published_on_create(self):
20792126
)
20802127
self.assertEqual(report.published, True)
20812128

2129+
@time_machine.travel("2024-01-01 00:00:00", tick=False)
2130+
def test_adult_without_picture_is_not_published_if_country_does_not_allow_public_on_create(self):
2131+
disabled_publish_country = EuropeCountry.objects.create(
2132+
cntr_id="RD", name_engl="Random", iso3_code="RND", fid="RD",
2133+
geom=MultiPolygon(Polygon.from_bbox((-10.0, 35.0, 3.5, 44.0))),
2134+
reports_can_be_published=False,
2135+
)
2136+
point_on_surface = disabled_publish_country.geom.point_on_surface
2137+
report = Report.objects.create(
2138+
user=TigaUser.objects.create(),
2139+
report_id='1234',
2140+
phone_upload_time=timezone.now(),
2141+
creation_time=timezone.now(),
2142+
version_time=timezone.now(),
2143+
type=Report.TYPE_ADULT,
2144+
location_choice=Report.LOCATION_CURRENT,
2145+
current_location_lon=point_on_surface.x,
2146+
current_location_lat=point_on_surface.y,
2147+
)
2148+
self.assertEqual(report.country, disabled_publish_country)
2149+
self.assertIsNone(report.published_at)
2150+
self.assertEqual(report.published, False)
2151+
20822152
def test_adult_with_picture_is_not_published_on_create(self):
20832153
report = Report.objects.create(
20842154
user=TigaUser.objects.create(),

util_scripts/make_data_euro_newmap.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ def move_masked_location_report_to_trash_layer(cursor):
214214
cursor.execute("""UPDATE map_aux_reports_newmap set private_webmap_layer='trash_layer' WHERE version_uuid=%s;""",
215215
(uuid,))
216216

217+
def move_not_publsihed_report_to_trash_layer(cursor):
218+
cursor.execute("""
219+
UPDATE map_aux_reports_newmap
220+
SET private_webmap_layer = 'trash_layer'
221+
WHERE version_uuid IN (
222+
SELECT "version_UUID"
223+
FROM tigaserver_app_report
224+
WHERE published_at IS NULL OR published_at > NOW()
225+
);
226+
""")
227+
217228
def add_photo_to_not_yet_filtered_adults(cursor):
218229
cursor.execute(
219230
"""SELECT m.version_uuid,p.photo FROM map_aux_reports_newmap m,tigaserver_app_photo p WHERE p.report_id = m.version_uuid and private_webmap_layer='not_yet_validated' and n_photos > 0 and photo_url='' and p.hide=false;""")
@@ -764,6 +775,7 @@ def get_storm_drain_status(report_responses):
764775
add_photo_to_not_yet_filtered_adults(cursor)
765776
move_hidden_adult_report_to_trash_layer(cursor)
766777
move_masked_location_report_to_trash_layer(cursor)
778+
move_not_publsihed_report_to_trash_layer(cursor)
767779

768780
cursor.execute(
769781
"""UPDATE map_aux_reports_newmap set validation=1 where expert_validated=1;""")

0 commit comments

Comments
 (0)