From 1277d0b08e4fb13b9f2d959c984f43f382a2c9a3 Mon Sep 17 00:00:00 2001 From: shashwat1002 Date: Wed, 22 Aug 2018 00:52:45 +0530 Subject: [PATCH 1/9] updated gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6dc400e53..460415733 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,6 @@ __pycache__ .env staticfiles/ mysite.log +settings.py venv .idea/* From 938f31bbb07b1e0540bc1d67e05b137b215012e1 Mon Sep 17 00:00:00 2001 From: shashwat1002 Date: Wed, 22 Aug 2018 00:54:01 +0530 Subject: [PATCH 2/9] updated gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 460415733..d4b979a46 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,6 @@ __pycache__ .env staticfiles/ mysite.log -settings.py +floodrelief/settings.py venv .idea/* From c0c77520a239375f23d64395c096e00cb6f52892 Mon Sep 17 00:00:00 2001 From: shashwat1002 Date: Wed, 22 Aug 2018 00:58:50 +0530 Subject: [PATCH 3/9] ss --- .gitignore | 2 +- floodrelief/settings.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d4b979a46..3fd6fde26 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,6 @@ __pycache__ .env staticfiles/ mysite.log -floodrelief/settings.py +floodrelief\settings.py venv .idea/* diff --git a/floodrelief/settings.py b/floodrelief/settings.py index 714a83568..8dfe72d24 100644 --- a/floodrelief/settings.py +++ b/floodrelief/settings.py @@ -16,6 +16,8 @@ import raven import datetime + + def get_list(text): return [item.strip() for item in text.split(',')] From 15c87e4062c6c8613b19151bc3b12a580bb29eaf Mon Sep 17 00:00:00 2001 From: shashwat1002 Date: Wed, 22 Aug 2018 01:02:21 +0530 Subject: [PATCH 4/9] stuff --- .gitignore | 2 +- floodrelief/settings.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3fd6fde26..460415733 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,6 @@ __pycache__ .env staticfiles/ mysite.log -floodrelief\settings.py +settings.py venv .idea/* diff --git a/floodrelief/settings.py b/floodrelief/settings.py index 8dfe72d24..610bb982d 100644 --- a/floodrelief/settings.py +++ b/floodrelief/settings.py @@ -18,6 +18,8 @@ + + def get_list(text): return [item.strip() for item in text.split(',')] From 09c798d74e26dc1362df384494f85cc6690d4562 Mon Sep 17 00:00:00 2001 From: shashwat1002 Date: Wed, 22 Aug 2018 01:05:24 +0530 Subject: [PATCH 5/9] setting file changed for local developement --- floodrelief/settings.py | 101 ++++------------------------------------ 1 file changed, 10 insertions(+), 91 deletions(-) diff --git a/floodrelief/settings.py b/floodrelief/settings.py index 610bb982d..14a77ac8c 100644 --- a/floodrelief/settings.py +++ b/floodrelief/settings.py @@ -1,42 +1,19 @@ """ Django settings for floodrelief project. - Generated by 'django-admin startproject' using Django 2.1. - For more information on this file, see https://docs.djangoproject.com/en/2.1/topics/settings/ - For the full list of settings and their values, see https://docs.djangoproject.com/en/2.1/ref/settings/ """ import os -import environ -import dj_database_url -import raven -import datetime - - - - - -def get_list(text): - return [item.strip() for item in text.split(',')] - -env = environ.Env( - # set casting, default value - DEBUG=(bool, False), - CACHE_TIMEOUT=(int, 60) -) -# reading .env file -root = environ.Path(__file__) - 2 -environ.Env.read_env(root('.env')) # False if not in os.environ -DEBUG = env('DEBUG') +DEBUG = True # Raises django's ImproperlyConfigured exception if SECRET_KEY not in os.environ -SECRET_KEY = env('SECRET_KEY') +SECRET_KEY = "dfsdf" # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -46,17 +23,7 @@ def get_list(text): # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # ALLOWED_HOSTS = ['127.0.0.1', 'keralarescue.herokuapp.com', 'keralarescue.in', 'www.keralarescue.in', 'localhost'] -ALLOWED_HOSTS = get_list(os.environ.get('ALLOWED_HOSTS')) - - -RAVEN_CONFIG = { - 'dsn': env('SENTRY_DSN'), - # If you are using git, you can also automatically configure the - # release based on the git info. - # 'release': raven.fetch_git_sha(os.path.abspath(os.pardir)), -} - - +ALLOWED_HOSTS = ["*"] # Application definition @@ -70,11 +37,6 @@ def get_list(text): 'django.contrib.staticfiles', 'bootstrap3', 'django_filters', - 'storages', - 'raven.contrib.django.raven_compat', - 'rest_framework', - 'rest_framework.authtoken', - 'rest_auth', ] MIDDLEWARE = [ @@ -111,24 +73,13 @@ def get_list(text): # Database # https://docs.djangoproject.com/en/2.1/ref/settings/#databases -# DATABASES = { -# # read os.environ['DATABASE_URL'] and raises ImproperlyConfigured exception if not found -# 'default': env.db() -# } -DATABASES = {} -DATABASES['default'] = dj_database_url.parse(env('B_DATABASE_URL'), conn_max_age=600) - -CACHES = { - "default": { - "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": env('REDIS_URL'), - "OPTIONS": { - "CLIENT_CLASS": "django_redis.client.DefaultClient" - }, - "KEY_PREFIX": "keralarescue" +DATABASES = { + 'default':{ + 'ENGINE':'django.db.backends.sqlite3', + 'NAME':os.path.join(BASE_DIR,'db.sqlite3') } } -CACHE_TIMEOUT = env('CACHE_TIMEOUT') + # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators @@ -205,37 +156,5 @@ def get_list(text): STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), ) -bucket_name = os.environ.get('AWS_STORAGE_BUCKET_NAME') -S3_URL = "https://{}.s3.ap-south-1.amazonaws.com".format(bucket_name,) - - -if os.environ.get('USE_S3'): - AWS_STORAGE_BUCKET_NAME=bucket_name - AWS_ACCESS_KEY_ID=os.environ.get("AWS_ACCESS_KEY_ID") - AWS_SECRET_ACCESS_KEY=os.environ.get("AWS_SECRET_ACCESS_KEY") - AWS_QUERYSTRING_AUTH=False - MEDIA_URL = S3_URL + "/media/" - DEFAULT_FILE_STORAGE="storages.backends.s3boto3.S3Boto3Storage" -else: - MEDIA_URL = '/media/' -ADMIN_SITE_HEADER = "Keralarescue Dashboard" -MEDIA_ROOT = 'media' - -#JWT REST Auth for API -REST_USE_JWT = True -JWT_AUTH = { - 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=20) -} -REST_SESSION_LOGIN = False -ACCOUNT_EMAIL_REQUIRED = False -ACCOUNT_AUTHENTICATION_METHOD = 'username' -ACCOUNT_EMAIL_VERIFICATION = 'optional' -REST_FRAMEWORK = { - 'DEFAULT_PERMISSION_CLASSES': ( - 'rest_framework.permissions.IsAuthenticated', - ), - 'DEFAULT_AUTHENTICATION_CLASSES': ( - 'rest_framework.authentication.BasicAuthentication', - 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', - ), -} \ No newline at end of file + +ADMIN_SITE_HEADER = "test" \ No newline at end of file From 3fcc702159be4a839d47be1a37745d02d461ec0e Mon Sep 17 00:00:00 2001 From: shashwat1002 Date: Thu, 23 Aug 2018 16:44:40 +0530 Subject: [PATCH 6/9] add the update request form to the request detail page --- .gitignore | 1 + floodrelief/settings.py | 54 +++++++++++++++-- floodrelief/urls.py | 3 +- .../templates/mainapp/request_details.html | 60 +++++++++++++++---- mainapp/urls.py | 2 +- mainapp/views.py | 38 ++++++++++++ 6 files changed, 140 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 460415733..19cb4cd74 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ __pycache__ staticfiles/ mysite.log settings.py +urls.py venv .idea/* diff --git a/floodrelief/settings.py b/floodrelief/settings.py index 14a77ac8c..7ea560d09 100644 --- a/floodrelief/settings.py +++ b/floodrelief/settings.py @@ -7,13 +7,30 @@ https://docs.djangoproject.com/en/2.1/ref/settings/ """ + import os +import environ +import dj_database_url +import raven +import datetime + +def get_list(text): + return [item.strip() for item in text.split(',')] + +env = environ.Env( + # set casting, default value + DEBUG=(bool, False), + CACHE_TIMEOUT=(int, 60) +) +# reading .env file +root = environ.Path(__file__) - 2 +environ.Env.read_env(root('.env')) # False if not in os.environ -DEBUG = True +DEBUG = env('DEBUG') # Raises django's ImproperlyConfigured exception if SECRET_KEY not in os.environ -SECRET_KEY = "dfsdf" +SECRET_KEY = env('SECRET_KEY') # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -23,7 +40,21 @@ # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # ALLOWED_HOSTS = ['127.0.0.1', 'keralarescue.herokuapp.com', 'keralarescue.in', 'www.keralarescue.in', 'localhost'] -ALLOWED_HOSTS = ["*"] +ALLOWED_HOSTS = get_list(os.environ.get('ALLOWED_HOSTS')) + + +RAVEN_CONFIG = { + 'dsn': env('SENTRY_DSN'), + # If you are using git, you can also automatically configure the + # release based on the git info. + # 'release': raven.fetch_git_sha(os.path.abspath(os.pardir)), +} + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ + +# ALLOWED_HOSTS = ['127.0.0.1', 'keralarescue.herokuapp.com', 'keralarescue.in', 'www.keralarescue.in', 'localhost'] + # Application definition @@ -37,6 +68,11 @@ 'django.contrib.staticfiles', 'bootstrap3', 'django_filters', + 'storages', + 'raven.contrib.django.raven_compat', + 'rest_framework', + 'rest_framework.authtoken', + 'rest_auth', ] MIDDLEWARE = [ @@ -131,7 +167,17 @@ }, } } - +CACHES = { + "default": { + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": env('REDIS_URL'), + "OPTIONS": { + "CLIENT_CLASS": "django_redis.client.DefaultClient" + }, + "KEY_PREFIX": "keralarescue" + } +} +CACHE_TIMEOUT = env('CACHE_TIMEOUT') # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ diff --git a/floodrelief/urls.py b/floodrelief/urls.py index ec0404f8d..f29f24be0 100644 --- a/floodrelief/urls.py +++ b/floodrelief/urls.py @@ -27,4 +27,5 @@ path('login/', auth_views.LoginView.as_view()), path('api/1/rest-auth/', include('rest_auth.urls')), path('api/1/', include('mainapp.api_urls')), -] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) +#CHANGED MEDIA_ROOT to STATIC_ROOT and STATIC_URL to MEDIA_URL \ No newline at end of file diff --git a/mainapp/templates/mainapp/request_details.html b/mainapp/templates/mainapp/request_details.html index 557e1a566..88fc8269e 100644 --- a/mainapp/templates/mainapp/request_details.html +++ b/mainapp/templates/mainapp/request_details.html @@ -7,44 +7,45 @@ {{ filter.form.as_p }} +
- + - + - + - - + + - + - + - +
Request details for #{{ req.id }}Request Updates
District : {{ req.get_district_display }} District : {{ view.original_request.get_district_display }}
Location : {{ req.location }} Location : {{ view.original_request.location }}
GPS Location : - {% if req.latlng %} - Open in maps + {% if view.original_request.latlng %} + Open in maps
- Accuracy: {{ req.latlng_accuracy }} + Accuracy: {{ view.original_request.latlng_accuracy }} {% else %} NA {% endif %}
Requestee : {{ req.requestee }}
Requestee : {{ view.original_request.requestee }}
Contact number : {{ req.requestee_phone }} Contact number : {{ view.original_request.requestee_phone }}
Summary of request : {{ req.summarise | linebreaks }} Summary of request : {{ view.original_request.summarise | linebreaks }}
Date : {{ req.dateadded }} Date : {{ view.original_request.dateadded }}
@@ -68,7 +69,7 @@

Updates

- {% for update in updates %} + {% for update in view.updates %} {{ update.status }} {{ update.other_status }} {{ update.updater_name }} @@ -84,4 +85,39 @@

Updates

+ +

Request Updates

+

placeholder for malayalam ‍

+
+ {% csrf_token %} + {% bootstrap_form form %} + + {% buttons %} + + {% endbuttons %} +
+ + + {% endblock %} diff --git a/mainapp/urls.py b/mainapp/urls.py index 1fc3f7bb3..9f073650b 100644 --- a/mainapp/urls.py +++ b/mainapp/urls.py @@ -17,7 +17,7 @@ path('ngoview/', views.ngo_list, name='ngoview'), path('NGO/download/', views.download_ngo_list, name='ngo_download_view'), path('requests/', views.request_list, name='requestlistview'), - url(r'request_details/(?P\d+)/$', views.request_details, name='requestdetailsview'), + url(r'request_details/(?P\d+)/$', views.RequestDetails.as_view(), name='requestdetailsview'), path('contactus/', views.districtmanager_list, name='contactus'), path('reg_success/', views.RegSuccess.as_view(), name='reg_successview'), path('req_sucess/', views.ReqSuccess.as_view(), name='req_sucessview'), diff --git a/mainapp/views.py b/mainapp/views.py index 89f6ce941..d6bd58b90 100644 --- a/mainapp/views.py +++ b/mainapp/views.py @@ -357,7 +357,45 @@ def request_details(request, request_id=None): except: return HttpResponseRedirect("/error?error_text={}".format('Sorry, we couldnt fetch details for that request')) return render(request, 'mainapp/request_details.html', {'filter' : filter, 'req': req_data, 'updates': updates }) +class RequestDetails(CreateView): + model = RequestUpdate + template_name='mainapp/request_details.html' + fields = [ + 'status', + 'other_status', + 'updater_name', + 'updater_phone', + 'notes' + ] + success_url = '/req_update_success/' + + def original_request(self): + return self.original_request + + def updates(self): + return self.updates + def get_context_data(self, **kwargs): + context= super().get_context_data() + filter=RequestFilter(None) + context['filter']= filter + return context + #@method_decorator(login_required) + def dispatch(self, request, *args, **kwargs): + #could not use login_required decorator because it redirects to /accounts/login and we need /login + #disable authentication + # if not request.user.is_authenticated: + # return redirect('/login'+'?next=request_updates/'+kwargs['request_id']+'/') + + self.original_request = get_object_or_404(Request, pk=kwargs['request_id']) + self.updates = RequestUpdate.objects.all().filter(request_id=kwargs['request_id']).order_by('-update_ts') + return super().dispatch(request, *args, **kwargs) + + def form_valid(self, form): + self.object = form.save(commit=False) + self.object.request = self.original_request + self.object = form.save() + return HttpResponseRedirect(self.get_success_url()) class DistrictManagerFilter(django_filters.FilterSet): class Meta: model = DistrictManager From 6a76c45efee40527c250a6882a34088612eaae4e Mon Sep 17 00:00:00 2001 From: shashwat1002 Date: Thu, 23 Aug 2018 16:56:03 +0530 Subject: [PATCH 7/9] removed extra column from the main request table --- mainapp/templates/mainapp/request_list.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mainapp/templates/mainapp/request_list.html b/mainapp/templates/mainapp/request_list.html index 7a181ff44..dad04d756 100644 --- a/mainapp/templates/mainapp/request_list.html +++ b/mainapp/templates/mainapp/request_list.html @@ -83,8 +83,9 @@

ഇതു വരെ ആവശ്യപ്പെട്ട Requestee - അപേക്ഷകന്‍റെ പേര Phone - ഫോണ്‍ നമ്പര്‍ Date - തീയതി - More details - കൂടുതൽ വിശദാംശങ്ങൾ - Update + More details/ update a request - + കൂടുതൽ വിവരങ്ങൾ / ഒരു അപേക്ഷ സമർപ്പിക്കുക + @@ -96,8 +97,8 @@

ഇതു വരെ ആവശ്യപ്പെട്ട {{ req.requestee }} {{ req.requestee_phone }} {{ req.dateadded }} - More details - Update + More details/ Update Request + {% endfor %} From 3467de68375be894b17f18605cced6305e5e6eba Mon Sep 17 00:00:00 2001 From: shashwat1002 Date: Thu, 23 Aug 2018 17:01:28 +0530 Subject: [PATCH 8/9] switching back to production env --- floodrelief/settings.py | 76 ++++++++++++++++++++++++++++------------- floodrelief/urls.py | 2 +- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/floodrelief/settings.py b/floodrelief/settings.py index 7ea560d09..220f79fee 100644 --- a/floodrelief/settings.py +++ b/floodrelief/settings.py @@ -7,13 +7,14 @@ https://docs.djangoproject.com/en/2.1/ref/settings/ """ - import os import environ import dj_database_url import raven import datetime + + def get_list(text): return [item.strip() for item in text.split(',')] @@ -50,10 +51,6 @@ def get_list(text): # 'release': raven.fetch_git_sha(os.path.abspath(os.pardir)), } -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ - -# ALLOWED_HOSTS = ['127.0.0.1', 'keralarescue.herokuapp.com', 'keralarescue.in', 'www.keralarescue.in', 'localhost'] # Application definition @@ -109,13 +106,24 @@ def get_list(text): # Database # https://docs.djangoproject.com/en/2.1/ref/settings/#databases -DATABASES = { - 'default':{ - 'ENGINE':'django.db.backends.sqlite3', - 'NAME':os.path.join(BASE_DIR,'db.sqlite3') +# DATABASES = { +# # read os.environ['DATABASE_URL'] and raises ImproperlyConfigured exception if not found +# 'default': env.db() +# } +DATABASES = {} +DATABASES['default'] = dj_database_url.parse(env('B_DATABASE_URL'), conn_max_age=600) + +CACHES = { + "default": { + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": env('REDIS_URL'), + "OPTIONS": { + "CLIENT_CLASS": "django_redis.client.DefaultClient" + }, + "KEY_PREFIX": "keralarescue" } } - +CACHE_TIMEOUT = env('CACHE_TIMEOUT') # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators @@ -167,17 +175,7 @@ def get_list(text): }, } } -CACHES = { - "default": { - "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": env('REDIS_URL'), - "OPTIONS": { - "CLIENT_CLASS": "django_redis.client.DefaultClient" - }, - "KEY_PREFIX": "keralarescue" - } -} -CACHE_TIMEOUT = env('CACHE_TIMEOUT') + # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ @@ -202,5 +200,37 @@ def get_list(text): STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), ) - -ADMIN_SITE_HEADER = "test" \ No newline at end of file +bucket_name = os.environ.get('AWS_STORAGE_BUCKET_NAME') +S3_URL = "https://{}.s3.ap-south-1.amazonaws.com".format(bucket_name,) + + +if os.environ.get('USE_S3'): + AWS_STORAGE_BUCKET_NAME=bucket_name + AWS_ACCESS_KEY_ID=os.environ.get("AWS_ACCESS_KEY_ID") + AWS_SECRET_ACCESS_KEY=os.environ.get("AWS_SECRET_ACCESS_KEY") + AWS_QUERYSTRING_AUTH=False + MEDIA_URL = S3_URL + "/media/" + DEFAULT_FILE_STORAGE="storages.backends.s3boto3.S3Boto3Storage" +else: + MEDIA_URL = '/media/' +ADMIN_SITE_HEADER = "Keralarescue Dashboard" +MEDIA_ROOT = 'media' + +#JWT REST Auth for API +REST_USE_JWT = True +JWT_AUTH = { + 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=20) +} +REST_SESSION_LOGIN = False +ACCOUNT_EMAIL_REQUIRED = False +ACCOUNT_AUTHENTICATION_METHOD = 'username' +ACCOUNT_EMAIL_VERIFICATION = 'optional' +REST_FRAMEWORK = { + 'DEFAULT_PERMISSION_CLASSES': ( + 'rest_framework.permissions.IsAuthenticated', + ), + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.BasicAuthentication', + 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', + ), +} \ No newline at end of file diff --git a/floodrelief/urls.py b/floodrelief/urls.py index f29f24be0..50152fbce 100644 --- a/floodrelief/urls.py +++ b/floodrelief/urls.py @@ -27,5 +27,5 @@ path('login/', auth_views.LoginView.as_view()), path('api/1/rest-auth/', include('rest_auth.urls')), path('api/1/', include('mainapp.api_urls')), -] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) #CHANGED MEDIA_ROOT to STATIC_ROOT and STATIC_URL to MEDIA_URL \ No newline at end of file From be7b7a959a2f4fa949768115b9c76eb3cccc32cb Mon Sep 17 00:00:00 2001 From: shashwat1002 Date: Thu, 23 Aug 2018 18:13:01 +0530 Subject: [PATCH 9/9] change gitignore --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fbbf38b18..b4871c27c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,8 @@ __pycache__ .env staticfiles/ mysite.log -settings.py -urls.py + + venv .idea/* media/