smartmetro Tech Stack (yay!)

  • Backend
  • Frontend
  • Database

Relevant files and snippets

settings.py


							DEBUG = True

							ALLOWED_HOSTS = [
								'127.0.0.1', 
								'localhost', 
								'10.144.36.2',
								'api.lungsod.tcagp.upd.edu.ph',
								'lungsod.tcagp.upd.edu.ph'
								]
							# ALLOWED_HOSTS = ['*']

							CSRF_TRUSTED_ORIGINS = ['https://api.lungsod.tcagp.upd.edu.ph', 'https://lungsod.tcagp.upd.edu.ph/api']

							# Application definition

							INSTALLED_APPS = [
								'django.contrib.admin',
								'django.contrib.auth',
								'django.contrib.contenttypes',
								'django.contrib.sessions',
								'django.contrib.messages',
								'django.contrib.staticfiles',
								'django.contrib.gis', #for geodjango / postgis
								'rest_framework',
								'corsheaders',
								'leaflet', # just a better map view
								'api',
								'simple_history', # for tracking changes in model; source: https://django-simple-history.readthedocs.io/en/latest/quick_start.html#what-is-django-simple-history-doing-behind-the-scenes
							]

							DATABASES = {
								'default': {
									'ENGINE': 'django.contrib.gis.db.backends.postgis',
									'NAME': 'lungsod_db_local',
									'USER': os.getenv('DB_USER'),
									'PASSWORD': os.getenv('DB_PASSWORD'),
									'HOST': os.getenv('DB_HOST'),
									'PORT': os.getenv('DB_PORT'),
									# 'OPTIONS': {
									#         'timeout': 20, # 20-second timeout; source: https://docs.djangoproject.com/en/4.0/ref/databases/
									#     }
								},
							

urls.py


							from django.urls import path, include
							from .views import accounts, account_link, vaccinations, emails, location, tourism, reports, logs, contact, image, points, districts, livefeed, cctv, command_user, emergency, cache
							from django.conf import settings
							from django.conf.urls.static import static

							from django.views.decorators.cache import cache_page

							urlpatterns = [

								# ACCOUNT ROUTES
								path('accounts/', accounts.home),
								path('accounts/create', accounts.createUser),
								path('accounts/login', accounts.loginUser),
								path('accounts/residents', accounts.residents),
								# path('accounts/residents/', accounts.residentLastName),
								path('accounts/visitors', accounts.visitors),
								path('accounts/verify', accounts.verifyUser),
								path('accounts/resendVerifyCode', accounts.resendVerifyCode),
								path('accounts/sendrecoveryemail', accounts.sendPasswordResetCode),
								path('accounts/resetcode', accounts.validateResetCode),
								path('accounts/changepassword', accounts.changePassword),
								path('accounts/changepasswordold', accounts.changePasswordWithOld),
								path('accounts/get/expopushtokens', accounts.getUserExpoPushToken),
								path('accounts/get/referred_by', accounts.getUsersByReferral),
								path('accounts/edit', accounts.editUser),
								path('accounts/delete', accounts.deleteUser),
							

models


								class Location(models.Model):
								""" GPS POINT of user """
								name = models.CharField(max_length=20)
								location = models.PointField(srid=4326)
								# DateTimeField formats https://www.geeksforgeeks.org/datetimefield-django-forms/
								# date = models.DateTimeField(auto_now_add=True, null = True) # 2021-07-05T11:16:36
								date = models.DateTimeField(default=utc_plus_8, null = True, ) # 2021-07-05T11:16:36
								district = models.CharField(default = "None", max_length=50)
								point_id = models.UUIDField(primary_key = True, default = uuid.uuid4, editable = False)
								objects = models.Manager()
							

views


								@api_view(['GET'])
								def getLocation(request):
									print('TEST')
									date_start = request.data['date_start']
									date_end = request.data['date_end']
									lat_start = request.data['lat_start']
									lat_end = request.data['lat_end']
									lon_start = request.data['lon_start']
									lon_end = request.data['lon_end']


									response = {
										"message": "No locations found",
										"description": "Query resulted no locations"
										}

									filtered_locations = filterLocation(date_start, date_end, lat_start, lat_end, lon_start, lon_end)

									if (filtered_locations == None): return Response(response, 200)

									serializer = LocationSerializer(filtered_locations, many=True)
									return Response(serializer.data, 200)
							

Relevant commands


							python manage.py runserver # - start development server
							python manage.py makemigrations # - make migrations (track changes between latest model definitions and database)
							python manage.py migrate # - process migrations to db