diff --git a/helloworld/apps.py b/helloworld/apps.py deleted file mode 100644 index cc315751252ab1eeb34988211f00c70fde410a9a..0000000000000000000000000000000000000000 --- a/helloworld/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class HelloworldConfig(AppConfig): - name = 'helloworld' diff --git a/helloworld/templates/helloworld.html b/helloworld/templates/helloworld.html deleted file mode 100644 index 8787fecdf94292a24bbaf227b795ba3ee738a539..0000000000000000000000000000000000000000 --- a/helloworld/templates/helloworld.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - Konnichihello - - - Hello World1 - - \ No newline at end of file diff --git a/helloworld/urls.py b/helloworld/urls.py deleted file mode 100644 index e158ede24f6b5bfce907c527a281b455ff31e202..0000000000000000000000000000000000000000 --- a/helloworld/urls.py +++ /dev/null @@ -1,10 +0,0 @@ -from django.conf.urls import url -from django.urls import path -from .views import helloworld -from . import views - -app_name = "helloworld" - -urlpatterns = [ - path('', views.helloworld, name='helloworld'), -] \ No newline at end of file diff --git a/helloworld/views.py b/helloworld/views.py deleted file mode 100644 index cce7cb0fdae763ac51bfbaa9e808b79f9a85f81f..0000000000000000000000000000000000000000 --- a/helloworld/views.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.shortcuts import render - -# Create your views here. -def helloworld(request): - return render(request, 'helloworld.html') diff --git a/informasi_fasilitas/migrations/0001_initial.py b/informasi_fasilitas/migrations/0001_initial.py index ed7a7c2dad3c8d9641497acfa55c609198d4153b..011d7c2af9ff02d405e4eb24692f59c2d25fa233 100644 --- a/informasi_fasilitas/migrations/0001_initial.py +++ b/informasi_fasilitas/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.1.5 on 2020-04-17 10:26 +# Generated by Django 2.1.5 on 2020-04-18 09:06 from django.conf import settings from django.db import migrations, models diff --git a/informasi_fasilitas/models.py b/informasi_fasilitas/models.py index 1d1c70b1bf79872a6dc6f7fd579e34266076e717..e0989103494bca1b0ec4fbb3bb05d0d4be67a05c 100644 --- a/informasi_fasilitas/models.py +++ b/informasi_fasilitas/models.py @@ -18,7 +18,7 @@ RUNNING_TEXT = 'RT' TEMPAT_PARKIR_BIASA = 'TB' FACILITIES = ( - ((KURSI_RODA, 'Kursi Roda'), + (KURSI_RODA, 'Kursi Roda'), (LIFT_DISABILITAS, 'Lift Disabilitas'), (TOILET_DISABILITTAS, 'Toilet Disabilitas'), (MASJID_MUSHOLA, 'Masjid/Mushola'), @@ -30,8 +30,9 @@ FACILITIES = ( (KURSI_UMUM_DISABILITAS, 'Kursi Umum Disabilitas'), (TEMPAT_PARKIR_DISABILITAS, 'Tempat Parkir Disabilitas'), (RUNNING_TEXT, 'Running Text'), - (TEMPAT_PARKIR_BIASA, 'Tempat Parkir Biasa')) -) + (TEMPAT_PARKIR_BIASA, 'Tempat Parkir Biasa') + ) + class Lokasi(models.Model): name = models.CharField(max_length=50) diff --git a/informasi_fasilitas/tests.py b/informasi_fasilitas/tests.py index e2e1015566151b1522c661ee91acd9182711405c..be8ad0b5f6d6c321f5db357737624653e6d979ad 100644 --- a/informasi_fasilitas/tests.py +++ b/informasi_fasilitas/tests.py @@ -1,18 +1,19 @@ from django.test import TestCase from django.db.utils import IntegrityError from .models import Lokasi, Fasilitas, Komentar, KURSI_RODA, RUNNING_TEXT -# from registrasi.models import User +from registrasi.models import BisaGoUser from django.contrib.auth.models import User import tempfile # Create your tests here. -class Informasi_Fasilitas_Test(TestCase): +class InformasiFasilitasTest(TestCase): + not_null_constraint_failed_message = 'NOT NULL constraint failed' def test_models_lokasi_not_created(self): with self.assertRaises(IntegrityError) as cm: obj = Lokasi(name=None) - obj.save(); - self.assertTrue(str(cm.exception).startswith('NOT NULL constraint failed')) + obj.save() + self.assertTrue(str(cm.exception).startswith(self.not_null_constraint_failed_message)) def test_models_create_new_lokasi(self): image = tempfile.NamedTemporaryFile(suffix=".jpg").name @@ -30,8 +31,8 @@ class Informasi_Fasilitas_Test(TestCase): def test_models_fasilitas_not_created(self): with self.assertRaises(IntegrityError) as cm: obj = Fasilitas(lokasi=None) - obj.save(); - self.assertTrue(str(cm.exception).startswith('NOT NULL constraint failed')) + obj.save() + self.assertTrue(str(cm.exception).startswith(self.not_null_constraint_failed_message)) def test_models_create_new_fasilitas(self): image = tempfile.NamedTemporaryFile(suffix=".jpg").name @@ -68,7 +69,7 @@ class Informasi_Fasilitas_Test(TestCase): with self.assertRaises(IntegrityError) as cm: obj = Komentar(fasilitas=None) obj.save(); - self.assertTrue(str(cm.exception).startswith('NOT NULL constraint failed')) + self.assertTrue(str(cm.exception).startswith(self.not_null_constraint_failed_message)) def test_models_create_new_komentar(self): image = tempfile.NamedTemporaryFile(suffix=".jpg").name diff --git a/informasi_fasilitas/urls.py b/informasi_fasilitas/urls.py index 09831e3849b1cfe0bd898f228ee6da4b757a1af8..1d83264e03545136326aad91f97765abac288b05 100644 --- a/informasi_fasilitas/urls.py +++ b/informasi_fasilitas/urls.py @@ -2,12 +2,7 @@ from django.urls import path, include from rest_framework import routers from . import views -#router = routers.DefaultRouter() -#router.register(r'lokasis', views.LokasiViewSet) - urlpatterns = [ - #path('', include(router.urls)), - #path('api-auth/', include('rest_framework.urls', namespace='rest_framework')) path('lokasi/list/', views.lokasi_list,name='lokasi-list'), path('lokasi/detail/', views.lokasi_details,name='lokasi-details'), path('lokasi/add/', views.add_lokasi,name='add-lokasi'), diff --git a/informasi_fasilitas/views.py b/informasi_fasilitas/views.py index 93822de4092ccb7efdc668cbb6a2317ba3a49456..62ff37f99e9639fb2a02a7e025732f24658e9a69 100644 --- a/informasi_fasilitas/views.py +++ b/informasi_fasilitas/views.py @@ -10,11 +10,11 @@ from rest_framework.authentication import TokenAuthentication from .serializers import LokasiSerializer from .models import Lokasi, Fasilitas, Komentar -# Create your views here. +def request_error_message(request_kind): + return "get {} request instead".format(request_kind) -#class LokasiViewSet(viewsets.ModelViewSet): -# queryset = Lokasi.objects.all().order_by('name') -# serializer_class = LokasiSerializer +def missing_key_message(key): + return "bad request. {} key needed".format(key) @csrf_exempt @api_view(['GET']) @@ -26,7 +26,7 @@ def lokasi_list(request): serializer = LokasiSerializer(lokasi_list, many=True) return JsonResponse(serializer.data, safe=False) else: - return JsonResponse({'response' : 'try get request instead'}, status = 400) + return JsonResponse({'response' : request_error_message("get")}, status = 400) @api_view(['GET']) @authentication_classes([]) @@ -38,9 +38,9 @@ def lokasi_details(request,name): serializer = LokasiSerializer(lokasi) return JsonResponse(serializer.data, safe=False) else: - return JsonResponse({'response' : 'try get request instead'}, status = 400) + return JsonResponse({'response' : request_error_message("get")}, status = 400) except KeyError as e: - return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500) + return JsonResponse({'response': missing_key_message(str(e))}, status = 500) except: return JsonResponse({'response':'lokasi not found'}, status = 404) @@ -59,9 +59,9 @@ def add_lokasi(request): Lokasi.objects.create(name=name, latitude=latitude, longitude=longitude, alamat=alamat, no_telp=no_telp, image=image) return JsonResponse({'response' : 'Location added', 'name':name}, status = 201) else: - return JsonResponse({'response' : 'try post request instead'}, status = 400) + return JsonResponse({'response' : request_error_message("post")}, status = 400) except KeyError as e: - return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500) + return JsonResponse({'response': missing_key_message(str(e))}, status = 500) @api_view(['GET']) @authentication_classes([TokenAuthentication,]) @@ -88,9 +88,9 @@ def list_fasilitas(request, nama_lokasi): fasilitas_details["is_verified"] = fasilitas.is_verified return JsonResponse(return_json, status = 201) except KeyError as e: - return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500) - except: - return JsonResponse({'response': 'lokasi might not be here'}) # Create your views here. + return JsonResponse({'response': missing_key_message(str(e))}, status = 500) + except Exception as e: + return JsonResponse({'response': str(e)}) @api_view(['POST']) @authentication_classes([TokenAuthentication,]) @@ -108,11 +108,11 @@ def add_fasilitas(request, nama_lokasi): image=image) return JsonResponse({'response' : 'fasilitas added', 'id':fasilitas.id}, status = 201) else: - return JsonResponse({'response' : 'try post request instead'}, status = 400) + return JsonResponse({'response' : request_error_message("post")}, status = 400) except KeyError as e: - return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500) - except: - return JsonResponse({'response':'lokasi might not be here'}, status = 404) + return JsonResponse({'response': missing_key_message(str(e))}, status = 500) + except Exception as e: + return JsonResponse({'response': str(e)}, status = 404) @api_view(['GET']) @authentication_classes([]) @@ -127,8 +127,8 @@ def detail_fasilitas(request, nama_lokasi, id): "like":fasilitas.like, "dislike":fasilitas.dislike, "rating":fasilitas.rating, "tag":fasilitas.tag, "image":str(fasilitas.image), "is_verified":fasilitas.is_verified} return JsonResponse(return_json, status = 201) else: - return JsonResponse({'response' : 'try get request instead'}, status = 400) + return JsonResponse({'response' : request_error_message("get")}, status = 400) except KeyError as e: - return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500) + return JsonResponse({'response': missing_key_message(str(e))}, status = 500) except Exception as e: return JsonResponse({'response': str(e)}, status = 404) \ No newline at end of file diff --git a/login/admin.py b/login/admin.py deleted file mode 100644 index 8c38f3f3dad51e4585f3984282c2a4bec5349c1e..0000000000000000000000000000000000000000 --- a/login/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/login/apps.py b/login/apps.py deleted file mode 100644 index be1c1733c8f0838587b91db9eaac121c8c23d4f4..0000000000000000000000000000000000000000 --- a/login/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class LoginConfig(AppConfig): - name = 'login' diff --git a/login/models.py b/login/models.py deleted file mode 100644 index 71a836239075aa6e6e4ecb700e9c42c95c022d91..0000000000000000000000000000000000000000 --- a/login/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/new_rest_api/urls.py b/new_rest_api/urls.py index f12ddc0fbb8687bf77f83a51385c8e884bf0dfb2..091ab95c4c2dc8fa9bdd697d7d319dfff7237313 100644 --- a/new_rest_api/urls.py +++ b/new_rest_api/urls.py @@ -6,11 +6,6 @@ import new_rest_api.views from django.views.generic import TemplateView -router = routers.DefaultRouter() -#router.register(r'users', rest_api.views.UserViewSet) -#router.register(r'groups', rest_api.views.GroupViewSet) - - urlpatterns = [ path('user-list/', new_rest_api.views.user_list,name='user-list'), path('user-detail/', new_rest_api.views.user_details,name='user-details'), diff --git a/new_rest_api/views.py b/new_rest_api/views.py index fb4009d1c6bd098a348ae092a808b4bf12cfa38a..ff35abc32570c43a894576e7d14a1b1ffd917a97 100644 --- a/new_rest_api/views.py +++ b/new_rest_api/views.py @@ -16,6 +16,13 @@ from rest_framework.decorators import api_view, permission_classes, authenticati from registrasi.models import BisaGoUser +def request_error_message(request_kind): + return "get {} request instead".format(request_kind) + +def missing_key_message(key): + return "bad request. {} key needed".format(key) + + @csrf_exempt @api_view(['GET']) @authentication_classes([]) @@ -29,10 +36,9 @@ def user_list(request): "name": user.user.last_name, "email": user.user.email, "phone_number": user.phone_number}) - #serializer = UserSerializer(user_list, many=True) return JsonResponse(json_return, safe=False) else: - return JsonResponse({'response' : 'try get request instead'}, status = 400) + return JsonResponse({'response' : request_error_message("get")}, status = 400) @api_view(['GET']) @authentication_classes([]) @@ -62,5 +68,5 @@ def register_user(request): BisaGoUser.objects.create(user= user, phone_number=phone_number) return JsonResponse({'response' : 'User created', 'email':email, 'name':name}, status = 201) except KeyError as e: - return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500) - # Create your views here. + return JsonResponse({'response':missing_key_message(str(e))}, status = 500) + \ No newline at end of file diff --git a/helloworld/__init__.py b/oauth/__init__.py similarity index 100% rename from helloworld/__init__.py rename to oauth/__init__.py diff --git a/helloworld/admin.py b/oauth/admin.py similarity index 100% rename from helloworld/admin.py rename to oauth/admin.py diff --git a/oauth/apps.py b/oauth/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..17fcea243e6d22e799d43d1d2b44a6cf3c1362d2 --- /dev/null +++ b/oauth/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class OauthConfig(AppConfig): + name = 'oauth' diff --git a/login/__init__.py b/oauth/migrations/__init__.py similarity index 100% rename from login/__init__.py rename to oauth/migrations/__init__.py diff --git a/helloworld/models.py b/oauth/models.py similarity index 100% rename from helloworld/models.py rename to oauth/models.py diff --git a/login/tests.py b/oauth/tests.py similarity index 100% rename from login/tests.py rename to oauth/tests.py diff --git a/login/views.py b/oauth/views.py similarity index 100% rename from login/views.py rename to oauth/views.py diff --git a/pplbackend/settings.py b/pplbackend/settings.py index 7ab3d4961da92fa87d39a988b3a61c3ba9682185..74f6a201be8e7edae84a9355462e891fb628d75e 100644 --- a/pplbackend/settings.py +++ b/pplbackend/settings.py @@ -41,7 +41,6 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.auth.hashers', - 'login', 'registrasi', 'informasi_fasilitas', 'new_rest_api', @@ -55,6 +54,7 @@ INSTALLED_APPS = [ 'allauth.socialaccount', 'allauth.socialaccount.providers.google', 'multiselectfield', + 'oauth2_provider', ] MIDDLEWARE = [ diff --git a/pplbackend/urls.py b/pplbackend/urls.py index 6c75b64f714ab76601050a9d4233f0a05a9f34cc..31744b9f1fe74fba836ff85be2064cb5c333161a 100644 --- a/pplbackend/urls.py +++ b/pplbackend/urls.py @@ -33,6 +33,7 @@ urlpatterns = [ path('accounts/', include('allauth.urls')), path('api-auth/', include('rest_framework.urls', namespace='rest_framework')), path('api/', include(new_rest_api.urls)), + path('o/', include('oauth2_provider.urls', namespace='oauth2_provider')), path('', include(router.urls)), path('api-token-auth/', views.obtain_auth_token, name='api-token-auth'), path('informasi-fasilitas/', include('informasi_fasilitas.urls')) diff --git a/registrasi/migrations/0001_initial.py b/registrasi/migrations/0001_initial.py index ca3fcbeb95a316260935f671b59d394412d8d9b9..02261bba3d375d7454144f2a0d73871df5b8a10d 100644 --- a/registrasi/migrations/0001_initial.py +++ b/registrasi/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.1.5 on 2020-04-17 10:27 +# Generated by Django 2.1.5 on 2020-04-18 09:06 from django.conf import settings from django.db import migrations, models diff --git a/requirements.txt b/requirements.txt index 09918a2cd6bb2736f5cb27c5b1ee0e760212a910..59edaae6bbf9e6bccb8f5a1a7990bdacb7959465 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,8 +10,10 @@ defusedxml==0.6.0 dj-database-url==0.4.2 Django==2.1.5 django-allauth==0.41.0 +django-cors-middleware==1.5.0 django-environ==0.4.4 django-multiselectfield==0.1.12 +django-oauth-toolkit==1.3.2 django-rest-auth==0.9.5 djangorestframework==3.11.0 google-api-python-client==1.7.11 @@ -24,8 +26,8 @@ isort==4.2.15 lazy-object-proxy==1.3.1 mccabe==0.6.1 oauthlib==3.1.0 +Pillow==7.0.0 pip==20.0.2 -pillow==7.0.0 psycopg2==2.8.4 pyasn1==0.4.8 pyasn1-modules==0.2.8