diff --git a/bootstrap.py b/bootstrap.py index 2c2e494..8ada3e6 100755 --- a/bootstrap.py +++ b/bootstrap.py @@ -13,26 +13,36 @@ Set up my development environment for me! """ -project_name = 'netland' +project_name = "netland" parser = argparse.ArgumentParser(description=description) -parser.add_argument('target', choices=['production', 'staging', 'test', 'jenkins', 'dev'], - help='production/staging/test/jenkins/dev') -parser.add_argument('--project', default=project_name, - help='Name of the project in your src directory, "%s" by default' % project_name) -parser.add_argument('--init', action='store_true', - help='Initialize a fresh "startproject" by pinning the requirements using pip-tools compile. ' - 'Automatically done if requirements/base.txt does not yet exist.') -parser.add_argument('--env', default='env', - help='Directory name for virtualenv, "env" by default') +parser.add_argument( + "target", + choices=["production", "staging", "test", "jenkins", "dev"], + help="production/staging/test/jenkins/dev", +) +parser.add_argument( + "--project", + default=project_name, + help='Name of the project in your src directory, "%s" by default' % project_name, +) +parser.add_argument( + "--init", + action="store_true", + help='Initialize a fresh "startproject" by pinning the requirements using pip-tools compile. ' + "Automatically done if requirements/base.txt does not yet exist.", +) +parser.add_argument( + "--env", default="env", help='Directory name for virtualenv, "env" by default' +) args = parser.parse_args() def replace_or_append(file_path, search_val, replace_val): file_handle, abs_path = mkstemp() - new_file = open(abs_path, 'w') - old_file = open(file_path, 'r') + new_file = open(abs_path, "w") + old_file = open(file_path, "r") found = False for line in old_file: if line.startswith(search_val): @@ -51,89 +61,109 @@ def replace_or_append(file_path, search_val, replace_val): def replace_wsgi_settings(target): - path = os.path.join('src', project_name, 'wsgi.py') + path = os.path.join("src", project_name, "wsgi.py") replace_or_append( - path, 'os.environ.setdefault', - 'os.environ.setdefault("DJANGO_SETTINGS_MODULE", "%s.conf.%s")\n' % (project_name, target) + path, + "os.environ.setdefault", + 'os.environ.setdefault("DJANGO_SETTINGS_MODULE", "%s.conf.%s")\n' + % (project_name, target), ) def replace_manage_settings(target): - path = os.path.join('src', project_name, 'manage.py') + path = os.path.join("src", project_name, "manage.py") replace_or_append( - path, ' os.environ.setdefault', - ' os.environ.setdefault("DJANGO_SETTINGS_MODULE", "%s.conf.%s")\n' % (project_name, target) + path, + " os.environ.setdefault", + ' os.environ.setdefault("DJANGO_SETTINGS_MODULE", "%s.conf.%s")\n' + % (project_name, target), ) def append_settings_activate(project, target, env): - if os.name == 'posix': - path = '%s/bin/activate' % env - replace_or_append(path, 'export DJANGO_SETTINGS_MODULE=', - 'export DJANGO_SETTINGS_MODULE=\'%s.conf.%s\'\n' % - (project, target)) - elif os.name == 'nt': - path = '%s\\Scripts\\activate.bat' % env - replace_or_append(path, 'set DJANGO_SETTINGS_MODULE=', - 'set DJANGO_SETTINGS_MODULE=%s.conf.%s\n' % - (project, target)) - path = '%s\\Scripts\\deactivate.bat' % env - replace_or_append(path, 'set DJANGO_SETTINGS_MODULE=', - 'set DJANGO_SETTINGS_MODULE=\n') + if os.name == "posix": + path = "%s/bin/activate" % env + replace_or_append( + path, + "export DJANGO_SETTINGS_MODULE=", + "export DJANGO_SETTINGS_MODULE='%s.conf.%s'\n" % (project, target), + ) + elif os.name == "nt": + path = "%s\\Scripts\\activate.bat" % env + replace_or_append( + path, + "set DJANGO_SETTINGS_MODULE=", + "set DJANGO_SETTINGS_MODULE=%s.conf.%s\n" % (project, target), + ) + path = "%s\\Scripts\\deactivate.bat" % env + replace_or_append( + path, "set DJANGO_SETTINGS_MODULE=", "set DJANGO_SETTINGS_MODULE=\n" + ) def pip_compile_pin_requirements(virtualenv): - print('\n== Compiling base requirements ==\n') - if os.name == 'posix': - pip_path = os.path.join(virtualenv, 'bin', 'pip') - elif os.name == 'nt': - pip_path = os.path.join(virtualenv, 'Scripts', 'pip') - cmd_tpl = '{pip} install pip-tools'.format(pip=pip_path) + print("\n== Compiling base requirements ==\n") + if os.name == "posix": + pip_path = os.path.join(virtualenv, "bin", "pip") + elif os.name == "nt": + pip_path = os.path.join(virtualenv, "Scripts", "pip") + cmd_tpl = "{pip} install pip-tools".format(pip=pip_path) call(cmd_tpl, shell=True) - print('Error: Run `. env/bin/activate && ./bin/compile_dependencies.sh` to ensure you have requirements/base.txt and requirements/dev.txt') - print('After that rerun bootstrap.py') + print( + "Error: Run `. env/bin/activate && ./bin/compile_dependencies.sh` to ensure you have requirements/base.txt and requirements/dev.txt" + ) + print("After that rerun bootstrap.py") sys.exit(1) + def main(): virtualenv = args.env - if not hasattr(sys, 'real_prefix'): - print('\n== Creating virtual environment ==\n') - call('virtualenv {0} --python=python3 --prompt="({1}-{2}) "'.format( - virtualenv, args.project, args.target - ), shell=True) - print('\n== Set "%s.conf.%s" as default settings ==\n' % (args.project, args.target)) + if not hasattr(sys, "real_prefix"): + print("\n== Creating virtual environment ==\n") + call( + 'virtualenv {0} --python=python3 --prompt="({1}-{2}) "'.format( + virtualenv, args.project, args.target + ), + shell=True, + ) + print( + '\n== Set "%s.conf.%s" as default settings ==\n' % (args.project, args.target) + ) append_settings_activate(args.project, args.target, args.env) - if os.name == 'posix': + if os.name == "posix": # Make manage.py executable - st = os.stat('src/manage.py') - os.chmod('src/manage.py', st.st_mode | stat.S_IEXEC) - django_admin_symlink = os.path.join(virtualenv, 'bin', 'django') + st = os.stat("src/manage.py") + os.chmod("src/manage.py", st.st_mode | stat.S_IEXEC) + django_admin_symlink = os.path.join(virtualenv, "bin", "django") if not os.path.exists(django_admin_symlink): - os.symlink('../../src/manage.py', django_admin_symlink) - - print('\n== Upgrading Pip ==\n') - if os.name == 'posix': - pip_path = os.path.join(virtualenv, 'bin', 'pip') - elif os.name == 'nt': - pip_path = os.path.join(virtualenv, 'Scripts', 'pip') - cmd_tpl = '{pip} install --upgrade pip'.format(pip=pip_path) + os.symlink("../../src/manage.py", django_admin_symlink) + + print("\n== Upgrading Pip ==\n") + if os.name == "posix": + pip_path = os.path.join(virtualenv, "bin", "pip") + elif os.name == "nt": + pip_path = os.path.join(virtualenv, "Scripts", "pip") + cmd_tpl = "{pip} install --upgrade pip".format(pip=pip_path) call(cmd_tpl, shell=True) - if args.init \ - or not os.path.exists(os.path.join('requirements', 'base.txt')) \ - or not os.path.exists(os.path.join('requirements', 'dev.txt')): + if ( + args.init + or not os.path.exists(os.path.join("requirements", "base.txt")) + or not os.path.exists(os.path.join("requirements", "dev.txt")) + ): pip_compile_pin_requirements(virtualenv) - print('\n== Installing %s requirements ==\n' % args.target) - if os.name == 'posix': - os.environ['TMPDIR'] = '/var/tmp/' - pip_path = os.path.join(virtualenv, 'bin', 'pip') - cmd_tpl = '{pip} install -r requirements/{target}.txt' - elif os.name == 'nt': - pip_path = os.path.join(virtualenv, 'Scripts', 'pip') - cmd_tpl = '{pip} install -r requirements\\{target}.txt' + print("\n== Installing %s requirements ==\n" % args.target) + if os.name == "posix": + os.environ["TMPDIR"] = "/var/tmp/" + pip_path = os.path.join(virtualenv, "bin", "pip") + cmd_tpl = "{pip} install -r requirements/{target}.txt" + elif os.name == "nt": + pip_path = os.path.join(virtualenv, "Scripts", "pip") + cmd_tpl = "{pip} install -r requirements\\{target}.txt" return call(cmd_tpl.format(pip=pip_path, target=args.target), shell=True) -if __name__ == '__main__': + +if __name__ == "__main__": sys.exit(main()) diff --git a/src/netland/accounts/migrations/0001_initial.py b/src/netland/accounts/migrations/0001_initial.py index 69cf5c9..5f1df46 100644 --- a/src/netland/accounts/migrations/0001_initial.py +++ b/src/netland/accounts/migrations/0001_initial.py @@ -7,7 +7,6 @@ class Migration(migrations.Migration): - initial = True dependencies = [ diff --git a/src/netland/accounts/tests/test_permission_limit.py b/src/netland/accounts/tests/test_permission_limit.py index 6f1d6cd..110f254 100644 --- a/src/netland/accounts/tests/test_permission_limit.py +++ b/src/netland/accounts/tests/test_permission_limit.py @@ -40,6 +40,7 @@ def test_user_add(self): self.assertEqual(response.status_code, 200) + class PasswordResetViewTests(TestCase): def setUp(self): super().setUp() diff --git a/src/netland/conf/base.py b/src/netland/conf/base.py index d502d1c..191c0c8 100644 --- a/src/netland/conf/base.py +++ b/src/netland/conf/base.py @@ -162,7 +162,7 @@ WSGI_APPLICATION = "netland.wsgi.application" # Translations -LOCALE_PATHS = (DJANGO_PROJECT_DIR / "conf" / "locale", ) +LOCALE_PATHS = (DJANGO_PROJECT_DIR / "conf" / "locale",) # # SERVING of static and media files @@ -356,7 +356,9 @@ repo = git.Repo(search_parent_directories=True) try: GIT_SHA = repo.head.object.hexsha - except ValueError: # on startproject initial runs before any git commits have been made + except ( + ValueError + ): # on startproject initial runs before any git commits have been made GIT_SHA = repo.active_branch.name else: GIT_SHA = None diff --git a/src/netland/conf/jenkins.py b/src/netland/conf/jenkins.py index ccd3320..50a1155 100644 --- a/src/netland/conf/jenkins.py +++ b/src/netland/conf/jenkins.py @@ -67,9 +67,7 @@ def get_db_name(prefix): INSTALLED_APPS += [ "django_jenkins", ] -PROJECT_APPS = [ - app for app in INSTALLED_APPS if app.startswith("netland.") -] +PROJECT_APPS = [app for app in INSTALLED_APPS if app.startswith("netland.")] JENKINS_TASKS = ( # 'django_jenkins.tasks.run_pylint', # Pylint < 2.0 does not run on Python 3.7+ # "django_jenkins.tasks.run_pep8", # -> renamed to pycodestyle, but django-jenkins hasn't been updated in 6 years diff --git a/src/netland/login/apps.py b/src/netland/login/apps.py index 7892238..2581a71 100644 --- a/src/netland/login/apps.py +++ b/src/netland/login/apps.py @@ -2,5 +2,5 @@ class LoginConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'netland.login' + default_auto_field = "django.db.models.BigAutoField" + name = "netland.login" diff --git a/src/netland/login/urls.py b/src/netland/login/urls.py index 63c638f..8c89e7f 100644 --- a/src/netland/login/urls.py +++ b/src/netland/login/urls.py @@ -1,7 +1,9 @@ +from django.contrib.auth.views import LogoutView from django.urls import path + from .views import * -from django.contrib.auth.views import LogoutView + urlpatterns = [ - path('login/', Login.as_view(), name='login'), - path('logout/', LogoutView.as_view(next_page='login'), name='logout'), -] \ No newline at end of file + path("login/", Login.as_view(), name="login"), + path("logout/", LogoutView.as_view(next_page="login"), name="logout"), +] diff --git a/src/netland/login/views.py b/src/netland/login/views.py index 6956690..8cff674 100644 --- a/src/netland/login/views.py +++ b/src/netland/login/views.py @@ -1,12 +1,13 @@ -from django.shortcuts import render from django.contrib.auth.views import LoginView, LogoutView +from django.shortcuts import render from django.urls import reverse_lazy + + # Create your views here. class Login(LoginView): - template_name = 'registration/login.html' - fields = '__all__' + template_name = "registration/login.html" + fields = "__all__" redirect_authenticated_user = True def get_success_url(self): - return reverse_lazy('index') - + return reverse_lazy("index") diff --git a/src/netland/movie/admin.py b/src/netland/movie/admin.py index 3188788..2ca0b4c 100644 --- a/src/netland/movie/admin.py +++ b/src/netland/movie/admin.py @@ -1,4 +1,6 @@ from django.contrib import admin + from .models import Movies + # Register your models here. -admin.site.register(Movies) \ No newline at end of file +admin.site.register(Movies) diff --git a/src/netland/movie/apps.py b/src/netland/movie/apps.py index 6de83d6..008f5e8 100644 --- a/src/netland/movie/apps.py +++ b/src/netland/movie/apps.py @@ -2,5 +2,5 @@ class MovieConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'netland.movie' + default_auto_field = "django.db.models.BigAutoField" + name = "netland.movie" diff --git a/src/netland/movie/forms.py b/src/netland/movie/forms.py index fa0acf7..c876a02 100644 --- a/src/netland/movie/forms.py +++ b/src/netland/movie/forms.py @@ -1,15 +1,24 @@ -from django import forms +from django import forms + from .models import Movies + class MovieForm(forms.ModelForm): class Meta: model = Movies - fields = ['title', 'length_in_minutes', 'released_at', 'country_of_origin', 'summary', 'youtube_trailer_id'] + fields = [ + "title", + "length_in_minutes", + "released_at", + "country_of_origin", + "summary", + "youtube_trailer_id", + ] widgets = { - 'title': forms.TextInput(attrs={'class': 'form-control'}), - 'length_in_minutes': forms.TextInput(attrs={'class': 'form-control'}), - 'released_at': forms.TextInput(attrs={'class': 'form-control'}), - 'country_of_origin': forms.TextInput(attrs={'class': 'form-control'}), - 'summary': forms.Textarea(attrs={'class': 'form-control'}), - 'youtube_trailer_id': forms.TextInput(attrs={'class': 'form-control'}), - } \ No newline at end of file + "title": forms.TextInput(attrs={"class": "form-control"}), + "length_in_minutes": forms.TextInput(attrs={"class": "form-control"}), + "released_at": forms.TextInput(attrs={"class": "form-control"}), + "country_of_origin": forms.TextInput(attrs={"class": "form-control"}), + "summary": forms.Textarea(attrs={"class": "form-control"}), + "youtube_trailer_id": forms.TextInput(attrs={"class": "form-control"}), + } diff --git a/src/netland/movie/migrations/0001_initial.py b/src/netland/movie/migrations/0001_initial.py index 20692cb..de27e84 100644 --- a/src/netland/movie/migrations/0001_initial.py +++ b/src/netland/movie/migrations/0001_initial.py @@ -4,26 +4,38 @@ class Migration(migrations.Migration): - initial = True - dependencies = [ - ] + dependencies = [] operations = [ migrations.CreateModel( - name='Movies', + name="Movies", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=100)), - ('length_in_minutes', models.IntegerField()), - ('released_at', models.DateField(blank=True, null=True)), - ('country_of_origin', models.CharField(blank=True, max_length=2, null=True)), - ('summary', models.TextField()), - ('youtube_trailer_id', models.CharField(blank=True, max_length=20, null=True)), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=100)), + ("length_in_minutes", models.IntegerField()), + ("released_at", models.DateField(blank=True, null=True)), + ( + "country_of_origin", + models.CharField(blank=True, max_length=2, null=True), + ), + ("summary", models.TextField()), + ( + "youtube_trailer_id", + models.CharField(blank=True, max_length=20, null=True), + ), ], options={ - 'db_table': 'movies', + "db_table": "movies", }, ), ] diff --git a/src/netland/movie/models.py b/src/netland/movie/models.py index b540aa2..40d7227 100644 --- a/src/netland/movie/models.py +++ b/src/netland/movie/models.py @@ -1,5 +1,6 @@ from django.db import models + # Create your models here. class Movies(models.Model): title = models.CharField(max_length=100) @@ -10,4 +11,4 @@ class Movies(models.Model): youtube_trailer_id = models.CharField(max_length=20, blank=True, null=True) class Meta: - db_table = 'movies' \ No newline at end of file + db_table = "movies" diff --git a/src/netland/movie/tests.py b/src/netland/movie/tests.py index 76cf31b..5b1c3a9 100644 --- a/src/netland/movie/tests.py +++ b/src/netland/movie/tests.py @@ -1,21 +1,38 @@ +from django.contrib.auth.models import User from django.test import TestCase +from django.urls import reverse + from .models import * from .views import * -from django.urls import reverse -from django.contrib.auth.models import User + + # Create your tests here. class MovieTest(TestCase): def test_movie(self): - movie = Movies.objects.create(title="Test Movie", length_in_minutes=100, released_at="2020-01-01", country_of_origin="NL", summary="Test summary", youtube_trailer_id="123456789") + movie = Movies.objects.create( + title="Test Movie", + length_in_minutes=100, + released_at="2020-01-01", + country_of_origin="NL", + summary="Test summary", + youtube_trailer_id="123456789", + ) self.assertEqual(movie.title, "Test Movie") self.assertEqual(movie.length_in_minutes, 100) self.assertEqual(movie.released_at, "2020-01-01") self.assertEqual(movie.country_of_origin, "NL") self.assertEqual(movie.summary, "Test summary") self.assertEqual(movie.youtube_trailer_id, "123456789") - + def test_movie2(self): - movie = Movies.objects.create(title="Test Movie2", length_in_minutes=100, released_at="2020-01-01", country_of_origin="NL", summary="Test summary", youtube_trailer_id="123456789") + movie = Movies.objects.create( + title="Test Movie2", + length_in_minutes=100, + released_at="2020-01-01", + country_of_origin="NL", + summary="Test summary", + youtube_trailer_id="123456789", + ) self.assertEqual(movie.title, "Test Movie2") self.assertEqual(movie.length_in_minutes, 100) self.assertEqual(movie.released_at, "2020-01-01") @@ -23,41 +40,99 @@ def test_movie2(self): self.assertEqual(movie.summary, "Test summary") self.assertEqual(movie.youtube_trailer_id, "123456789") + class MovieViewsTest(TestCase): def setUp(self): - self.movie1 = Movies.objects.create(title="Test Movie", length_in_minutes=100, released_at="2020-01-01", country_of_origin="NL", summary="Test summary", youtube_trailer_id="123456789") - self.movie2 = Movies.objects.create(title="Test Movie2", length_in_minutes=100, released_at="2020-01-01", country_of_origin="NL", summary="Test summary", youtube_trailer_id="123456789") - self.movie3 = Movies.objects.create(title="Test Movie3", length_in_minutes=100, released_at="2020-01-01", country_of_origin="NL", summary="Test summary", youtube_trailer_id="123456789") - self.movie4 = Movies.objects.create(title="Test Movie4", length_in_minutes=100, released_at="2020-01-01", country_of_origin="NL", summary="Test summary", youtube_trailer_id="123456789") - self.user = User.objects.create_user(username='root', password='test') - self.client.login(username='root', password='test') + self.movie1 = Movies.objects.create( + title="Test Movie", + length_in_minutes=100, + released_at="2020-01-01", + country_of_origin="NL", + summary="Test summary", + youtube_trailer_id="123456789", + ) + self.movie2 = Movies.objects.create( + title="Test Movie2", + length_in_minutes=100, + released_at="2020-01-01", + country_of_origin="NL", + summary="Test summary", + youtube_trailer_id="123456789", + ) + self.movie3 = Movies.objects.create( + title="Test Movie3", + length_in_minutes=100, + released_at="2020-01-01", + country_of_origin="NL", + summary="Test summary", + youtube_trailer_id="123456789", + ) + self.movie4 = Movies.objects.create( + title="Test Movie4", + length_in_minutes=100, + released_at="2020-01-01", + country_of_origin="NL", + summary="Test summary", + youtube_trailer_id="123456789", + ) + self.user = User.objects.create_user(username="root", password="test") + self.client.login(username="root", password="test") def test_index(self): - url = reverse('index') + url = reverse("index") response = self.client.get(url) self.assertEqual(response.status_code, 200) - + def test_detailmovie(self): - url = reverse('detailmovie', kwargs={'pk': self.movie1.pk}) + url = reverse("detailmovie", kwargs={"pk": self.movie1.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200) def test_updatemovie(self): - url = reverse('updatemovie', kwargs={'pk': self.movie1.pk}) + url = reverse("updatemovie", kwargs={"pk": self.movie1.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200) + class MovieViewsTestContent(TestCase): def setUp(self): - self.movie1 = Movies.objects.create(title="Test Movie", length_in_minutes=100, released_at="2020-01-01", country_of_origin="NL", summary="Test summary", youtube_trailer_id="123456789") - self.movie2 = Movies.objects.create(title="Test Movie2", length_in_minutes=100, released_at="2020-01-01", country_of_origin="NL", summary="Test summary", youtube_trailer_id="123456789") - self.movie3 = Movies.objects.create(title="Test Movie3", length_in_minutes=100, released_at="2020-01-01", country_of_origin="NL", summary="Test summary", youtube_trailer_id="123456789") - self.movie4 = Movies.objects.create(title="Test Movie4", length_in_minutes=100, released_at="2020-01-01", country_of_origin="NL", summary="Test summary", youtube_trailer_id="123456789") - self.user = User.objects.create_user(username='root', password='test') - self.client.login(username='root', password='test') - + self.movie1 = Movies.objects.create( + title="Test Movie", + length_in_minutes=100, + released_at="2020-01-01", + country_of_origin="NL", + summary="Test summary", + youtube_trailer_id="123456789", + ) + self.movie2 = Movies.objects.create( + title="Test Movie2", + length_in_minutes=100, + released_at="2020-01-01", + country_of_origin="NL", + summary="Test summary", + youtube_trailer_id="123456789", + ) + self.movie3 = Movies.objects.create( + title="Test Movie3", + length_in_minutes=100, + released_at="2020-01-01", + country_of_origin="NL", + summary="Test summary", + youtube_trailer_id="123456789", + ) + self.movie4 = Movies.objects.create( + title="Test Movie4", + length_in_minutes=100, + released_at="2020-01-01", + country_of_origin="NL", + summary="Test summary", + youtube_trailer_id="123456789", + ) + self.user = User.objects.create_user(username="root", password="test") + self.client.login(username="root", password="test") + def test_index(self): - url = reverse('index') + url = reverse("index") response = self.client.get(url) self.assertContains(response, self.movie1.title) self.assertContains(response, self.movie2.title) @@ -65,7 +140,7 @@ def test_index(self): self.assertContains(response, self.movie4.title) def test_detailmovie(self): - url = reverse('detailmovie', kwargs={'pk': self.movie1.pk}) + url = reverse("detailmovie", kwargs={"pk": self.movie1.pk}) response = self.client.get(url) self.assertContains(response, self.movie1.title) self.assertContains(response, self.movie1.length_in_minutes) @@ -73,11 +148,11 @@ def test_detailmovie(self): self.assertContains(response, self.movie1.summary) def test_updatemovie(self): - url = reverse('updatemovie', kwargs={'pk': self.movie1.pk}) + url = reverse("updatemovie", kwargs={"pk": self.movie1.pk}) response = self.client.get(url) self.assertContains(response, self.movie1.title) self.assertContains(response, self.movie1.length_in_minutes) self.assertContains(response, self.movie1.released_at) self.assertContains(response, self.movie1.country_of_origin) self.assertContains(response, self.movie1.summary) - self.assertContains(response, self.movie1.youtube_trailer_id) \ No newline at end of file + self.assertContains(response, self.movie1.youtube_trailer_id) diff --git a/src/netland/movie/urls.py b/src/netland/movie/urls.py index 5f41e4d..725c42e 100644 --- a/src/netland/movie/urls.py +++ b/src/netland/movie/urls.py @@ -1,10 +1,11 @@ from django.urls import path + from .models import * from .views import * urlpatterns = [ - path('deletemovie/', DeleteMovie.as_view(), name='deletemovie'), - path('updatemovie//', UpdateMovie.as_view(), name='updatemovie'), - path('movie//', DetailMovie.as_view(), name='detailmovie'), - path('createmovie/', CreateMovie.as_view(), name='createmovie'), -] \ No newline at end of file + path("deletemovie/", DeleteMovie.as_view(), name="deletemovie"), + path("updatemovie//", UpdateMovie.as_view(), name="updatemovie"), + path("movie//", DetailMovie.as_view(), name="detailmovie"), + path("createmovie/", CreateMovie.as_view(), name="createmovie"), +] diff --git a/src/netland/movie/views.py b/src/netland/movie/views.py index 8fbbabb..9906bfa 100644 --- a/src/netland/movie/views.py +++ b/src/netland/movie/views.py @@ -1,29 +1,33 @@ -from .models import * -from django.views import generic +from django.contrib.auth.mixins import LoginRequiredMixin from django.urls import reverse_lazy +from django.views import generic + from .forms import * +from .models import * -from django.contrib.auth.mixins import LoginRequiredMixin # Create your views here. + class DetailMovie(LoginRequiredMixin, generic.DetailView): model = Movies - template_name = 'detailmovie.html' + template_name = "detailmovie.html" + class UpdateMovie(LoginRequiredMixin, generic.UpdateView): model = Movies - template_name = 'updatemovie.html' + template_name = "updatemovie.html" form_class = MovieForm - success_url = reverse_lazy('index') + success_url = reverse_lazy("index") + class DeleteMovie(LoginRequiredMixin, generic.DeleteView): model = Movies - template_name = 'deletemovie.html' - success_url = reverse_lazy('index') + template_name = "deletemovie.html" + success_url = reverse_lazy("index") + class CreateMovie(LoginRequiredMixin, generic.CreateView): model = Movies - template_name = 'createmovie.html' + template_name = "createmovie.html" form_class = MovieForm() - success_url = reverse_lazy('index') - \ No newline at end of file + success_url = reverse_lazy("index") diff --git a/src/netland/serie/admin.py b/src/netland/serie/admin.py index b7b7efa..f8ec3a2 100644 --- a/src/netland/serie/admin.py +++ b/src/netland/serie/admin.py @@ -1,4 +1,6 @@ from django.contrib import admin + from .models import * + # Register your models here. admin.site.register(Series) diff --git a/src/netland/serie/apps.py b/src/netland/serie/apps.py index b01c209..7c93bb3 100644 --- a/src/netland/serie/apps.py +++ b/src/netland/serie/apps.py @@ -2,5 +2,5 @@ class SerieConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'netland.serie' + default_auto_field = "django.db.models.BigAutoField" + name = "netland.serie" diff --git a/src/netland/serie/forms.py b/src/netland/serie/forms.py index 9b59112..4280b97 100644 --- a/src/netland/serie/forms.py +++ b/src/netland/serie/forms.py @@ -1,16 +1,26 @@ from django import forms + from .models import Series + class SerieForm(forms.ModelForm): class Meta: model = Series - fields = ['title', 'rating', 'has_won_awards', 'country', 'summary', 'seasons', 'spoken_in_language'] + fields = [ + "title", + "rating", + "has_won_awards", + "country", + "summary", + "seasons", + "spoken_in_language", + ] wdigets = { - 'title': forms.TextInput(attrs={'class': 'form-control'}), - 'rating': forms.NumberInput(attrs={'class': 'form-control'}), - 'has_won_awards': forms.NumberInput(attrs={'class': 'form-control'}), - 'country': forms.TextInput(attrs={'class': 'form-control'}), - 'summary': forms.Textarea(attrs={'class': 'form-control'}), - 'seasons': forms.NumberInput(attrs={'class': 'form-control'}), - 'spoken_in_language': forms.TextInput(attrs={'class': 'form-control'}), - } \ No newline at end of file + "title": forms.TextInput(attrs={"class": "form-control"}), + "rating": forms.NumberInput(attrs={"class": "form-control"}), + "has_won_awards": forms.NumberInput(attrs={"class": "form-control"}), + "country": forms.TextInput(attrs={"class": "form-control"}), + "summary": forms.Textarea(attrs={"class": "form-control"}), + "seasons": forms.NumberInput(attrs={"class": "form-control"}), + "spoken_in_language": forms.TextInput(attrs={"class": "form-control"}), + } diff --git a/src/netland/serie/management/commands/series_rating.py b/src/netland/serie/management/commands/series_rating.py index d265b72..edf02b9 100644 --- a/src/netland/serie/management/commands/series_rating.py +++ b/src/netland/serie/management/commands/series_rating.py @@ -1,13 +1,17 @@ -from django.core.management.base import BaseCommand, CommandError -from serie.models import Series from django.core.mail import send_mail +from django.core.management.base import BaseCommand, CommandError from django.utils.html import strip_tags +from serie.models import Series + + class Command(BaseCommand): - help = "Automatically check each week for the top 3 based on the rating of the series" + help = ( + "Automatically check each week for the top 3 based on the rating of the series" + ) def handle(self, *args, **options): - series = Series.objects.all().order_by('-rating')[:3] + series = Series.objects.all().order_by("-rating")[:3] body = """

Hello!

@@ -24,11 +28,18 @@ def handle(self, *args, **options): \ \/ \/ / _ \ | | / _` |/ _ \| '_ \ / _ \ | | \ /\ / __/ | | | (_| | (_) | | | | __/ |_| \/ \/ \___|_|_| \__,_|\___/|_| |_|\___| (_) - """.format(series[0].title, series[0].rating, series[1].title, series[1].rating, series[2].title, series[2].rating) + """.format( + series[0].title, + series[0].rating, + series[1].title, + series[1].rating, + series[2].title, + series[2].rating, + ) send_mail( - 'Top 3 series', + "Top 3 series", strip_tags(body), - 'test@gmail.nl', - ['erhan.citil@maykinmedia.nl'], - ) \ No newline at end of file + "test@gmail.nl", + ["erhan.citil@maykinmedia.nl"], + ) diff --git a/src/netland/serie/migrations/0001_initial.py b/src/netland/serie/migrations/0001_initial.py index 867ff38..b99ba47 100644 --- a/src/netland/serie/migrations/0001_initial.py +++ b/src/netland/serie/migrations/0001_initial.py @@ -4,27 +4,38 @@ class Migration(migrations.Migration): - initial = True - dependencies = [ - ] + dependencies = [] operations = [ migrations.CreateModel( - name='Series', + name="Series", fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=100)), - ('rating', models.DecimalField(blank=True, decimal_places=1, max_digits=2, null=True)), - ('summary', models.TextField()), - ('has_won_awards', models.IntegerField()), - ('seasons', models.IntegerField()), - ('country', models.CharField(max_length=2)), - ('spoken_in_language', models.CharField(max_length=2)), + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=100)), + ( + "rating", + models.DecimalField( + blank=True, decimal_places=1, max_digits=2, null=True + ), + ), + ("summary", models.TextField()), + ("has_won_awards", models.IntegerField()), + ("seasons", models.IntegerField()), + ("country", models.CharField(max_length=2)), + ("spoken_in_language", models.CharField(max_length=2)), ], options={ - 'db_table': 'series', + "db_table": "series", }, ), ] diff --git a/src/netland/serie/models.py b/src/netland/serie/models.py index 55fd83e..d8e5159 100644 --- a/src/netland/serie/models.py +++ b/src/netland/serie/models.py @@ -2,6 +2,7 @@ # Create your models here. + class Series(models.Model): title = models.CharField(max_length=100) rating = models.DecimalField(max_digits=2, decimal_places=1, blank=True, null=True) @@ -12,4 +13,4 @@ class Series(models.Model): spoken_in_language = models.CharField(max_length=2) class Meta: - db_table = 'series' \ No newline at end of file + db_table = "series" diff --git a/src/netland/serie/tests/test_management_command.py b/src/netland/serie/tests/test_management_command.py index 48bd0e2..c81bcc6 100644 --- a/src/netland/serie/tests/test_management_command.py +++ b/src/netland/serie/tests/test_management_command.py @@ -1,41 +1,94 @@ -from django.test import TestCase +from django.core import mail from django.core.management import call_command +from django.test import TestCase + from serie.models import Series -from django.core import mail + class SeriesRatingTest(TestCase): def setUp(self): - Series.objects.create(title='The Walking Dead', rating=9.0, summary='A group of survivors travel through a post-apocalyptic world, holding on to the hope of humanity by banding together to fight against the zombies that threaten their lives.', has_won_awards=1, seasons=10, country='US', spoken_in_language='EN') - Series.objects.create(title='Breaking Bad', rating=9.5, summary='A high school chemistry teacher diagnosed with inoperable lung cancer turns to manufacturing and selling methamphetamine in order to secure his familys future.', has_won_awards='1', seasons='5', country='US', spoken_in_language='EN') - Series.objects.create(title='Game of Thrones', rating=9.3, summary='Nine noble families fight for control over the mythical lands of Westeros, while a forgotten', has_won_awards='1', seasons='8', country='US', spoken_in_language='EN') - Series.objects.create(title='The Big Bang Theory', rating=5.7, summary='Test', has_won_awards='1', seasons='8', country='US', spoken_in_language='EN') - Series.objects.create(title='The Simpsons', rating=8.7, summary='Test', has_won_awards='1', seasons='8', country='US', spoken_in_language='EN') - Series.objects.create(title='The Office', rating=9.9, summary='Test', has_won_awards='1', seasons='8', country='US', spoken_in_language='EN') + Series.objects.create( + title="The Walking Dead", + rating=9.0, + summary="A group of survivors travel through a post-apocalyptic world, holding on to the hope of humanity by banding together to fight against the zombies that threaten their lives.", + has_won_awards=1, + seasons=10, + country="US", + spoken_in_language="EN", + ) + Series.objects.create( + title="Breaking Bad", + rating=9.5, + summary="A high school chemistry teacher diagnosed with inoperable lung cancer turns to manufacturing and selling methamphetamine in order to secure his familys future.", + has_won_awards="1", + seasons="5", + country="US", + spoken_in_language="EN", + ) + Series.objects.create( + title="Game of Thrones", + rating=9.3, + summary="Nine noble families fight for control over the mythical lands of Westeros, while a forgotten", + has_won_awards="1", + seasons="8", + country="US", + spoken_in_language="EN", + ) + Series.objects.create( + title="The Big Bang Theory", + rating=5.7, + summary="Test", + has_won_awards="1", + seasons="8", + country="US", + spoken_in_language="EN", + ) + Series.objects.create( + title="The Simpsons", + rating=8.7, + summary="Test", + has_won_awards="1", + seasons="8", + country="US", + spoken_in_language="EN", + ) + Series.objects.create( + title="The Office", + rating=9.9, + summary="Test", + has_won_awards="1", + seasons="8", + country="US", + spoken_in_language="EN", + ) def test_rating(self): - serie = Series.objects.get(title='The Walking Dead') + serie = Series.objects.get(title="The Walking Dead") self.assertEqual(serie.rating, 9.0) - serie = Series.objects.get(title='Breaking Bad') + serie = Series.objects.get(title="Breaking Bad") self.assertEqual(serie.rating, 9.5) def test_email_has_been_sent(self): - call_command('series_rating') + call_command("series_rating") self.assertEqual(len(mail.outbox), 1) def test_email_subject(self): - call_command('series_rating') - self.assertEqual(mail.outbox[0].subject, 'Top 3 series') + call_command("series_rating") + self.assertEqual(mail.outbox[0].subject, "Top 3 series") def test_email_body(self): - call_command('series_rating') + call_command("series_rating") for email in mail.outbox: - self.assertEqual(email.body.count('This is the top 3 of the series based on the rating:'), 1) - + self.assertEqual( + email.body.count( + "This is the top 3 of the series based on the rating:" + ), + 1, + ) + def test_top_three_series(self): - call_command('series_rating') + call_command("series_rating") for email in mail.outbox: - self.assertEqual(email.body.count('The Office'), 1) - self.assertEqual(email.body.count('Breaking Bad'), 1) - self.assertEqual(email.body.count('Game of Thrones'), 1) - - \ No newline at end of file + self.assertEqual(email.body.count("The Office"), 1) + self.assertEqual(email.body.count("Breaking Bad"), 1) + self.assertEqual(email.body.count("Game of Thrones"), 1) diff --git a/src/netland/serie/tests/test_model.py b/src/netland/serie/tests/test_model.py index adcb126..20da233 100644 --- a/src/netland/serie/tests/test_model.py +++ b/src/netland/serie/tests/test_model.py @@ -1,37 +1,68 @@ from django.test import TestCase + from ..models import * from ..views import * + class SerieTestCase(TestCase): def setUp(self): - Series.objects.create(title='The Walking Dead', rating=9.0, summary='A group of survivors travel through a post-apocalyptic world, holding on to the hope of humanity by banding together to fight against the zombies that threaten their lives.', has_won_awards=1, seasons=10, country='US', spoken_in_language='EN') - Series.objects.create(title='Breaking Bad', rating='9.5', summary='A high school chemistry teacher diagnosed with inoperable lung cancer turns to manufacturing and selling methamphetamine in order to secure his familys future.', has_won_awards='1', seasons='5', country='US', spoken_in_language='EN') - Series.objects.create(title='Game of Thrones', rating='9.3', summary='Nine noble families fight for control over the mythical lands of Westeros, while a forgotten', has_won_awards='1', seasons='8', country='US', spoken_in_language='EN') + Series.objects.create( + title="The Walking Dead", + rating=9.0, + summary="A group of survivors travel through a post-apocalyptic world, holding on to the hope of humanity by banding together to fight against the zombies that threaten their lives.", + has_won_awards=1, + seasons=10, + country="US", + spoken_in_language="EN", + ) + Series.objects.create( + title="Breaking Bad", + rating="9.5", + summary="A high school chemistry teacher diagnosed with inoperable lung cancer turns to manufacturing and selling methamphetamine in order to secure his familys future.", + has_won_awards="1", + seasons="5", + country="US", + spoken_in_language="EN", + ) + Series.objects.create( + title="Game of Thrones", + rating="9.3", + summary="Nine noble families fight for control over the mythical lands of Westeros, while a forgotten", + has_won_awards="1", + seasons="8", + country="US", + spoken_in_language="EN", + ) def test_title(self): - serie = Series.objects.get(title='The Walking Dead') - self.assertEqual(serie.title, 'The Walking Dead') - + serie = Series.objects.get(title="The Walking Dead") + self.assertEqual(serie.title, "The Walking Dead") + def test_rating(self): serie = Series.objects.get(rating=9.0) self.assertEqual(serie.rating, 9.0) - + def test_summary(self): - serie = Series.objects.get(summary='A group of survivors travel through a post-apocalyptic world, holding on to the hope of humanity by banding together to fight against the zombies that threaten their lives.') - self.assertEqual(serie.summary, 'A group of survivors travel through a post-apocalyptic world, holding on to the hope of humanity by banding together to fight against the zombies that threaten their lives.') - + serie = Series.objects.get( + summary="A group of survivors travel through a post-apocalyptic world, holding on to the hope of humanity by banding together to fight against the zombies that threaten their lives." + ) + self.assertEqual( + serie.summary, + "A group of survivors travel through a post-apocalyptic world, holding on to the hope of humanity by banding together to fight against the zombies that threaten their lives.", + ) + def test_has_won_awards(self): - for serie in Series.objects.all(): - self.assertEqual(serie.has_won_awards, 1) - + for serie in Series.objects.all(): + self.assertEqual(serie.has_won_awards, 1) + def test_seasons(self): serie = Series.objects.get(seasons=10) self.assertEqual(serie.seasons, 10) - + def test_country(self): for serie in Series.objects.all(): - self.assertEqual(serie.country, 'US') - + self.assertEqual(serie.country, "US") + def test_spoken_in_language(self): for serie in Series.objects.all(): - self.assertEqual(serie.spoken_in_language, 'EN') \ No newline at end of file + self.assertEqual(serie.spoken_in_language, "EN") diff --git a/src/netland/serie/tests/test_views.py b/src/netland/serie/tests/test_views.py index f3bf6bc..15c7647 100644 --- a/src/netland/serie/tests/test_views.py +++ b/src/netland/serie/tests/test_views.py @@ -1,50 +1,102 @@ +from django.contrib.auth.models import User from django.test import TestCase +from django.urls import reverse + from ..models import * from ..views import * -from django.urls import reverse -from django.contrib.auth.models import User + class SerieViewTestCase(TestCase): def setUp(self): - self.series1 = Series.objects.create(title='The Walking Dead', rating=9.0, summary='A group of survivors travel through a post-apocalyptic world, holding on to the hope of humanity by banding together to fight against the zombies that threaten their lives.', has_won_awards=1, seasons=10, country='US', spoken_in_language='EN') - self.series2 = Series.objects.create(title='Breaking Bad', rating=9.5, summary='A high school chemistry teacher diagnosed with inoperable lung cancer turns to manufacturing and selling methamphetamine in order to secure his familys future.', has_won_awards='1', seasons='5', country='US', spoken_in_language='EN') - self.series3 = Series.objects.create(title='Game of Thrones', rating=9.3, summary='Nine noble families fight for control over the mythical lands of Westeros, while a forgotten', has_won_awards='1', seasons='8', country='US', spoken_in_language='EN') - self.user = User.objects.create_user(username='root', password='test') - self.client.login(username='root', password='test') + self.series1 = Series.objects.create( + title="The Walking Dead", + rating=9.0, + summary="A group of survivors travel through a post-apocalyptic world, holding on to the hope of humanity by banding together to fight against the zombies that threaten their lives.", + has_won_awards=1, + seasons=10, + country="US", + spoken_in_language="EN", + ) + self.series2 = Series.objects.create( + title="Breaking Bad", + rating=9.5, + summary="A high school chemistry teacher diagnosed with inoperable lung cancer turns to manufacturing and selling methamphetamine in order to secure his familys future.", + has_won_awards="1", + seasons="5", + country="US", + spoken_in_language="EN", + ) + self.series3 = Series.objects.create( + title="Game of Thrones", + rating=9.3, + summary="Nine noble families fight for control over the mythical lands of Westeros, while a forgotten", + has_won_awards="1", + seasons="8", + country="US", + spoken_in_language="EN", + ) + self.user = User.objects.create_user(username="root", password="test") + self.client.login(username="root", password="test") def test_index(self): - response = self.client.get('/') + response = self.client.get("/") self.assertEqual(response.status_code, 200) def test_detail(self): - url = reverse('detailserie', kwargs={'pk': self.series1.pk}) + url = reverse("detailserie", kwargs={"pk": self.series1.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200) - + def test_update(self): - url = reverse('updateserie', kwargs={'pk': self.series1.pk}) + url = reverse("updateserie", kwargs={"pk": self.series1.pk}) response = self.client.get(url) self.assertEqual(response.status_code, 200) - + def test_create(self): - response = self.client.get('/createserie/') + response = self.client.get("/createserie/") self.assertEqual(response.status_code, 200) + class SerieViewTestContent(TestCase): def setUp(self): - self.series1 = Series.objects.create(title='The Walking Dead', rating=9.0, summary='A group of survivors travel through a post-apocalyptic world, holding on to the hope of humanity by banding together to fight against the zombies that threaten their lives.', has_won_awards=1, seasons=10, country='US', spoken_in_language='EN') - self.series2 = Series.objects.create(title='Breaking Bad', rating=9.5, summary='A high school chemistry teacher diagnosed with inoperable lung cancer turns to manufacturing and selling methamphetamine in order to secure his familys future.', has_won_awards='1', seasons='5', country='US', spoken_in_language='EN') - self.series3 = Series.objects.create(title='Game of Thrones', rating=9.3, summary='Nine noble families fight for control over the mythical lands of Westeros, while a forgotten', has_won_awards='1', seasons='8', country='US', spoken_in_language='EN') - self.user = User.objects.create_user(username='root', password='test') - self.client.login(username='root', password='test') + self.series1 = Series.objects.create( + title="The Walking Dead", + rating=9.0, + summary="A group of survivors travel through a post-apocalyptic world, holding on to the hope of humanity by banding together to fight against the zombies that threaten their lives.", + has_won_awards=1, + seasons=10, + country="US", + spoken_in_language="EN", + ) + self.series2 = Series.objects.create( + title="Breaking Bad", + rating=9.5, + summary="A high school chemistry teacher diagnosed with inoperable lung cancer turns to manufacturing and selling methamphetamine in order to secure his familys future.", + has_won_awards="1", + seasons="5", + country="US", + spoken_in_language="EN", + ) + self.series3 = Series.objects.create( + title="Game of Thrones", + rating=9.3, + summary="Nine noble families fight for control over the mythical lands of Westeros, while a forgotten", + has_won_awards="1", + seasons="8", + country="US", + spoken_in_language="EN", + ) + self.user = User.objects.create_user(username="root", password="test") + self.client.login(username="root", password="test") + def test_index(self): - response = self.client.get('/') - self.assertContains(response, 'The Walking Dead') - self.assertContains(response, 'Breaking Bad') - self.assertContains(response, 'Game of Thrones') - + response = self.client.get("/") + self.assertContains(response, "The Walking Dead") + self.assertContains(response, "Breaking Bad") + self.assertContains(response, "Game of Thrones") + def test_detail(self): - url = reverse('detailserie', kwargs={'pk': self.series1.pk}) + url = reverse("detailserie", kwargs={"pk": self.series1.pk}) response = self.client.get(url) self.assertContains(response, self.series1.title) self.assertContains(response, self.series1.rating) @@ -53,9 +105,9 @@ def test_detail(self): self.assertContains(response, self.series1.seasons) self.assertContains(response, self.series1.country) self.assertContains(response, self.series1.spoken_in_language) - + def test_update(self): - url = reverse('updateserie', kwargs={'pk': self.series1.pk}) + url = reverse("updateserie", kwargs={"pk": self.series1.pk}) response = self.client.get(url) self.assertContains(response, self.series1.title) self.assertContains(response, self.series1.rating) @@ -63,4 +115,4 @@ def test_update(self): self.assertContains(response, self.series1.has_won_awards) self.assertContains(response, self.series1.seasons) self.assertContains(response, self.series1.country) - self.assertContains(response, self.series1.spoken_in_language) \ No newline at end of file + self.assertContains(response, self.series1.spoken_in_language) diff --git a/src/netland/serie/urls.py b/src/netland/serie/urls.py index 093d28a..d31a8df 100644 --- a/src/netland/serie/urls.py +++ b/src/netland/serie/urls.py @@ -1,11 +1,12 @@ from django.urls import path + from .models import * from .views import * urlpatterns = [ - path('', Index.as_view(), name='index'), - path('serie/', DetailSerie.as_view(), name='detailserie'), - path('updateserie/', UpdateSerie.as_view(), name='updateserie'), - path('deleteserie/', DeleteSerie.as_view(), name='deleteserie'), - path('createserie/', CreateSerie.as_view(), name='createserie'), -] \ No newline at end of file + path("", Index.as_view(), name="index"), + path("serie/", DetailSerie.as_view(), name="detailserie"), + path("updateserie/", UpdateSerie.as_view(), name="updateserie"), + path("deleteserie/", DeleteSerie.as_view(), name="deleteserie"), + path("createserie/", CreateSerie.as_view(), name="createserie"), +] diff --git a/src/netland/serie/views.py b/src/netland/serie/views.py index 4f05ec6..269e3a3 100644 --- a/src/netland/serie/views.py +++ b/src/netland/serie/views.py @@ -1,37 +1,44 @@ -from .models import * -from django.views import generic +from django.contrib.auth.mixins import LoginRequiredMixin from django.urls import reverse_lazy +from django.views import generic + from netland.movie.models import * + from .forms import * +from .models import * + -from django.contrib.auth.mixins import LoginRequiredMixin # Create your views here. class Index(LoginRequiredMixin, generic.ListView): model = Series - template_name = 'index.html' - context_object_name = 'series' + template_name = "index.html" + context_object_name = "series" def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context['movies'] = Movies.objects.all() + context["movies"] = Movies.objects.all() return context + class DetailSerie(LoginRequiredMixin, generic.DetailView): model = Series - template_name = 'detailserie.html' + template_name = "detailserie.html" + class UpdateSerie(LoginRequiredMixin, generic.UpdateView): model = Series - template_name = 'updateserie.html' + template_name = "updateserie.html" form_class = SerieForm - success_url = reverse_lazy('index') + success_url = reverse_lazy("index") + class DeleteSerie(LoginRequiredMixin, generic.DeleteView): model = Series - success_url = reverse_lazy('index') + success_url = reverse_lazy("index") + class CreateSerie(LoginRequiredMixin, generic.CreateView): model = Movies - template_name = 'createmovie.html' + template_name = "createmovie.html" form_class = SerieForm - success_url = reverse_lazy('index') + success_url = reverse_lazy("index") diff --git a/src/netland/setup.py b/src/netland/setup.py index 28cfc7e..fe98231 100644 --- a/src/netland/setup.py +++ b/src/netland/setup.py @@ -40,9 +40,7 @@ def monkeypatch_requests(): try: from requests import Session except ModuleNotFoundError: - logger.debug( - "Attempt to patch requests, but the library is not installed" - ) + logger.debug("Attempt to patch requests, but the library is not installed") return if hasattr(Session, "_original_request"): diff --git a/src/netland/urls.py b/src/netland/urls.py index ed7b577..db0c0c8 100644 --- a/src/netland/urls.py +++ b/src/netland/urls.py @@ -38,9 +38,9 @@ name="password_reset_complete", ), # Simply show the master template. - path('', include('netland.movie.urls')), - path('', include('netland.serie.urls')), - path('', include('netland.login.urls')), + path("", include("netland.movie.urls")), + path("", include("netland.serie.urls")), + path("", include("netland.login.urls")), ] # NOTE: The staticfiles_urlpatterns also discovers static files (ie. no need to run collectstatic). Both the static diff --git a/src/netland/utils/context_processors.py b/src/netland/utils/context_processors.py index 1994b63..438eebf 100644 --- a/src/netland/utils/context_processors.py +++ b/src/netland/utils/context_processors.py @@ -10,9 +10,7 @@ def settings(request): ) context = { - "settings": { - k: getattr(django_settings, k, None) for k in public_settings - }, + "settings": {k: getattr(django_settings, k, None) for k in public_settings}, } if hasattr(django_settings, "SENTRY_CONFIG"): diff --git a/src/netland/utils/migration_operations.py b/src/netland/utils/migration_operations.py index b7291a3..c01cf0c 100644 --- a/src/netland/utils/migration_operations.py +++ b/src/netland/utils/migration_operations.py @@ -45,7 +45,6 @@ def database_forwards(self, app_label, schema_editor, from_state, to_state) -> N if router.allow_migrate( schema_editor.connection.alias, app_label, **self.hints ): - base_sql = _get_reset_sql() with schema_editor.connection.cursor() as cursor: diff --git a/src/netland/utils/tests/test_celery_beat.py b/src/netland/utils/tests/test_celery_beat.py index ad3a4e3..a83e04e 100644 --- a/src/netland/utils/tests/test_celery_beat.py +++ b/src/netland/utils/tests/test_celery_beat.py @@ -6,7 +6,10 @@ class BeatConfigTests(SimpleTestCase): - @skipIf(not hasattr(settings, "CELERY_BEAT_SCHEDULE"), "Project does not have celery (beat config)") + @skipIf( + not hasattr(settings, "CELERY_BEAT_SCHEDULE"), + "Project does not have celery (beat config)", + ) def test_task_references_correct(self): """ Assert that the task import paths in the Beat config are valid.