Skip to content
This repository was archived by the owner on Feb 2, 2022. It is now read-only.

User interface #4

Merged
merged 2 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@
# Python pycache:
__pycache__/
# Ignored by the build system
/setup.cfg
# Secrets
/secrets
/setup.cfg
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ media
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
secrets/

# Gradle
.idea/**/gradle.xml
Expand Down Expand Up @@ -135,4 +134,9 @@ GitHub.sublime-settings
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history
.history

# Python package installation files #
*.whl

firebase_admin_sdk.json
3 changes: 3 additions & 0 deletions .idea/AdvancedDevelopment.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 23 additions & 18 deletions AdvancedDevelopment/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from firebase_admin import credentials
import djongo
import requests
from google.api_core.exceptions import PermissionDenied
from google.auth.exceptions import DefaultCredentialsError
from google.cloud import secretmanager

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Expand Down Expand Up @@ -77,16 +79,20 @@

WSGI_APPLICATION = 'AdvancedDevelopment.wsgi.application'

# Use Bootstrap 4 Forms With Django
# https://simpleisbetterthancomplex.com/tutorial/2018/08/13/how-to-use-bootstrap-4-forms-with-django.html

CRISPY_TEMPLATE_PACK = 'bootstrap4'

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'AdvancedDevelopment',
}
}
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite3',
}
}


# Password validation
Expand All @@ -112,13 +118,9 @@
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


Expand All @@ -127,11 +129,13 @@

STATIC_URL = '/static/'


# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


# Certifying Firebase credentials for Firebase integration
# https://jrizmal.medium.com/how-to-authenticate-firebase-users-in-django-rest-framework-c2d90f5a0a11

Expand All @@ -141,16 +145,17 @@
]
}


# Specify your Google API key as environment variable GOOGLE_API_KEY
# You may also specify it here, though be sure not to commit it to a repository
# todo hide this in secrets
# GOOGLE_API_KEY = 'AIzaSyBvikAKlkILoJTxKC5w0bgUAOOG_U8o4-U' # Specify your Google API key here
# GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY', GOOGLE_API_KEY)
GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY')
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "F:/Projects/AdvancedDevelopment/firebase_admin_sdk.json"

secrets = secretmanager.SecretManagerServiceClient()
# fixme fetches secret successfully as string, needs to be file path
# response = secrets.access_secret_version(name="projects/idyllic-kit-328813/secrets/Firebase_Admin_SDK/versions/2")
# cred = credentials.Certificate(response)
cred = credentials.Certificate(os.path.join(BASE_DIR, "firebase_admin_sdk.json"))

try:
# todo save response to file
response = secrets.access_secret_version(name="projects/idyllic-kit-328813/secrets/Firebase_Admin_SDK/versions/latest")
cred = credentials.Certificate(response)
except PermissionDenied as exception: # todo write to log
cred = credentials.Certificate(os.path.join(BASE_DIR, "firebase_admin_sdk.json"))

firebase_admin.initialize_app(cred)
4 changes: 2 additions & 2 deletions AdvancedDevelopment/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from users.views import ProfileView

urlpatterns = [
# path("", parcel_views.home, name="home"),
path("", user_views.register, name="home"),
path("", parcel_views.home, name="home"),
# path("", user_views.register, name="home"),
path("admin/", admin.site.urls),
path("product/<int:pk>/", ProductDetailView.as_view(), name="product"),
path("order/<int:pk>/", OrderDetailView.as_view(), name="order"),
Expand Down
8 changes: 1 addition & 7 deletions AdvancedDevelopment/utils/access_secret_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,5 @@ def access_secret_version(project_id, secret_id, version_id):

# Access the secret version.
response = client.access_secret_version(request={"name": name})

# Print the secret payload.
#
# WARNING: Do not print the secret in a production environment - this
# snippet is showing how to access the secret material.
payload = response.payload.data.decode("UTF-8")
print("Plaintext: {}".format(payload))
return response

3 changes: 0 additions & 3 deletions blog/admin.py

This file was deleted.

6 changes: 0 additions & 6 deletions blog/apps.py

This file was deleted.

3 changes: 0 additions & 3 deletions blog/models.py

This file was deleted.

3 changes: 0 additions & 3 deletions blog/tests.py

This file was deleted.

3 changes: 0 additions & 3 deletions blog/views.py

This file was deleted.

Binary file added default.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion products/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from django.contrib import admin

# Register your models here.
from products.models import Product, Order

admin.site.register(Product)
admin.site.register(Order)
20 changes: 12 additions & 8 deletions products/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
# Generated by Django 3.2.9 on 2021-12-15 04:25
# Generated by Django 3.2.9 on 2021-12-20 23:54

import address.models
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('address', '0004_auto_20211215_0401'),
]

operations = [
migrations.CreateModel(
name='Order',
name='Product',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quantity', models.IntegerField()),
('status', models.CharField(choices=[('1', 'Order confirmed'), ('2', 'Awaiting dispatch'), ('3', 'Dispatched, awaiting courier'), ('4', 'With courier, awaiting delivery'), ('5', 'Out for delivery'), ('6', 'Order delivered and fulfilled')], default='1', max_length=1)),
('name', models.CharField(max_length=128)),
('desc', models.TextField(max_length=512)),
('price', models.FloatField()),
],
),
migrations.CreateModel(
name='Product',
name='Order',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128)),
('desc', models.TextField(max_length=512)),
('price', models.FloatField()),
('quantity', models.IntegerField()),
('status', models.CharField(choices=[('1', 'Order confirmed'), ('2', 'Awaiting dispatch'), ('3', 'Dispatched, awaiting courier'), ('4', 'With courier, awaiting delivery'), ('5', 'Out for delivery'), ('6', 'Order delivered and fulfilled')], default='1', max_length=1)),
('address', address.models.AddressField(on_delete=django.db.models.deletion.CASCADE, to='address.address')),
],
),
]
20 changes: 20 additions & 0 deletions products/migrations/0002_order_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.9 on 2021-12-21 02:06

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('products', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='order',
name='product',
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, to='products.product'),
preserve_default=False,
),
]
4 changes: 2 additions & 2 deletions products/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Order(models.Model):
("6", "Order delivered and fulfilled")
]

product = Product
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.IntegerField()
# address = AddressField() # todo needs default value as migrations have been made
address = AddressField()
status = models.CharField(default="1", max_length=1, choices=STATUS_CHOICES)
customer = get_user_model()

Expand Down
File renamed without changes.
82 changes: 39 additions & 43 deletions products/templates/products/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,57 @@
{% endif %}

{# scripts and styles #}
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"
integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
crossorigin="anonymous"></script>

{# <link rel="stylesheet" href="{% static "/css/reset.css" %}" />#}
<link rel="stylesheet" href="{% static "css/styling.css" %}"/>

</head>
<body>

<header>
<header class="container mb-3">

<div class="site-logo">
<img src="/media/site%20logo.png" alt="" />
</div>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="/">Product Co.</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="search">
<!-- search form -->
</div>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>

<div class="utility-menu">
<a href="javascript:void(0)" class="utility-menu__login">Login</a>
<a href="javascript:void(0)" class="utility-menu__register">Register</a>
</div>

</header>

<section class="site-banner">
<div class="site-banner__text">
<h1>Advanced Development assignment</h1>
<p>Lorem ipsum</p>
<div class="site-banner__buttons">
<a href="javascript:void(0)" class="btn btn-outline-light">Register</a>
</div>
</div>
</section>

<aside>
<h3>Site news</h3>
<ul class="site-news">
<li class="site-news__item">
<a href="javascript:void(0)">Notice of upcoming down-time</a> · 5th Jun 2020
</li>
<li class="site-news__item">
<a href="javascript:void(0)">New creators for April</a> · 1st May 2020
</li>
</ul>
<footer class="site-footer">
<p>
Copyright message
</p>
</footer>
</aside>
{% block banner %}{% endblock %}

<main>
<main class="container">
{% if messages %}
<ul class="messages">
{% for message in messages %}
Expand Down
11 changes: 11 additions & 0 deletions products/templates/products/home.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{% extends "products/base.html" %}
{% block banner %}
<div class="jumbotron container">
<h1 class="display-3">Welcome to Product Co.</h1>
<p class="lead">This is a simple hero unit, a simple jumbotron-style component for
calling extra attention to featured content or information.</p>
<p class="lead">
<a class="btn btn-primary btn-lg" href="{% url 'register' %}" role="button">Register</a>
</p>
</div>
{% endblock %}

{% block content %}
<h1>Hello world!</h1>
{% endblock %}
2 changes: 1 addition & 1 deletion products/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OrderDetailView(DetailView):
model = Order


class OrderCreateView(LoginRequiredMixin, CreateView):
class OrderCreateView(CreateView):
model = Order
fields = ["product", "quantity", "address"]

Expand Down
Loading