From 3e5cc392336853539d8d095b71e726983f9dfb14 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Sun, 12 Jul 2020 19:10:06 +0000 Subject: [PATCH 01/74] Update Makefile with new dependencies --- Makefile | 1 + requirements.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3485be1d..84dc3d62 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ install: + apt install postgresql postgresql-server-dev-all gcc python-dev libmemcached-dev zlib1g-dev pip install -r requirements.txt build: diff --git a/requirements.txt b/requirements.txt index c389e7bd..72b2c17f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,7 @@ drf-json-api==0.1.0 gunicorn==19.1.1 keen==0.3.7 markdown2==2.3.0 -psycopg2==2.5.4 +psycopg2-binary pycrypto==2.6.1 pylibmc==1.4.1 requests==2.5.1 From 21008594ed87d8ed49386ab78821c18169a0b3f0 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 19:33:15 +0300 Subject: [PATCH 02/74] Add .idea to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8e1bef19..5cb228b7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ staticfiles .env db.sqlite3 .DS_Store +.idea \ No newline at end of file From f32238b689f6badd2d13e9aeeafb5873044dca3f Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 19:33:35 +0300 Subject: [PATCH 03/74] Remove old migrations --- resources/migrations/0001_initial.py | 182 ---------------- ...1_squashed_0005_remove_transport_pilots.py | 195 ------------------ .../migrations/0002_auto_20141213_1454.py | 24 --- .../migrations/0003_film_release_date.py | 21 -- resources/migrations/0004_editablemodel.py | 24 --- 5 files changed, 446 deletions(-) delete mode 100644 resources/migrations/0001_initial.py delete mode 100644 resources/migrations/0001_squashed_0005_remove_transport_pilots.py delete mode 100644 resources/migrations/0002_auto_20141213_1454.py delete mode 100644 resources/migrations/0003_film_release_date.py delete mode 100644 resources/migrations/0004_editablemodel.py diff --git a/resources/migrations/0001_initial.py b/resources/migrations/0001_initial.py deleted file mode 100644 index e11b9649..00000000 --- a/resources/migrations/0001_initial.py +++ /dev/null @@ -1,182 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Film', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('created', models.DateTimeField(auto_now_add=True)), - ('edited', models.DateTimeField(auto_now=True)), - ('title', models.CharField(max_length=100)), - ('episode_id', models.IntegerField(max_length=10)), - ('opening_crawl', models.TextField(max_length=1000)), - ('director', models.CharField(max_length=100)), - ('producer', models.CharField(max_length=100)), - ], - options={ - 'abstract': False, - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='People', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('created', models.DateTimeField(auto_now_add=True)), - ('edited', models.DateTimeField(auto_now=True)), - ('name', models.CharField(max_length=100)), - ('height', models.CharField(max_length=10, blank=True)), - ('mass', models.CharField(max_length=10, blank=True)), - ('hair_color', models.CharField(max_length=20, blank=True)), - ('skin_color', models.CharField(max_length=20, blank=True)), - ('eye_color', models.CharField(max_length=20, blank=True)), - ('birth_year', models.CharField(max_length=10, blank=True)), - ('gender', models.CharField(max_length=40, blank=True)), - ], - options={ - 'abstract': False, - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='Planet', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('created', models.DateTimeField(auto_now_add=True)), - ('edited', models.DateTimeField(auto_now=True)), - ('name', models.CharField(max_length=100)), - ('rotation_period', models.CharField(max_length=40)), - ('orbital_period', models.CharField(max_length=40)), - ('diameter', models.CharField(max_length=40)), - ('climate', models.CharField(max_length=40)), - ('gravity', models.CharField(max_length=40)), - ('terrain', models.CharField(max_length=40)), - ('surface_water', models.CharField(max_length=40)), - ('population', models.CharField(max_length=40)), - ], - options={ - 'abstract': False, - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='Species', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('created', models.DateTimeField(auto_now_add=True)), - ('edited', models.DateTimeField(auto_now=True)), - ('name', models.CharField(max_length=40)), - ('classification', models.CharField(max_length=40)), - ('designation', models.CharField(max_length=40)), - ('average_height', models.CharField(max_length=40)), - ('skin_colors', models.CharField(max_length=200)), - ('hair_colors', models.CharField(max_length=200)), - ('eye_colors', models.CharField(max_length=200)), - ('average_lifespan', models.CharField(max_length=40)), - ('language', models.CharField(max_length=40)), - ('homeworld', models.ForeignKey(to='resources.Planet', blank=True)), - ('people', models.ManyToManyField(related_name='species', to='resources.People')), - ], - options={ - 'abstract': False, - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='Transport', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('created', models.DateTimeField(auto_now_add=True)), - ('edited', models.DateTimeField(auto_now=True)), - ('name', models.CharField(max_length=40)), - ('model', models.CharField(max_length=40)), - ('manufacturer', models.CharField(max_length=80)), - ('cost_in_credits', models.CharField(max_length=40)), - ('length', models.CharField(max_length=40)), - ('max_atmosphering_speed', models.CharField(max_length=40)), - ('crew', models.CharField(max_length=40)), - ('passengers', models.CharField(max_length=40)), - ('cargo_capacity', models.CharField(max_length=40)), - ('consumables', models.CharField(max_length=40)), - ], - options={ - 'abstract': False, - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='Starship', - fields=[ - ('transport_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='resources.Transport')), - ('hyperdrive_rating', models.CharField(max_length=40)), - ('MGLT', models.CharField(max_length=40)), - ('starship_class', models.CharField(max_length=40)), - ], - options={ - 'abstract': False, - }, - bases=('resources.transport',), - ), - migrations.CreateModel( - name='Vehicle', - fields=[ - ('transport_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='resources.Transport')), - ('vehicle_class', models.CharField(max_length=40)), - ], - options={ - 'abstract': False, - }, - bases=('resources.transport',), - ), - migrations.AddField( - model_name='transport', - name='pilots', - field=models.ManyToManyField(related_name='transport', to='resources.People'), - preserve_default=True, - ), - migrations.AddField( - model_name='people', - name='homeworld', - field=models.ForeignKey(related_name='residents', to='resources.Planet'), - preserve_default=True, - ), - migrations.AddField( - model_name='film', - name='characters', - field=models.ManyToManyField(related_name='films', to='resources.People'), - preserve_default=True, - ), - migrations.AddField( - model_name='film', - name='planets', - field=models.ManyToManyField(related_name='films', to='resources.Planet'), - preserve_default=True, - ), - migrations.AddField( - model_name='film', - name='species', - field=models.ManyToManyField(related_name='films', to='resources.Species'), - preserve_default=True, - ), - migrations.AddField( - model_name='film', - name='starships', - field=models.ManyToManyField(related_name='films', to='resources.Starship'), - preserve_default=True, - ), - migrations.AddField( - model_name='film', - name='vehicles', - field=models.ManyToManyField(related_name='films', to='resources.Vehicle'), - preserve_default=True, - ), - ] diff --git a/resources/migrations/0001_squashed_0005_remove_transport_pilots.py b/resources/migrations/0001_squashed_0005_remove_transport_pilots.py deleted file mode 100644 index 1f058c11..00000000 --- a/resources/migrations/0001_squashed_0005_remove_transport_pilots.py +++ /dev/null @@ -1,195 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - replaces = [(b'resources', '0001_initial'), (b'resources', '0002_auto_20141210_1424'), (b'resources', '0003_auto_20141210_1516'), (b'resources', '0004_auto_20141213_1443'), (b'resources', '0005_remove_transport_pilots')] - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Film', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('created', models.DateTimeField(auto_now_add=True)), - ('edited', models.DateTimeField(auto_now=True)), - ('title', models.CharField(max_length=100)), - ('episode_id', models.IntegerField(max_length=10)), - ('opening_crawl', models.TextField(max_length=1000)), - ('director', models.CharField(max_length=100)), - ('producer', models.CharField(max_length=100)), - ], - options={ - 'abstract': False, - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='People', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('created', models.DateTimeField(auto_now_add=True)), - ('edited', models.DateTimeField(auto_now=True)), - ('name', models.CharField(max_length=100)), - ('height', models.CharField(max_length=10, blank=True)), - ('mass', models.CharField(max_length=10, blank=True)), - ('hair_color', models.CharField(max_length=20, blank=True)), - ('skin_color', models.CharField(max_length=20, blank=True)), - ('eye_color', models.CharField(max_length=20, blank=True)), - ('birth_year', models.CharField(max_length=10, blank=True)), - ('gender', models.CharField(max_length=40, blank=True)), - ], - options={ - 'abstract': False, - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='Planet', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('created', models.DateTimeField(auto_now_add=True)), - ('edited', models.DateTimeField(auto_now=True)), - ('name', models.CharField(max_length=100)), - ('rotation_period', models.CharField(max_length=40)), - ('orbital_period', models.CharField(max_length=40)), - ('diameter', models.CharField(max_length=40)), - ('climate', models.CharField(max_length=40)), - ('gravity', models.CharField(max_length=40)), - ('terrain', models.CharField(max_length=40)), - ('surface_water', models.CharField(max_length=40)), - ('population', models.CharField(max_length=40)), - ], - options={ - 'abstract': False, - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='Species', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('created', models.DateTimeField(auto_now_add=True)), - ('edited', models.DateTimeField(auto_now=True)), - ('name', models.CharField(max_length=40)), - ('classification', models.CharField(max_length=40)), - ('designation', models.CharField(max_length=40)), - ('average_height', models.CharField(max_length=40)), - ('skin_colors', models.CharField(max_length=200)), - ('hair_colors', models.CharField(max_length=200)), - ('eye_colors', models.CharField(max_length=200)), - ('average_lifespan', models.CharField(max_length=40)), - ('language', models.CharField(max_length=40)), - ('homeworld', models.ForeignKey(blank=True, to='resources.Planet', null=True)), - ('people', models.ManyToManyField(related_name='species', to=b'resources.People')), - ], - options={ - 'abstract': False, - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='Transport', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('created', models.DateTimeField(auto_now_add=True)), - ('edited', models.DateTimeField(auto_now=True)), - ('name', models.CharField(max_length=40)), - ('model', models.CharField(max_length=40)), - ('manufacturer', models.CharField(max_length=80)), - ('cost_in_credits', models.CharField(max_length=40)), - ('length', models.CharField(max_length=40)), - ('max_atmosphering_speed', models.CharField(max_length=40)), - ('crew', models.CharField(max_length=40)), - ('passengers', models.CharField(max_length=40)), - ('cargo_capacity', models.CharField(max_length=40)), - ('consumables', models.CharField(max_length=40)), - ], - options={ - 'abstract': False, - }, - bases=(models.Model,), - ), - migrations.CreateModel( - name='Starship', - fields=[ - ('transport_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='resources.Transport')), - ('hyperdrive_rating', models.CharField(max_length=40)), - ('MGLT', models.CharField(max_length=40)), - ('starship_class', models.CharField(max_length=40)), - ], - options={ - 'abstract': False, - }, - bases=('resources.transport',), - ), - migrations.CreateModel( - name='Vehicle', - fields=[ - ('transport_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='resources.Transport')), - ('vehicle_class', models.CharField(max_length=40)), - ], - options={ - 'abstract': False, - }, - bases=('resources.transport',), - ), - migrations.AddField( - model_name='people', - name='homeworld', - field=models.ForeignKey(related_name='residents', to='resources.Planet'), - preserve_default=True, - ), - migrations.AddField( - model_name='film', - name='characters', - field=models.ManyToManyField(related_name='films', to=b'resources.People', blank=True), - preserve_default=True, - ), - migrations.AddField( - model_name='film', - name='planets', - field=models.ManyToManyField(related_name='films', to=b'resources.Planet', blank=True), - preserve_default=True, - ), - migrations.AddField( - model_name='film', - name='species', - field=models.ManyToManyField(related_name='films', to=b'resources.Species', blank=True), - preserve_default=True, - ), - migrations.AddField( - model_name='film', - name='starships', - field=models.ManyToManyField(related_name='films', to=b'resources.Starship', blank=True), - preserve_default=True, - ), - migrations.AddField( - model_name='film', - name='vehicles', - field=models.ManyToManyField(related_name='films', to=b'resources.Vehicle', blank=True), - preserve_default=True, - ), - migrations.AddField( - model_name='starship', - name='new_pilots', - field=models.ManyToManyField(related_name='starships', to=b'resources.People', blank=True), - preserve_default=True, - ), - migrations.AddField( - model_name='vehicle', - name='new_pilots', - field=models.ManyToManyField(related_name='vehicles', to=b'resources.People', blank=True), - preserve_default=True, - ), - migrations.AlterField( - model_name='film', - name='episode_id', - field=models.IntegerField(), - ), - ] diff --git a/resources/migrations/0002_auto_20141213_1454.py b/resources/migrations/0002_auto_20141213_1454.py deleted file mode 100644 index f32cc793..00000000 --- a/resources/migrations/0002_auto_20141213_1454.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('resources', '0001_squashed_0005_remove_transport_pilots'), - ] - - operations = [ - migrations.RenameField( - model_name='starship', - old_name='new_pilots', - new_name='pilots', - ), - migrations.RenameField( - model_name='vehicle', - old_name='new_pilots', - new_name='pilots', - ), - ] diff --git a/resources/migrations/0003_film_release_date.py b/resources/migrations/0003_film_release_date.py deleted file mode 100644 index a521b369..00000000 --- a/resources/migrations/0003_film_release_date.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations -import django.utils.datetime_safe - - -class Migration(migrations.Migration): - - dependencies = [ - ('resources', '0002_auto_20141213_1454'), - ] - - operations = [ - migrations.AddField( - model_name='film', - name='release_date', - field=models.DateField(default=django.utils.datetime_safe.date.today), - preserve_default=False, - ), - ] diff --git a/resources/migrations/0004_editablemodel.py b/resources/migrations/0004_editablemodel.py deleted file mode 100644 index d384cdef..00000000 --- a/resources/migrations/0004_editablemodel.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('resources', '0003_film_release_date'), - ] - - operations = [ - migrations.CreateModel( - name='EditableModel', - fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('editable', models.NullBooleanField()), - ], - options={ - }, - bases=(models.Model,), - ), - ] From 96b4c584baab0edec6671cb22e9303c14df22bd4 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 19:34:05 +0300 Subject: [PATCH 04/74] Update ForeignKey`s with on_delete param --- resources/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/models.py b/resources/models.py index 758febd4..2ca096a4 100644 --- a/resources/models.py +++ b/resources/models.py @@ -69,7 +69,7 @@ def __unicode__(self): gender = models.CharField(max_length=40, blank=True) - homeworld = models.ForeignKey(Planet, related_name="residents") + homeworld = models.ForeignKey(Planet, related_name="residents", on_delete=models.PROTECT) class Transport(DateTimeModel): @@ -148,7 +148,7 @@ def __unicode__(self): average_lifespan = models.CharField(max_length=40) - homeworld = models.ForeignKey(Planet, blank=True, null=True) + homeworld = models.ForeignKey(Planet, blank=True, null=True, on_delete=models.PROTECT) language = models.CharField(max_length=40) From bee2a07b16d78d5a3eb36472b03428e68e19582b Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 19:34:36 +0300 Subject: [PATCH 05/74] Add new migrations --- resources/migrations/0001_initial.py | 157 +++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 resources/migrations/0001_initial.py diff --git a/resources/migrations/0001_initial.py b/resources/migrations/0001_initial.py new file mode 100644 index 00000000..e499503c --- /dev/null +++ b/resources/migrations/0001_initial.py @@ -0,0 +1,157 @@ +# Generated by Django 3.0.8 on 2020-07-16 16:09 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='EditableModel', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('editable', models.NullBooleanField()), + ], + ), + migrations.CreateModel( + name='People', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', models.DateTimeField(auto_now_add=True)), + ('edited', models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=100)), + ('height', models.CharField(blank=True, max_length=10)), + ('mass', models.CharField(blank=True, max_length=10)), + ('hair_color', models.CharField(blank=True, max_length=20)), + ('skin_color', models.CharField(blank=True, max_length=20)), + ('eye_color', models.CharField(blank=True, max_length=20)), + ('birth_year', models.CharField(blank=True, max_length=10)), + ('gender', models.CharField(blank=True, max_length=40)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Planet', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', models.DateTimeField(auto_now_add=True)), + ('edited', models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=100)), + ('rotation_period', models.CharField(max_length=40)), + ('orbital_period', models.CharField(max_length=40)), + ('diameter', models.CharField(max_length=40)), + ('climate', models.CharField(max_length=40)), + ('gravity', models.CharField(max_length=40)), + ('terrain', models.CharField(max_length=40)), + ('surface_water', models.CharField(max_length=40)), + ('population', models.CharField(max_length=40)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Transport', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', models.DateTimeField(auto_now_add=True)), + ('edited', models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=40)), + ('model', models.CharField(max_length=40)), + ('manufacturer', models.CharField(max_length=80)), + ('cost_in_credits', models.CharField(max_length=40)), + ('length', models.CharField(max_length=40)), + ('max_atmosphering_speed', models.CharField(max_length=40)), + ('crew', models.CharField(max_length=40)), + ('passengers', models.CharField(max_length=40)), + ('cargo_capacity', models.CharField(max_length=40)), + ('consumables', models.CharField(max_length=40)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Species', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', models.DateTimeField(auto_now_add=True)), + ('edited', models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=40)), + ('classification', models.CharField(max_length=40)), + ('designation', models.CharField(max_length=40)), + ('average_height', models.CharField(max_length=40)), + ('skin_colors', models.CharField(max_length=200)), + ('hair_colors', models.CharField(max_length=200)), + ('eye_colors', models.CharField(max_length=200)), + ('average_lifespan', models.CharField(max_length=40)), + ('language', models.CharField(max_length=40)), + ('homeworld', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='resources.Planet')), + ('people', models.ManyToManyField(related_name='species', to='resources.People')), + ], + options={ + 'abstract': False, + }, + ), + migrations.AddField( + model_name='people', + name='homeworld', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='residents', to='resources.Planet'), + ), + migrations.CreateModel( + name='Vehicle', + fields=[ + ('transport_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='resources.Transport')), + ('vehicle_class', models.CharField(max_length=40)), + ('pilots', models.ManyToManyField(blank=True, related_name='vehicles', to='resources.People')), + ], + options={ + 'abstract': False, + }, + bases=('resources.transport',), + ), + migrations.CreateModel( + name='Starship', + fields=[ + ('transport_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='resources.Transport')), + ('hyperdrive_rating', models.CharField(max_length=40)), + ('MGLT', models.CharField(max_length=40)), + ('starship_class', models.CharField(max_length=40)), + ('pilots', models.ManyToManyField(blank=True, related_name='starships', to='resources.People')), + ], + options={ + 'abstract': False, + }, + bases=('resources.transport',), + ), + migrations.CreateModel( + name='Film', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', models.DateTimeField(auto_now_add=True)), + ('edited', models.DateTimeField(auto_now=True)), + ('title', models.CharField(max_length=100)), + ('episode_id', models.IntegerField()), + ('opening_crawl', models.TextField(max_length=1000)), + ('director', models.CharField(max_length=100)), + ('producer', models.CharField(max_length=100)), + ('release_date', models.DateField()), + ('characters', models.ManyToManyField(blank=True, related_name='films', to='resources.People')), + ('planets', models.ManyToManyField(blank=True, related_name='films', to='resources.Planet')), + ('species', models.ManyToManyField(blank=True, related_name='films', to='resources.Species')), + ('starships', models.ManyToManyField(blank=True, related_name='films', to='resources.Starship')), + ('vehicles', models.ManyToManyField(blank=True, related_name='films', to='resources.Vehicle')), + ], + options={ + 'abstract': False, + }, + ), + ] From 31305ac48fa53286b0234d9364fcb5eb4dadfbd5 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 19:35:16 +0300 Subject: [PATCH 06/74] Remove DjangoWhiteNoise [deprecated] --- swapi/wsgi.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/swapi/wsgi.py b/swapi/wsgi.py index ba610a88..c33e4734 100644 --- a/swapi/wsgi.py +++ b/swapi/wsgi.py @@ -9,14 +9,9 @@ import os -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swapi.settings") from django.core.wsgi import get_wsgi_application -from whitenoise.django import DjangoWhiteNoise -# Fix django closing connection to MemCachier after every request (#11331) -from django.core.cache.backends.memcached import BaseMemcachedCache -BaseMemcachedCache.close = lambda self, **kwargs: None +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'swapi.settings') application = get_wsgi_application() -application = DjangoWhiteNoise(application) From 8f0e26852f6dbf420ccc3a259e184b635eb21a3e Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 19:35:31 +0300 Subject: [PATCH 07/74] Reformat render functions --- swapi/views.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/swapi/views.py b/swapi/views.py index 522d568a..df776e0a 100644 --- a/swapi/views.py +++ b/swapi/views.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals -from django.shortcuts import render_to_response, redirect +from django.shortcuts import render, redirect from django.views.decorators.csrf import csrf_exempt from django.core.cache import cache from django.conf import settings @@ -14,18 +14,12 @@ def index(request): - stripe_key = settings.STRIPE_KEYS['publishable'] - return render_to_response( - 'index.html', - { - "stripe_key": stripe_key - } - ) + return render(request, 'index.html', {"stripe_key": stripe_key}) def documentation(request): - return render_to_response("documentation.html") + return render(request, "documentation.html") def about(request): @@ -35,7 +29,7 @@ def about(request): data = get_resource_stats() cache.set('resource_data', data, 10000) data['stripe_key'] = stripe_key - return render_to_response( + return render(request, "about.html", data ) @@ -73,7 +67,7 @@ def stats(request): data = {} data['keen_project_id'] = settings.KEEN_PROJECT_ID data['keen_read_key'] = settings.KEEN_READ_KEY - return render_to_response( + return render(request, 'stats.html', data ) From 7ee9392bcc7ea12736f5a4f55c437dadb1a1d2a4 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 19:36:55 +0300 Subject: [PATCH 08/74] Updated settings.py with topical parameters --- swapi/settings.py | 101 ++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/swapi/settings.py b/swapi/settings.py index 41df3d12..fec08413 100644 --- a/swapi/settings.py +++ b/swapi/settings.py @@ -1,7 +1,6 @@ import os -import dj_database_url -BASE_DIR = os.path.dirname(os.path.dirname(__file__)) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = os.environ.get( 'SECRET_KEY', @@ -14,35 +13,35 @@ TEMPLATE_DEBUG = DEBUG -ALLOWED_HOSTS = [] - -CUSTOM_APPS = ( +CUSTOM_APPS = [ 'resources', 'rest_framework', 'markdown_deux', 'corsheaders', 'clear_cache', -) - -INSTALLED_APPS = ( - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.humanize', - 'django.contrib.staticfiles', -) + CUSTOM_APPS - -MIDDLEWARE_CLASSES = ( +] + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django.contrib.humanize', + ] + CUSTOM_APPS + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', - 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', -) + 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.security.SecurityMiddleware', +] ROOT_URLCONF = 'swapi.urls' @@ -62,36 +61,49 @@ USE_L10N = True USE_TZ = True -if not DEBUG: - DATABASES['default'] = dj_database_url.config() - - DATABASES['default']['ENGINE'] = 'django_postgrespool' +# if not DEBUG: +# DATABASES['default'] = dj_database_url.config() +# +# DATABASES['default']['ENGINE'] = 'django_postgrespool' SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') ALLOWED_HOSTS = ['*'] BASE_DIR = os.path.dirname(os.path.abspath(__file__)) -STATIC_ROOT = 'staticfiles' +STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), ) -TEMPLATE_DIRS = ( - os.path.join(BASE_DIR, 'templates'), -) - -CACHES = { - 'default': { - 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', - 'TIMEOUT': 60 - } -} +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + os.path.join(BASE_DIR, 'templates') + ], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] -STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' +# CACHES = { +# 'default': { +# 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', +# 'TIMEOUT': 60 +# } +# } +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' # Markdown @@ -140,12 +152,12 @@ if DEBUG: STRIPE_KEYS = { - "secret" :STRIPE_TEST_SECRET_KEY, + "secret": STRIPE_TEST_SECRET_KEY, "publishable": STRIPE_TEST_PUBLISHABLE_KEY } else: STRIPE_KEYS = { - "secret" :STRIPE_SECRET_KEY, + "secret": STRIPE_SECRET_KEY, "publishable": STRIPE_PUBLISHABLE_KEY } @@ -154,14 +166,5 @@ CORS_ORIGIN_ALLOW_ALL = True CORS_URLS_REGEX = r'^/api/.*$' CORS_ALLOW_METHODS = ( - 'GET', - ) - -# Memcache - -from memcacheify import memcacheify - -CACHES = memcacheify() - - -APPEND_SLASH = True + 'GET', +) From 6dcffca5bbe86c37e76b4b1f3909d0f9fe71e8d9 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 19:37:26 +0300 Subject: [PATCH 09/74] Replace url with path function, comment schema urls --- swapi/urls.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/swapi/urls.py b/swapi/urls.py index 3247befc..8b2af79b 100644 --- a/swapi/urls.py +++ b/swapi/urls.py @@ -1,7 +1,11 @@ from __future__ import unicode_literals -from django.conf.urls import patterns, url, include +from django.conf.urls import url, include from django.contrib import admin +from django.urls import path + +from .views import index, documentation, about, stats, stripe_donation + admin.autodiscover() from rest_framework import routers @@ -17,19 +21,17 @@ router.register(r"vehicles", views.VehicleViewSet) router.register(r"starships", views.StarshipViewSet) - -urlpatterns = patterns("", - url(r"^admin/", include(admin.site.urls)), - url(r"^$", "swapi.views.index"), - url(r"^documentation$", "swapi.views.documentation"), - url(r"^about$", "swapi.views.about"), - url(r"^stats$", "swapi.views.stats"), - url(r"^stripe/donation", "swapi.views.stripe_donation"), - url(r"^api/people/schema$", "resources.schemas.people"), - url(r"^api/planets/schema$", "resources.schemas.planets"), - url(r"^api/films/schema$", "resources.schemas.films"), - url(r"^api/species/schema$", "resources.schemas.species"), - url(r"^api/vehicles/schema$", "resources.schemas.vehicles"), - url(r"^api/starships/schema$", "resources.schemas.starships"), - url(r"^api/", include(router.urls)), -) +urlpatterns = [ + path("", index), + path("documentation", documentation), + path("about", about), + path("stats", stats), + path("stripe/donation", stripe_donation), + # url(r"^api/people/schema$", "resources.schemas.people"), + # url(r"^api/planets/schema$", "resources.schemas.planets"), + # url(r"^api/films/schema$", "resources.schemas.films"), + # url(r"^api/species/schema$", "resources.schemas.species"), + # url(r"^api/vehicles/schema$", "resources.schemas.vehicles"), + # url(r"^api/starships/schema$", "resources.schemas.starships"), + path("api/", include(router.urls)), +] From 009dc0f8754da6f09646a27eb5405311ca654886 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 19:38:57 +0300 Subject: [PATCH 10/74] Update requirements.txt --- requirements.txt | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/requirements.txt b/requirements.txt index c389e7bd..3b937766 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,28 +1,18 @@ -Django==1.7.4 -Padding==0.4 -SQLAlchemy==0.9.8 -dj-database-url==0.3.0 -dj-stripe==0.3.5 -django-braces==1.4.0 +asgiref==3.2.10 +certifi==2020.6.20 +chardet==3.0.4 +Django==3.0.8 django-clear-cache==0.3 -django-cors-headers==1.0.0 -django-heroku-memcacheify==0.8 -django-jsonfield==0.9.13 -django-keen==0.1.3 +django-cors-headers==3.4.0 +django-filter==2.3.0 django-markdown-deux==1.0.5 -django-model-utils==2.2 -django-postgrespool==0.3.0 -django-pylibmc==0.5.0 -djangorestframework==3.0.0 -drf-json-api==0.1.0 -gunicorn==19.1.1 -keen==0.3.7 -markdown2==2.3.0 -psycopg2==2.5.4 -pycrypto==2.6.1 -pylibmc==1.4.1 -requests==2.5.1 -six==1.8.0 -stripe==1.19.1 -whitenoise==1.0.3 -wsgiref==0.1.2 +django-markdown2==0.3.1 +djangorestframework==3.11.0 +idna==2.10 +markdown2==2.3.9 +pytz==2020.1 +requests==2.24.0 +sqlparse==0.3.1 +stripe==2.48.0 +urllib3==1.25.9 +whitenoise==5.1.0 From e9e5c3509991f84daa7446da11e26bb86a655e46 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 21:17:46 +0300 Subject: [PATCH 11/74] Add cache and ConditionalGetMiddleware to set eTag --- swapi/settings.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/swapi/settings.py b/swapi/settings.py index fec08413..e9fa34e0 100644 --- a/swapi/settings.py +++ b/swapi/settings.py @@ -40,6 +40,7 @@ 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.http.ConditionalGetMiddleware', 'django.middleware.security.SecurityMiddleware', ] @@ -96,12 +97,13 @@ }, ] -# CACHES = { -# 'default': { -# 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', -# 'TIMEOUT': 60 -# } -# } +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', + 'LOCATION': '127.0.0.1:11211', + 'TIMEOUT': 60 + } +} STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' @@ -133,7 +135,9 @@ }, 'DEFAULT_FILTER_BACKENDS': ( 'rest_framework.filters.SearchFilter', - ) + ), + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', + 'PAGE_SIZE': 10, } # Keen.io From 6f4393b116cbd9ce435ec46fc13a39d9ab16ec1b Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 21:18:16 +0300 Subject: [PATCH 12/74] Update renderers.py --- resources/renderers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/renderers.py b/resources/renderers.py index 7fa703b1..c142d11f 100644 --- a/resources/renderers.py +++ b/resources/renderers.py @@ -39,7 +39,9 @@ def render(self, data, media_type=None, renderer_context=None): encoded_data = super(WookieeRenderer, self).render( data, media_type, renderer_context ) - return bytes(self.translate_to_wookie(encoded_data)) + return self.translate_to_wookie( + encoded_data.decode('utf-8') + ).encode("utf-8") def translate_to_wookie(self, data): translated_data = "" From 96f30d572a28464901708a7cda7ba934a0eb4959 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 21:18:32 +0300 Subject: [PATCH 13/74] Add schemas urls --- swapi/urls.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/swapi/urls.py b/swapi/urls.py index 8b2af79b..8c0e58b5 100644 --- a/swapi/urls.py +++ b/swapi/urls.py @@ -5,6 +5,7 @@ from django.urls import path from .views import index, documentation, about, stats, stripe_donation +from resources import schemas admin.autodiscover() @@ -27,11 +28,11 @@ path("about", about), path("stats", stats), path("stripe/donation", stripe_donation), - # url(r"^api/people/schema$", "resources.schemas.people"), - # url(r"^api/planets/schema$", "resources.schemas.planets"), - # url(r"^api/films/schema$", "resources.schemas.films"), - # url(r"^api/species/schema$", "resources.schemas.species"), - # url(r"^api/vehicles/schema$", "resources.schemas.vehicles"), - # url(r"^api/starships/schema$", "resources.schemas.starships"), - path("api/", include(router.urls)), + path("api/people/schema", schemas.people), + path("api/planets/schema", schemas.planets), + path("api/films/schema", schemas.films), + path("api/species/schema", schemas.species), + path("api/vehicles/schema", schemas.vehicles), + path("api/starships/schema", schemas.starships), + url(r"^api/", include(router.urls)), ] From 409e91a9b586631f05c3abec199337f91ee2f3ac Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 21:21:18 +0300 Subject: [PATCH 14/74] Update requirements.txt (Django 3.0.8!) --- requirements.txt | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/requirements.txt b/requirements.txt index c389e7bd..efe5597e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,28 +1,20 @@ -Django==1.7.4 -Padding==0.4 -SQLAlchemy==0.9.8 -dj-database-url==0.3.0 -dj-stripe==0.3.5 -django-braces==1.4.0 +asgiref==3.2.10 +certifi==2020.6.20 +chardet==3.0.4 +Django==3.0.8 django-clear-cache==0.3 -django-cors-headers==1.0.0 -django-heroku-memcacheify==0.8 -django-jsonfield==0.9.13 -django-keen==0.1.3 +django-cors-headers==3.4.0 +django-filter==2.3.0 django-markdown-deux==1.0.5 -django-model-utils==2.2 -django-postgrespool==0.3.0 -django-pylibmc==0.5.0 -djangorestframework==3.0.0 -drf-json-api==0.1.0 -gunicorn==19.1.1 -keen==0.3.7 -markdown2==2.3.0 -psycopg2==2.5.4 -pycrypto==2.6.1 -pylibmc==1.4.1 -requests==2.5.1 -six==1.8.0 -stripe==1.19.1 -whitenoise==1.0.3 -wsgiref==0.1.2 +django-markdown2==0.3.1 +djangorestframework==3.11.0 +idna==2.10 +markdown2==2.3.9 +python-memcached==1.59 +pytz==2020.1 +requests==2.24.0 +six==1.15.0 +sqlparse==0.3.1 +stripe==2.48.0 +urllib3==1.25.9 +whitenoise==5.1.0 From 62e0e2da59d4a774ec4b7baa39f95e41ad86ef4f Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 21:27:30 +0300 Subject: [PATCH 15/74] Removed text about maintain --- README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index 6fd690aa..f58b2608 100644 --- a/README.md +++ b/README.md @@ -1,8 +1 @@ -# SWAPI -## The Star Wars API - -## NO LONGER MAINTAINED! - -If you rely on this project for your own tools - then please fork and spin up your own instance. It's a pretty simple project, and the Makefile will take you a long way. - -If you are looking for an API to play with to learn about APIs, then I recommend [https://pokeapi.co](https://pokeapi.co). +# SWAPI \ No newline at end of file From 7b6ae6eff0f3c9c1fd7b100efe6cbdf8586212a0 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 21:41:56 +0300 Subject: [PATCH 16/74] Remove automatically install dependencies with apt --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 84dc3d62..3485be1d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ install: - apt install postgresql postgresql-server-dev-all gcc python-dev libmemcached-dev zlib1g-dev pip install -r requirements.txt build: From 00f6e8eae2174c55e97abbc149747f9b62d71b4b Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 21:52:04 +0300 Subject: [PATCH 17/74] Updated Python version for travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ad154b4d..5ac45611 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: python python: - - "2.7" + - "3.8" install: pip install -r requirements.txt From 613bfebf9e5ff6652efe3f4a37571dad88748296 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 22:10:59 +0300 Subject: [PATCH 18/74] Removed import of unicode_literals --- swapi/urls.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/swapi/urls.py b/swapi/urls.py index 8c0e58b5..150ad967 100644 --- a/swapi/urls.py +++ b/swapi/urls.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from django.conf.urls import url, include from django.contrib import admin from django.urls import path From d6c5b5d5d209f217b4de75a5db5f045c0b4b4ec3 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 22:11:31 +0300 Subject: [PATCH 19/74] Beautify code --- swapi/settings.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/swapi/settings.py b/swapi/settings.py index e9fa34e0..bf74a382 100644 --- a/swapi/settings.py +++ b/swapi/settings.py @@ -2,12 +2,10 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -SECRET_KEY = os.environ.get( - 'SECRET_KEY', - 'i+acxn5(akgsn!sr4^qgf(^m&*@+g1@u^t@=8s@axc41ml*f=s' -) +SECRET_KEY = os.environ.get('SECRET_KEY', 'i+acxn5(akgsn!sr4^qgf(^m&*@+g1@u^t@=8s@axc41ml*f=s') DEBUG = bool(os.environ.get('DEBUG', True)) + # Because test settings will trigger KEEN.io hits KEEN_DEBUG = bool(os.environ.get('DEBUG', True)) @@ -62,11 +60,6 @@ USE_L10N = True USE_TZ = True -# if not DEBUG: -# DATABASES['default'] = dj_database_url.config() -# -# DATABASES['default']['ENGINE'] = 'django_postgrespool' - SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') ALLOWED_HOSTS = ['*'] From d5c2a339f3247bd743a2f40f3b6e4f87305f967b Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 23:11:39 +0300 Subject: [PATCH 20/74] Test update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5ac45611..f11e2829 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,4 +10,4 @@ install: pip install -r requirements.txt script: python manage.py test notifications: - email: false + email: true From bdba85ba1acb6622a38a6fef527e64c03abab99f Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 23:17:35 +0300 Subject: [PATCH 21/74] Added build status --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f58b2608..0243db0e 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# SWAPI \ No newline at end of file +# SWAPI +[![Build Status](https://travis-ci.com/leonidpodriz/swapi.svg?branch=master)](https://travis-ci.com/leonidpodriz/swapi) \ No newline at end of file From 2d48a950603d93d27678c373fe39dbe8aa9e8703 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 23:31:22 +0300 Subject: [PATCH 22/74] Added admins url --- swapi/urls.py | 1 + 1 file changed, 1 insertion(+) diff --git a/swapi/urls.py b/swapi/urls.py index 150ad967..26b07c14 100644 --- a/swapi/urls.py +++ b/swapi/urls.py @@ -21,6 +21,7 @@ router.register(r"starships", views.StarshipViewSet) urlpatterns = [ + path('admin/', admin.site.urls), path("", index), path("documentation", documentation), path("about", about), From 1fd9e24df283ec4356c90c2aa5e1670d4fd71aab Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 23:33:23 +0300 Subject: [PATCH 23/74] Removed autodiscover function --- swapi/urls.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/swapi/urls.py b/swapi/urls.py index 26b07c14..054550c3 100644 --- a/swapi/urls.py +++ b/swapi/urls.py @@ -5,8 +5,6 @@ from .views import index, documentation, about, stats, stripe_donation from resources import schemas -admin.autodiscover() - from rest_framework import routers from resources import views From daaf5977b103403fd7af78b14a3dea2bf9ac8315 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 23:34:51 +0300 Subject: [PATCH 24/74] Imports refactor --- swapi/urls.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/swapi/urls.py b/swapi/urls.py index 054550c3..222b5489 100644 --- a/swapi/urls.py +++ b/swapi/urls.py @@ -1,13 +1,11 @@ from django.conf.urls import url, include from django.contrib import admin from django.urls import path - -from .views import index, documentation, about, stats, stripe_donation -from resources import schemas - from rest_framework import routers +from resources import schemas from resources import views +from .views import index, documentation, about, stats, stripe_donation router = routers.DefaultRouter() From 3367442f12c5725096412fdabebadf857cd451ea Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 23:35:38 +0300 Subject: [PATCH 25/74] Changed url to path function --- swapi/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swapi/urls.py b/swapi/urls.py index 222b5489..f94716ab 100644 --- a/swapi/urls.py +++ b/swapi/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import url, include +from django.conf.urls import include from django.contrib import admin from django.urls import path from rest_framework import routers @@ -29,5 +29,5 @@ path("api/species/schema", schemas.species), path("api/vehicles/schema", schemas.vehicles), path("api/starships/schema", schemas.starships), - url(r"^api/", include(router.urls)), + path("api/", include(router.urls)), ] From a0971c42836d41a75b5e18d3369d561843670998 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 23:36:47 +0300 Subject: [PATCH 26/74] Removed unicode_literals from views.py --- resources/views.py | 2 -- swapi/views.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/resources/views.py b/resources/views.py index c2ff1547..73526119 100644 --- a/resources/views.py +++ b/resources/views.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from rest_framework import viewsets from .models import ( diff --git a/swapi/views.py b/swapi/views.py index df776e0a..e780b775 100644 --- a/swapi/views.py +++ b/swapi/views.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from django.shortcuts import render, redirect from django.views.decorators.csrf import csrf_exempt from django.core.cache import cache From ca023482bb572a3f16dfdbabf5645b412a3a035f Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 23:43:56 +0300 Subject: [PATCH 27/74] Beautify code --- resources/serializers.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/resources/serializers.py b/resources/serializers.py index a963cd60..7e87ec3c 100644 --- a/resources/serializers.py +++ b/resources/serializers.py @@ -13,7 +13,6 @@ class PeopleSerializer(serializers.HyperlinkedModelSerializer): - homeworld = serializers.HyperlinkedRelatedField( read_only=True, view_name="planet-detail" @@ -42,7 +41,6 @@ class Meta: class PlanetSerializer(serializers.HyperlinkedModelSerializer): - class Meta: model = Planet fields = ( @@ -64,7 +62,6 @@ class Meta: class FilmSerializer(serializers.HyperlinkedModelSerializer): - class Meta: model = Film fields = ( @@ -73,7 +70,7 @@ class Meta: "opening_crawl", "director", "producer", - "release_date", + "release_date", "characters", "planets", "starships", @@ -86,7 +83,6 @@ class Meta: class SpeciesSerializer(serializers.HyperlinkedModelSerializer): - homeworld = serializers.HyperlinkedRelatedField( read_only=True, view_name='planet-detail' @@ -114,7 +110,6 @@ class Meta: class VehicleSerializer(serializers.HyperlinkedModelSerializer): - pilots = serializers.HyperlinkedRelatedField( many=True, read_only=True, @@ -144,7 +139,6 @@ class Meta: class StarshipSerializer(serializers.HyperlinkedModelSerializer): - pilots = serializers.HyperlinkedRelatedField( many=True, read_only=True, @@ -173,4 +167,3 @@ class Meta: "edited", "url" ) - From 767e3fa405eedeb6917f1422db2c9435247dd531 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Thu, 16 Jul 2020 23:44:30 +0300 Subject: [PATCH 28/74] Remove unicode_literals from serializers.py --- resources/serializers.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/resources/serializers.py b/resources/serializers.py index 7e87ec3c..9dd71fd0 100644 --- a/resources/serializers.py +++ b/resources/serializers.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from rest_framework import serializers from .models import ( From f38b8a2e6903157a2888d25b42f6ab386ea5df1a Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Fri, 17 Jul 2020 00:07:22 +0300 Subject: [PATCH 29/74] Reformat base.html --- swapi/templates/base.html | 154 ++++++++++++++++++++++++-------------- 1 file changed, 99 insertions(+), 55 deletions(-) diff --git a/swapi/templates/base.html b/swapi/templates/base.html index 3ad96858..4f83e3d6 100644 --- a/swapi/templates/base.html +++ b/swapi/templates/base.html @@ -1,73 +1,117 @@ +{% load static %} - + - SWAPI - The Star Wars API + SWAPI - The Star Wars API + - - - - + + + + - - - - - gtag('js', new Date()); - gtag('config', 'UA-163610532-1'); - - - - - - -
- -
-
-

SWAPI

-

The Star Wars API

-

(what happened to swapi.co?)

-
+ - {% block mainbody %}{% endblock mainbody %} + + + + - {% block scripts %}{% endblock scripts %} + + + - - - -

-
- - + function gtag() { + dataLayer.push(arguments); + } + + gtag('js', new Date()); + gtag('config', 'UA-163610532-1'); + diff --git a/swapi/templates/documentation.html b/swapi/templates/documentation.html index e2fb449d..2a37ac0b 100644 --- a/swapi/templates/documentation.html +++ b/swapi/templates/documentation.html @@ -4,9 +4,9 @@ {% block mainbody %}
-
+
Getting started
-
-
+
{% markdown %} {% include "docs.md" %} {% endmarkdown %} diff --git a/swapi/templates/index.html b/swapi/templates/index.html index 061fb8c1..70d6be24 100644 --- a/swapi/templates/index.html +++ b/swapi/templates/index.html @@ -2,38 +2,44 @@ {% load humanize %} {% block mainbody %} +
-
-
+

All the Star Wars data you've ever wanted:

Planets, Spaceships, Vehicles, People, Films and Species

From all SEVEN Star Wars films

Now with The Force Awakens data!

-
-
+ +
+
-
-
-
-

Try it now!

-
- {{ request.build_absolute_uri }}api/ - +
+ +
+
+ {{ request.build_absolute_uri }}api/ +
- - - +
+ +
- Need a hint? try + + Need a hint? try people/1/ or planets/3/ or starships/9/ -

Result:

+ +

Result:

-
+               
+                    
 {
 	"name": "Luke Skywalker",
 	"height": "172",
@@ -66,37 +72,34 @@ 

Try it now!

"edited": "2014-12-20T21:17:56.891000Z", "url": "https://swapi.dev/api/people/1/" } -
+ +
-
-
-
-
-

What is this?

+
+
+

What is this?

The Star Wars API, or "swapi" (Swah-pee) is the world's first quantified and programmatically-accessible data source for all the data from the Star Wars canon universe!

We've taken all the rich contextual stuff from the universe and formatted into something easier to consume with software. Then we went and stuck an API on the front so you can access it all!

-
-

How can I use it?

+
+

How can I use it?

All the data is accessible through our HTTP web API. Consult our documentation if you'd like to get started.

Helper libraries for popular programming languages are also provided so you can consume swapi in your favourite programming language, in a style that suits you.

-
-

What happened with old swapi.co?

+
+

What happened with old swapi.co?

swapi.co is not supported and maintained anymode. But since so many projects and tutorials used it as their educational playground, this is an "unofficial" branch

This project is open source and you can contribute on GitHub.

-
-

{% endblock mainbody %} @@ -109,22 +112,23 @@

What happened with old swapi.co?

function interactive_call() { let content = jQuery('#interactive').val() - if (content === '') { - content = 'people/1/'; - } + content = content || 'people/1/'; let call_url = 'api/' + content; - jQuery.ajax({ + + jQuery.ajax(call_url, { dataType: 'json', - url: call_url, context: document.body - }).complete(function (data) { - if (data['status'] === 200) { - let d = jQuery.parseJSON(data['responseText']); - jQuery('#interactive_output').text(JSON.stringify(d, null, '\t')); - } else if (data['status'] === 404) { - jQuery('#interactive_output').text(data['status'] + ' ' + data['statusText']); - } + }).done(function (data) { + jQuery('#interactive_output').text(JSON.stringify(data, null, '\t')); + }).fail(function (data) { + jQuery('#interactive_output').text(data['status'] + ' ' + data['statusText']); }); } + {% endblock scripts %} \ No newline at end of file From f774cdc64534d21579ddee1acbe5439cdd1c9d44 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Sat, 18 Jul 2020 17:18:04 +0300 Subject: [PATCH 65/74] Refactor code. Added icon support --- swapi/templates/rest_framework/api.html | 58 +++++++++++++++++-------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/swapi/templates/rest_framework/api.html b/swapi/templates/rest_framework/api.html index 51da42b4..2ebf2b32 100644 --- a/swapi/templates/rest_framework/api.html +++ b/swapi/templates/rest_framework/api.html @@ -1,24 +1,44 @@ {% extends "rest_framework/base.html" %} +{% load static %} + {% block bootstrap_theme %} - + + + {% endblock %} -SWAPI - The Star Wars API + +{% block title %}SWAPI - The Star Wars API{% endblock %} + {% block bootstrap_navbar_variant %}{% endblock %} + {% block branding %} - -{% endblock %} + + +{% endblock %} From 69574072db01600431f7a13e99e7b1acdcc14771 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Sat, 18 Jul 2020 17:25:44 +0300 Subject: [PATCH 66/74] Fixed code displaying on main page --- swapi/templates/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swapi/templates/index.html b/swapi/templates/index.html index 70d6be24..89ef953a 100644 --- a/swapi/templates/index.html +++ b/swapi/templates/index.html @@ -38,7 +38,7 @@

Now with The Force Awakens data!

Result:

-
+               
                     
 {
 	"name": "Luke Skywalker",

From d7bb1f2c0dd8b8a2b123eb5378b4481fee8412da Mon Sep 17 00:00:00 2001
From: Leonid Podriz 
Date: Sat, 18 Jul 2020 17:43:52 +0300
Subject: [PATCH 67/74] "Try it now!" to primary text

---
 swapi/templates/index.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/swapi/templates/index.html b/swapi/templates/index.html
index 89ef953a..b0198ad1 100644
--- a/swapi/templates/index.html
+++ b/swapi/templates/index.html
@@ -16,7 +16,7 @@ 

Now with The Force Awakens data!

- +
{{ request.build_absolute_uri }}api/ From 066fc0a20980233d3524c91facab360b6776457d Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Sat, 18 Jul 2020 17:48:27 +0300 Subject: [PATCH 68/74] Replaced http:// with https:// --- swapi/templates/docs.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/swapi/templates/docs.md b/swapi/templates/docs.md index a09390bf..e1ddc28e 100644 --- a/swapi/templates/docs.md +++ b/swapi/templates/docs.md @@ -13,11 +13,11 @@ Welcome to the swapi, the Star Wars API! This documentation should help you fami Let's make our first API request to the Star Wars API! -Open up a terminal and use [curl](http://curl.haxx.se) or [httpie](http://httpie.org) to make an API request for a resource. In the example below, we're trying to get the first planet, Tatooine: +Open up a terminal and use [curl](https://curl.haxx.se) or [httpie](https://httpie.org) to make an API request for a resource. In the example below, we're trying to get the first planet, Tatooine: http swapi.dev/api/planets/1/ -We'll use [httpie](http://httpie.org) for our examples as it displays responses nicely and gives us a whole lot more useful information. If you don't want to download httpie, just use the *curl* command instead. +We'll use [httpie](https://httpie.org) for our examples as it displays responses nicely and gives us a whole lot more useful information. If you don't want to download httpie, just use the *curl* command instead. Here is the response we get: @@ -78,7 +78,7 @@ All resources support a `search` parameter that filters the set of resources ret https://swapi.dev/api/people/?search=r2 ``` - All searches will use case-insensitive partial matches on the set of search fields. To see the set of search fields for each resource, check out the individual resource documentation. For more information on advanced search terms see [here](http://www.django-rest-framework.org/api-guide/filtering/#searchfilter). + All searches will use case-insensitive partial matches on the set of search fields. To see the set of search fields for each resource, check out the individual resource documentation. For more information on advanced search terms see [here](https://www.django-rest-framework.org/api-guide/filtering/#searchfilter). #Encodings - - - @@ -652,7 +652,7 @@ A Planet resource is a large mass, planet or planetoid in the Star Wars Universe There are a bunch of helper libraries available for consuming the Star Wars API in a native programming language. -![helper_library_gif](http://i.imgur.com/l02u363.gif) +![helper_library_gif](https://i.imgur.com/l02u363.gif) ##Python @@ -724,10 +724,10 @@ There are a bunch of helper libraries available for consuming the Star Wars API ## F# # -- [fsharp-swapi](https://github.com/evelinag/fsharp-swapi) by [Evelina Gabasova](http://evelinag.com/). +- [fsharp-swapi](https://github.com/evelinag/fsharp-swapi) by [Evelina Gabasova](https://evelinag.com/). ## Elixir -- [swapi.ex](https://github.com/twhitacre/swapi.ex) by [Tim Whitacre](http://timw.co/). -- [ex_swapi](https://github.com/mrkjlchvz/ex_swapi) by [Mark Chavez](http://markjoelchavez.com). +- [swapi.ex](https://github.com/twhitacre/swapi.ex) by [Tim Whitacre](https://timw.co/). +- [ex_swapi](https://github.com/mrkjlchvz/ex_swapi) by [Mark Chavez](https://markjoelchavez.com). - [elixir-swapi](https://github.com/kylesurowiec/swapi-elixir) by [Kyle Surowiec](https://github.com/kylesurowiec). From 57865ce020ed3a4393753df882e7a56af16274c4 Mon Sep 17 00:00:00 2001 From: Leonid Podriz Date: Sat, 18 Jul 2020 17:51:57 +0300 Subject: [PATCH 69/74] Make a logo text link --- swapi/templates/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swapi/templates/base.html b/swapi/templates/base.html index fe3cd362..518f90fa 100644 --- a/swapi/templates/base.html +++ b/swapi/templates/base.html @@ -17,7 +17,7 @@