-
Notifications
You must be signed in to change notification settings - Fork 55
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 #524 from SEED-platform/434-develop-labels
434 develop labels
- Loading branch information
Showing
83 changed files
with
3,068 additions
and
1,869 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
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 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 |
---|---|---|
|
@@ -80,3 +80,4 @@ wsgiref==0.1.2 | |
xlrd==0.9.3 | ||
xlwt==0.7.5 | ||
xmltodict==0.9.0 | ||
djangorestframework==3.3.1 |
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,25 @@ | ||
from rest_framework import authentication | ||
from rest_framework import exceptions | ||
|
||
|
||
class SEEDAuthentication(authentication.BaseAuthentication): | ||
""" | ||
Django Rest Framework implementation of the | ||
`seed.utils.api.get_api_request_user` functionality to extract the User | ||
from the HTTP_AUTHORIZATION header using an API key. | ||
""" | ||
def authenticate(self, request): | ||
auth_header = request.META.get('HTTP_AUTHORIZATION') | ||
|
||
if not auth_header: | ||
return None | ||
|
||
try: | ||
from seed.landing.models import SEEDUser as User | ||
username, api_key = auth_header.split(':') | ||
user = User.objects.get(api_key=api_key, username=username) | ||
return user, api_key | ||
except ValueError: | ||
raise exceptions.AuthenticationFailed("Invalid HTTP_AUTHORIZATION Header") | ||
except User.DoesNotExist: | ||
raise exceptions.AuthenticationFailed("Invalid API key") |
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,46 @@ | ||
import json | ||
|
||
from rest_framework import filters | ||
|
||
from seed import search | ||
|
||
|
||
class LabelFilterBackend(filters.BaseFilterBackend): | ||
def filter_queryset(self, request, queryset, view): | ||
if 'organization_id' in request.query_params: | ||
return queryset.filter( | ||
super_organization_id=request.query_params['organization_id'], | ||
) | ||
return queryset | ||
|
||
|
||
class BuildingFilterBackend(filters.BaseFilterBackend): | ||
""" | ||
Implements the filtering and searching of buildings as a Django Rest | ||
Framework filter backend. | ||
""" | ||
def filter_queryset(self, request, queryset, view): | ||
# TODO: this needs to be filled in with the same logic that implements | ||
# search/filtering in `seed.views.main.search_buildings`. | ||
params = request.query_params.dict() | ||
# Since this is being passed in as a query string, the object ends up | ||
# coming through as a string. | ||
params['filter_params'] = json.loads(params.get('filter_params', '{}')) | ||
|
||
params = search.process_search_params( | ||
params=params, | ||
user=request.user, | ||
is_api_request=True, | ||
) | ||
buildings_queryset = search.orchestrate_search_filter_sort( | ||
params=params, | ||
user=request.user, | ||
) | ||
|
||
if request.query_params.get('select_all_checkbox', 'false') == 'true': | ||
pass | ||
elif 'selected_buildings' in request.query_params: | ||
return buildings_queryset.filter( | ||
id__in=request.query_params.getlist('selected_buildings'), | ||
) | ||
return buildings_queryset |
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,20 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('seed', '0003_auto_20151105_1539'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='statuslabel', | ||
name='color', | ||
field=models.CharField(default=b'green', max_length=30, verbose_name='compliance_type', choices=[(b'red', 'red'), (b'blue', 'blue'), (b'light blue', 'light blue'), (b'green', 'green'), (b'white', 'white'), (b'orange', 'orange'), (b'gray', 'gray')]), | ||
preserve_default=True, | ||
), | ||
] |
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,23 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('seed', '0003_auto_20151105_1539'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='NonCanonicalProjectBuildings', | ||
fields=[ | ||
('projectbuilding', models.ForeignKey(primary_key=True, serialize=False, to='seed.ProjectBuilding')), | ||
], | ||
options={ | ||
}, | ||
bases=(models.Model,), | ||
), | ||
] |
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,25 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
#some of the project buildings point at building snapshot records that are not canonical buildings | ||
#This probably shouldn't be but before the migration for the label changes record them here | ||
#so the users can be alerted that the label changes will not be applied. | ||
def save_non_canonical_project_buildings(app, schema_editor): | ||
project_building_model = app.get_model("seed", "ProjectBuilding") | ||
canonical_building_model = app.get_model("seed", "CanonicalBuilding") | ||
non_canonical_project_buildings_model = app.get_model("seed", "NonCanonicalProjectBuildings") | ||
|
||
for building_with_labels in project_building_model.objects.filter(status_label__isnull=False): | ||
if not canonical_building_model.objects.filter(canonical_snapshot = building_with_labels.building_snapshot.id).exists(): | ||
non_canonical_project_buildings_model.objects.create(projectbuilding = building_with_labels) | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('seed', '0004_noncanonicalprojectbuildings'), | ||
] | ||
|
||
operations = [migrations.RunPython(save_non_canonical_project_buildings), | ||
] |
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,20 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('seed', '0005_auto_20151201_1510'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='canonicalbuilding', | ||
name='labels', | ||
field=models.ManyToManyField(to='seed.StatusLabel'), | ||
preserve_default=True, | ||
), | ||
] |
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,30 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
#assuming all building_snapshot_ids in seed_projectbuilding point at the canonical building | ||
#For any records that do no point at canonical buildings the labels will be dropped | ||
#but a record is kept via migration 005_auto_20151201_1510 | ||
def move_labels(app, schema_editor): | ||
project_building_model = app.get_model("seed", "ProjectBuilding") | ||
canonical_building_model = app.get_model("seed", "CanonicalBuilding") | ||
|
||
for building_with_labels in project_building_model.objects.filter(status_label__isnull=False): | ||
for canonical_building in canonical_building_model.objects.filter(canonical_snapshot = building_with_labels.building_snapshot.id): | ||
canonical_building.labels.add(building_with_labels.status_label) | ||
|
||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
|
||
dependencies = [ | ||
('seed', '0006_canonicalbuilding_labels'), | ||
] | ||
|
||
operations = [ migrations.RunPython(move_labels), | ||
] | ||
|
||
|
||
|
18 changes: 18 additions & 0 deletions
18
seed/migrations/0008_remove_projectbuilding_status_label.py
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,18 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('seed', '0007_auto_20151201_1515'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='projectbuilding', | ||
name='status_label', | ||
), | ||
] |
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,15 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('seed', '0008_remove_projectbuilding_status_label'), | ||
('seed', '0004_auto_20151201_1404'), | ||
] | ||
|
||
operations = [ | ||
] |
Oops, something went wrong.