-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from legiongis/land_manager_update
Land Manager account improvements; site-filter refactor; and more...
- Loading branch information
Showing
30 changed files
with
2,391 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
from django.contrib.gis import admin | ||
from fpan.models.region import Region | ||
from fpan.models.managedarea import ManagedArea | ||
from fpan.models import Region, ManagedArea | ||
|
||
class ManagedAreaAdmin(admin.GeoModelAdmin): | ||
|
||
search_fields = ["name"] | ||
|
||
admin.site.register(Region, admin.GeoModelAdmin) | ||
admin.site.register(ManagedArea, ManagedAreaAdmin) | ||
# admin.site.register(Region, admin.GeoModelAdmin) | ||
# admin.site.register(ManagedArea, ManagedAreaAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[ | ||
{ | ||
"model": "fpan.agency", | ||
"fields": { | ||
"code": "fsp", | ||
"name": "FL Dept. of Environmental Protection, Div. of Recreation and Parks" | ||
} | ||
}, | ||
{ | ||
"model": "fpan.agency", | ||
"fields": { | ||
"code": "ffs", | ||
"name": "FL Dept. of Agriculture and Consumer Services, Florida Forest Service" | ||
} | ||
}, | ||
{ | ||
"model": "fpan.agency", | ||
"fields": { | ||
"code": "fwcc", | ||
"name": "FL Fish and Wildlife Conservation Commission" | ||
} | ||
}, | ||
{ | ||
"model": "fpan.agency", | ||
"fields": { | ||
"code": "fco", | ||
"name": "FL Dept. of Environmental Protection, Florida Coastal Office" | ||
} | ||
}, | ||
{ | ||
"model": "fpan.agency", | ||
"fields": { | ||
"code": "owp", | ||
"name": "FL Dept. of Environmental Protection, Office of Water Policy" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[ | ||
{ | ||
"model": "fpan.managementareatype", | ||
"fields": { | ||
"name": "State Park" | ||
} | ||
}, | ||
{ | ||
"model": "fpan.managementareatype", | ||
"fields": { | ||
"name": "County Park" | ||
} | ||
}, | ||
{ | ||
"model": "fpan.managementareatype", | ||
"fields": { | ||
"name": "State Forest" | ||
} | ||
}, | ||
{ | ||
"model": "fpan.managementareatype", | ||
"fields": { | ||
"name": "Aquatic Preserve" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import os | ||
import csv | ||
from django.conf import settings | ||
from django.core.management.base import BaseCommand, CommandError | ||
from arches.app.models.resource import Resource | ||
from arches.app.models.graph import Graph | ||
from arches.app.search.search_engine_factory import SearchEngineInstance as se | ||
|
||
class Command(BaseCommand): | ||
|
||
help = 'Checks the current ElasticSearch resource index against the ORM '\ | ||
'objects and prints a list of missing resources to the logs directory.' | ||
|
||
def add_arguments(self, parser): | ||
|
||
parser.add_argument("--index", | ||
action="store_true", | ||
default=False, | ||
help="attempt to index resources that aren't in index." | ||
) | ||
|
||
def handle(self, *args, **options): | ||
|
||
es_contents = self.get_es_contents() | ||
|
||
graphs = Graph.objects.filter(isresource=True).exclude(name="Arches System Settings") | ||
|
||
for graph in graphs: | ||
|
||
print(graph.name) | ||
|
||
missing = [] | ||
uuid_resids = Resource.objects.filter(graph=graph).values_list('resourceinstanceid', flat=True) | ||
db_resourceids = set([str(i) for i in uuid_resids]) | ||
|
||
try: | ||
es_resourceids = es_contents[str(graph.pk)] | ||
except KeyError: | ||
es_resourceids = set() | ||
|
||
print(f"- in db: {len(db_resourceids)}") | ||
print(f"- in index: {len(es_resourceids)}") | ||
if db_resourceids != es_resourceids: | ||
es_diff = list(es_resourceids - db_resourceids) | ||
if len(es_diff) > 0: | ||
print(f" {len(es_diff)} indexed resources not in db:") | ||
[print(" " + i) for i in es_diff[:5]] | ||
if len(es_diff) > 5: | ||
print(" ...") | ||
db_diff = list(db_resourceids - es_resourceids) | ||
if len(db_diff) > 0: | ||
print(f" {len(db_diff)} db resources not in index:") | ||
[print(" " + i) for i in db_diff[:5]] | ||
if len(db_diff) > 5: | ||
print(" ...") | ||
if options["index"]: | ||
print(" indexing these resources now...") | ||
for id in db_diff: | ||
r = Resource.objects.get(pk=id) | ||
try: | ||
r.index() | ||
except Exception as e: | ||
print(e) | ||
break | ||
|
||
|
||
|
||
def get_es_contents(self): | ||
|
||
summary = dict() | ||
for resinfo in self.iterate_all_documents(se, 'resources'): | ||
resid, graphid = resinfo | ||
if graphid != 'None': | ||
if graphid in summary: | ||
summary[graphid].add(resid) | ||
else: | ||
summary[graphid] = set([resid]) | ||
return summary | ||
|
||
def iterate_all_documents(self, se, index, pagesize=250, scroll_timeout="1m"): | ||
""" | ||
Helper to iterate ALL values from a single index. Yields all the documents. | ||
https://techoverflow.net/2019/05/07/elasticsearch-how-to-iterate-scroll-through-all-documents-in-index/ | ||
""" | ||
is_first = True | ||
while True: | ||
# Scroll next | ||
if is_first: # Initialize scroll | ||
result = se.search(index=index, scroll="1m", body={ | ||
"size": pagesize | ||
}) | ||
is_first = False | ||
else: | ||
## note: need to access the ElasticSearch() instance directly | ||
## here, (.es), because the Arches se object doesn't inherit .scroll() | ||
result = se.es.scroll(body={ | ||
"scroll_id": scroll_id, | ||
"scroll": scroll_timeout | ||
}) | ||
scroll_id = result["_scroll_id"] | ||
hits = result["hits"]["hits"] | ||
# Stop after no more docs | ||
if not hits: | ||
break | ||
# Yield each entry | ||
yield from ((hit['_source']['resourceinstanceid'], hit['_source']['graph_id']) for hit in hits) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.