Skip to content

Commit

Permalink
Save changes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterprescott committed Oct 14, 2023
1 parent 0a912d7 commit 207b4f0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
21 changes: 17 additions & 4 deletions backend/fullstack_api/resources.py
Expand Up @@ -12,12 +12,15 @@

import os

import pandas as pd
from flask import request
from flask_praetorian import Praetorian, auth_required, roles_required
from flask_restful import Api, Resource
from git import Repo
from sqlalchemy import inspect
from sqlalchemy.exc import OperationalError

from fullstack_api.config import data_dir
from fullstack_api.models import User, db

guard = Praetorian()
Expand All @@ -28,11 +31,21 @@ def get(self, postcode_str):
postcode = "".join(
[char.upper() for char in postcode_str if str.isalnum(char)]
)
data = db.session.execute(
db.text(
f"SELECT * FROM postcode WHERE REPLACE(postcode, ' ','') = '{postcode}'"
try:
data = db.session.execute(
db.text(
f"SELECT * FROM postcode WHERE REPLACE(postcode, ' ','') = '{postcode}'"
)
).fetchone()
except OperationalError:
postcode_csv = pd.read_csv(
data_dir / "latlon.csv.gz",
index_col=None,
)
postcode_csv.to_sql(
"postcode",
db.engine,
)
).fetchone()
if data:
return {
"success": True,
Expand Down
4 changes: 2 additions & 2 deletions frontend/fullstack_ui/css/style.css
Expand Up @@ -38,9 +38,9 @@ button:hover {
#map {
position: absolute;
top: 100px;
z-index: 1;
z-index: -1;
width: 100%;
height: 300px;
height: 400px;
}

/*
Expand Down
7 changes: 3 additions & 4 deletions frontend/fullstack_ui/index.html
Expand Up @@ -50,10 +50,9 @@ <h1>Fullstack App</h1>
<div id="app-body">
<div id="map"></div>
</div>
<div id="app-footer">
...
</div>

<div id="app-footer">
<p>...</p>
</div>
</div>
<!-- End of main app -->

Expand Down
11 changes: 11 additions & 0 deletions frontend/fullstack_ui/js/maps.js
Expand Up @@ -21,3 +21,14 @@ const mapDiv = document.getElementById('map');
const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
}).addTo(map);

// Define a boundary for the map to restrict panning
var ukBounds = L.latLngBounds(
L.latLng(58.635, -13.687), // Northeast corner of the UK
L.latLng(49.866, 2.684) // Southwest corner of the UK
);

map.setMaxBounds(ukBounds); // Restrict panning to the UK boundaries
map.on('drag', function() {
map.panInsideBounds(ukBounds, { animate: false });
});
2 changes: 1 addition & 1 deletion frontend/fullstack_ui/js/popup-alert.js
Expand Up @@ -12,7 +12,7 @@ function alert(message) {
popUp(message);
msgFooter(message);
if (context === "local") {
rickRoll();
// rickRoll();
}
}

Expand Down

0 comments on commit 207b4f0

Please sign in to comment.