Skip to content

Commit

Permalink
Update old Python 2 formatting to Python 3 formatting.
Browse files Browse the repository at this point in the history
* Also add new migration for Django 2
  • Loading branch information
mimischi committed Dec 30, 2017
1 parent 9db1218 commit a6cae48
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 83 deletions.
2 changes: 1 addition & 1 deletion geomat/contrib/sites/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Migration(migrations.Migration):
'ordering': ('domain',),
},
managers=[
(b'objects', django.contrib.sites.models.SiteManager()),
('objects', django.contrib.sites.models.SiteManager()),
],
),
]
2 changes: 1 addition & 1 deletion geomat/contrib/sites/migrations/0004_auto_20171020_0922.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-20 09:22
from __future__ import unicode_literals


import django.contrib.sites.models
from django.db import migrations
Expand Down
2 changes: 1 addition & 1 deletion geomat/stein/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
MineralType,
Photograph,
QuizAnswer,
QuizQuestion
QuizQuestion,
)


Expand Down
103 changes: 62 additions & 41 deletions geomat/stein/migrations/0007_auto_20160615_2017.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-06-15 20:17


from django.db import migrations, models


Expand All @@ -14,86 +12,109 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='mineraltype',
name='cleavage2',
field=models.CharField(blank=True, choices=[(b'PE', 'Perfect'), (b'LP', 'Less perfect'), (b'GO', 'Good'),
(b'DI', 'Distinct'), (b'ID', 'Indistinct'), (b'NO', 'None')],
max_length=2, verbose_name='cleavage 2'),
),
field=models.CharField(
blank=True,
choices=[('PE', 'Perfect'), ('LP', 'Less perfect'),
('GO', 'Good'), ('DI', 'Distinct'),
('ID', 'Indistinct'), ('NO', 'None')],
max_length=2,
verbose_name='cleavage 2'), ),
migrations.AddField(
model_name='mineraltype',
name='density',
field=models.CharField(default=0, max_length=20, verbose_name='density'),
),
field=models.CharField(
default=0, max_length=20, verbose_name='density'), ),
migrations.AddField(
model_name='mineraltype',
name='fracture2',
field=models.CharField(blank=True, choices=[(b'CF', 'Conchoidal'), (b'EF', 'Earthy'), (b'HF', 'Hackly'),
(b'SF', 'Splintery'), (b'UF', 'Uneven')], max_length=2,
verbose_name='fracture 2'),
),
field=models.CharField(
blank=True,
choices=[('CF', 'Conchoidal'), ('EF', 'Earthy'),
('HF', 'Hackly'), ('SF', 'Splintery'), ('UF',
'Uneven')],
max_length=2,
verbose_name='fracture 2'), ),
migrations.AddField(
model_name='mineraltype',
name='lustre2',
field=models.CharField(blank=True, choices=[(b'AM', 'Adamantine'), (b'DL', 'Dull'), (b'GR', 'Greasy'),
(b'MT', 'Metallic'), (b'PY', 'Pearly'), (b'SL', 'Silky'),
(b'SM', 'Submetallic'), (b'VT', 'Vitreous'), (b'WY', 'Waxy')],
max_length=2, verbose_name='lustre 2'),
),
field=models.CharField(
blank=True,
choices=[('AM', 'Adamantine'), ('DL', 'Dull'), ('GR',
'Greasy'),
('MT', 'Metallic'), ('PY', 'Pearly'), ('SL', 'Silky'),
('SM', 'Submetallic'), ('VT', 'Vitreous'), ('WY',
'Waxy')],
max_length=2,
verbose_name='lustre 2'), ),
migrations.AddField(
model_name='mineraltype',
name='other',
field=models.CharField(blank=True, max_length=100, verbose_name='other'),
),
field=models.CharField(
blank=True, max_length=100, verbose_name='other'), ),
migrations.AddField(
model_name='mineraltype',
name='resource_mindat',
field=models.CharField(blank=True, max_length=100, verbose_name='MinDat ID'),
),
field=models.CharField(
blank=True, max_length=100, verbose_name='MinDat ID'), ),
migrations.AddField(
model_name='mineraltype',
name='resource_mineralienatlas',
field=models.CharField(blank=True, max_length=100, verbose_name='MineralienAtlas ID'),
field=models.CharField(
blank=True, max_length=100, verbose_name='MineralienAtlas ID'),
),
migrations.AddField(
model_name='mineraltype',
name='systematics',
field=models.CharField(
choices=[(b'EL', 'Elements'), (b'SF', 'Sulfides & Sulfosalts'), (b'HG', 'Halogenides'),
(b'OH', 'Oxides and Hydroxides'), (b'CN', 'Carbonates and Nitrates'), (b'BR', 'Borates'),
(b'SL', 'Sulfates'), (b'PV', 'Phosphates, Arsenates & Vanadates'),
(b'SG', 'Silicates & Germanates'), (b'OC', 'Organic Compounds')], default=b'EL', max_length=2,
verbose_name='systematics'),
),
choices=[('EL', 'Elements'), ('SF', 'Sulfides & Sulfosalts'),
('HG', 'Halogenides'), ('OH',
'Oxides and Hydroxides'),
('CN', 'Carbonates and Nitrates'), ('BR', 'Borates'),
('SL',
'Sulfates'), ('PV',
'Phosphates, Arsenates & Vanadates'),
('SG',
'Silicates & Germanates'), ('OC',
'Organic Compounds')],
default='EL',
max_length=2,
verbose_name='systematics'), ),
migrations.AlterField(
model_name='handpiece',
name='current_location',
field=models.CharField(blank=True, max_length=200, verbose_name='current location'),
field=models.CharField(
blank=True, max_length=200, verbose_name='current location'),
),
migrations.AlterField(
model_name='handpiece',
name='finding_place',
field=models.CharField(blank=True, max_length=200, verbose_name='place of discovery'),
field=models.CharField(
blank=True, max_length=200, verbose_name='place of discovery'),
),
migrations.AlterField(
model_name='mineraltype',
name='crystal_system',
field=models.CharField(blank=True,
choices=[(b'TC', 'Triclinic'), (b'MC', 'Monoclinic'), (b'OR', 'Orthorhombic'),
(b'TT', 'Tetragonal'), (b'TR', 'Trigonal'), (b'HG', 'Hexagonal'),
(b'CB', 'Cubic')], max_length=2, verbose_name='crystal system'),
),
field=models.CharField(
blank=True,
choices=[('TC', 'Triclinic'), ('MC', 'Monoclinic'),
('OR', 'Orthorhombic'), ('TT', 'Tetragonal'),
('TR', 'Trigonal'), ('HG', 'Hexagonal'), ('C',
'Cubic')],
max_length=2,
verbose_name='crystal system'), ),
migrations.AlterField(
model_name='mineraltype',
name='minerals',
field=models.CharField(blank=True, max_length=100, verbose_name='minerals'),
),
field=models.CharField(
blank=True, max_length=100, verbose_name='minerals'), ),
migrations.AlterField(
model_name='mineraltype',
name='trivial_name',
field=models.CharField(blank=True, max_length=100, verbose_name='trivial name'),
),
field=models.CharField(
blank=True, max_length=100, verbose_name='trivial name'), ),
migrations.AlterField(
model_name='mineraltype',
name='variety',
field=models.CharField(blank=True, max_length=100, verbose_name='variety'),
),
field=models.CharField(
blank=True, max_length=100, verbose_name='variety'), ),
]
2 changes: 1 addition & 1 deletion geomat/stein/migrations/0035_auto_20171020_0922.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-20 09:22
from __future__ import unicode_literals


import django.contrib.postgres.fields
from django.db import migrations, models
Expand Down
13 changes: 8 additions & 5 deletions geomat/stein/tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
from rest_framework import status
from rest_framework.test import APIClient

from geomat.stein.models import Classification, CrystalSystem, Handpiece, MineralType, Photograph
from geomat.stein.models import (
Classification,
CrystalSystem,
Handpiece,
MineralType,
Photograph,
)
from geomat.stein.serializers import StdImageField

# Helper functions


def convert(input):
if isinstance(input, dict):
return {
convert(key): convert(value)
for key, value in list(input.items())
}
return {convert(key): convert(value) for key, value in input.items()}
elif isinstance(input, list):
return [convert(element) for element in input]
elif isinstance(input, str):
Expand Down
45 changes: 34 additions & 11 deletions geomat/stein/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
MineralType,
Photograph,
QuizAnswer,
QuizQuestion
QuizQuestion,
)
from geomat.stein.serializers import (
ClassificationSerializer,
Expand All @@ -28,7 +28,7 @@
MineralTypeSerializer,
PhotographSerializer,
QuizAnswerFullSerializer,
QuizQuestionFullSerializer
QuizQuestionFullSerializer,
)


Expand Down Expand Up @@ -66,28 +66,30 @@ class ListFilterAPIView(generics.ListAPIView):
""" A View which creates a filters dict and returns a List of objects matching alle given Filters.
View only for Retrieving Data."""
varchar_fields = (
) # Tupel containing all modelfileds which are varcharfields
int_fields = () # Tupel containing all modelfileds which are integerfields
) # Tupel containing all modelfileds which are varcharfields
int_fields = (
) # Tupel containing all modelfileds which are integerfields
model_fields = (
) # Tupel containing all modelfileds which are Model relation fields those are also ints
) # Tupel containing all modelfileds which are Model relation fields those are also ints

def get_filters(self):
""" Method which creates the filters dict.
Matches the given Parameters from the request with the allowed lookup_fields, and only maps non-empty fields.
"""
filters = {}
for field in self.lookup_field: # goes on for every field we defined as lookup_field
for field in self.lookup_field: # goes on for every field we defined as lookup_field
if self.request.GET.get(field, None):
if field in self.varchar_fields: # we do not want the filter to contain "empty" fields
if field in self.varchar_fields: # we do not want the filter to contain "empty" fields
filters[field] = ast.literal_eval(
self.request.GET.get(field, None))
elif field in self.int_fields: # Modelreferences are searched by pk
elif field in self.int_fields: # Modelreferences are searched by pk
filters[field] = int(self.request.GET.get(field, None))
elif field in self.model_fields:
filters[field] = int(self.request.GET.get(field, None))
else:
filters[field] = self.request.GET.get(
field, None) # get the value of the field from request
field,
None) # get the value of the field from request

return filters

Expand Down Expand Up @@ -241,8 +243,29 @@ class FilterPhotographList(ListFilterAPIView):
# API View for the Mineraltype Profiles
class MineraltypeProfiles(generics.ListAPIView):
queryset = MineralType.objects.all()
serializer_class = MineralProfilesSerializer
name = 'mineraltype-profiles'
serializer_class = MineralTypeSerializer
name = 'mineral-profiles'

def get(self, request, *args, **kwargs):

categories = MineralType.MINERAL_CATEGORIES
data = {}

for cat in categories:
cat_string = cat[0]
classification = Classification.objects.filter(
mineral_type__systematics=cat_string).all()
human_string = cat[1]
data[str(human_string)] = {}
for clas in classification:
minerals = MineralType.objects.filter(
systematics=cat_string, classification=clas).all()

data[str(human_string)][
clas.classification_name] = MineralTypeSerializer(
minerals, many=True).data

return Response(data=data)


# Api View for the Glossary
Expand Down
Loading

0 comments on commit a6cae48

Please sign in to comment.