Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProjectClient_Y1S1_TramshedTech_15.git
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Beaumont Mogridge
ProjectClient_Y1S1_TramshedTech_15.git
Commits
391a89a7
Commit
391a89a7
authored
3 years ago
by
Rhiannon Austin
Browse files
Options
Downloads
Patches
Plain Diff
Login system first draft
parent
28f1fada
Branches
Branches containing commit
No related tags found
3 merge requests
!18
Login
,
!7
Login
,
!2
Web pages
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
database.db
+0
-0
0 additions, 0 deletions
database.db
database.py
+100
-0
100 additions, 0 deletions
database.py
login.html
+36
-0
36 additions, 0 deletions
login.html
main.py
+22
-0
22 additions, 0 deletions
main.py
with
158 additions
and
0 deletions
database.db
0 → 100644
+
0
−
0
View file @
391a89a7
File added
This diff is collapsed.
Click to expand it.
database.py
0 → 100644
+
100
−
0
View file @
391a89a7
import
os
import
sqlite3
from
typing
import
List
DATABASE
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
"
database.db
"
)
class
Connection
:
def
__init__
(
self
):
self
.
connection
=
sqlite3
.
connect
(
DATABASE
)
self
.
cursor
=
self
.
connection
.
cursor
()
self
.
do_rollback
=
False
def
commit
(
self
):
self
.
connection
.
commit
()
self
.
do_rollback
=
False
def
execute
(
self
,
sql
:
str
,
tuple
=
()):
self
.
do_rollback
=
True
self
.
cursor
.
execute
(
sql
,
tuple
)
def
fetch_all
(
self
):
return
self
.
cursor
.
fetchall
()
def
close
(
self
):
if
self
.
do_rollback
:
self
.
connection
.
rollback
()
self
.
connection
.
close
()
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
*
args
):
self
.
close
()
with
Connection
()
as
conn
:
conn
.
execute
(
'''
CREATE TABLE IF NOT EXISTS Workspaces (
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
name text NOT NULL,
address text NOT NULL,
main_photo text NOT NULL,
description text NOT NULL,
website text NOT NULL,
email text NOT NULL,
phone_number text NOT NULL,
opening_hours text,
checkin_instructions text)
'''
)
conn
.
execute
(
'''
CREATE TABLE IF NOT EXISTS AdditionalPhotos (
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
url text NOT NULL,
workspace_id integer NOT NULL,
FOREIGN KEY (workspace_id) REFERENCES Workspaces(id))
'''
)
conn
.
commit
()
class
Workspace
:
def
__init__
(
self
,
name
:
str
,
address
:
str
,
main_photo
:
str
,
additional_photos
:
List
[
str
],
description
:
str
,
website
:
str
,
email
:
str
,
phone_number
:
str
,
opening_hours
:
str
,
checkin_instructions
:
str
):
self
.
id
=
None
self
.
name
=
name
self
.
address
=
address
self
.
main_photo
=
main_photo
self
.
additional_photos
=
additional_photos
self
.
description
=
description
self
.
website
=
website
self
.
email
=
email
self
.
phone_number
=
phone_number
self
.
opening_hours
=
opening_hours
self
.
checkin_instructions
=
checkin_instructions
def
from_query
(
conn
,
tuple
):
(
id
,
name
,
address
,
main_photo
,
description
,
website
,
email
,
phone_number
,
opening_hours
,
checkin_instructions
)
=
tuple
additional_photos
=
[]
conn
.
execute
(
"
SELECT url FROM AdditionalPhotos WHERE workspace_id = ?
"
,
(
str
(
id
)))
for
x
in
conn
.
cursor
.
fetchall
():
additional_photos
.
append
(
x
[
0
])
workspace
=
Workspace
(
name
,
address
,
main_photo
,
additional_photos
,
description
,
website
,
email
,
phone_number
,
opening_hours
,
checkin_instructions
)
workspace
.
id
=
id
return
workspace
def
add_workspace
(
workspace
:
Workspace
):
with
Connection
()
as
conn
:
conn
.
execute
(
"
INSERT INTO Workspaces (name, address, main_photo, description, website, email, phone_number, opening_hours, checkin_instructions) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
"
,
(
workspace
.
name
,
workspace
.
address
,
workspace
.
main_photo
,
workspace
.
description
,
workspace
.
website
,
workspace
.
email
,
workspace
.
phone_number
,
workspace
.
opening_hours
,
workspace
.
checkin_instructions
)
)
id
=
conn
.
cursor
.
lastrowid
for
url
in
workspace
.
additional_photos
:
conn
.
execute
(
"
INSERT INTO AdditionalPhotos (url, workspace_id) VALUES (?, ?)
"
,
(
url
,
id
))
conn
.
commit
()
return
id
def
get_workspaces
():
with
Connection
()
as
conn
:
conn
.
execute
(
"
SELECT * FROM Workspaces
"
)
return
[
Workspace
.
from_query
(
conn
,
x
)
for
x
in
conn
.
cursor
.
fetchall
()]
print
(
get_workspaces
())
This diff is collapsed.
Click to expand it.
login.html
0 → 100644
+
36
−
0
View file @
391a89a7
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<link
rel=
"stylesheet"
href=
"static/style.css"
>
<!-- Bootstrap CSS -->
<link
rel=
"stylesheet"
href=
"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity=
"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin=
"anonymous"
>
<title>
{% block title %}{% endblock %} - Tramshed Workspaces
</title>
</head>
<form
class=
'myForm'
method=
"POST"
action=
""
>
<p>
Enter Username:
</p>
<br>
<input
type =
"text"
name =
"username"
placeholder=
"Username.."
><br>
<button
type =
"submit"
id=
'mySubmit'
>
Submit
</button>
</form>
<!-- <div class="parallax">
<body class="body">
<!--<img src="static/Tramshed_Logo.jpg" alt="Logo" height="50" width="100">-->
<!-- navigation -->
-->
<nav>
<ul>
<li><a
href=
"#home"
>
Home
</a></li>
<li><a
href=
"#Map"
>
Map
</a></li>
<li><a
href=
"#contactUs"
>
Contact Us
</a></li>
<li
style=
"float:right"
><a
class=
"active"
href=
"#about"
>
About
</a></li>
</ul>
</nav>
<!--{% block mainBlock %}{% endblock %}-->
</body>
</html>
This diff is collapsed.
Click to expand it.
main.py
0 → 100644
+
22
−
0
View file @
391a89a7
from
flask
import
Flask
,
request
,
render_template
import
database
app
=
Flask
(
__name__
)
@app.route
(
"
/
"
,
methods
=
[
"
GET
"
])
def
home
():
if
request
.
method
==
"
GET
"
:
workspaces
=
database
.
get_workspaces
()
return
render_template
(
"
home.html
"
,
workspaces
=
workspaces
)
@app.route
(
'
/login.html
'
,
methods
=
[
"
post
"
])
def
login
():
username
=
request
.
form
.
get
(
'
username
'
)
if
username
==
"
admin
"
:
return
redirect
(
"
/templates/home.html
"
)
else
:
message
=
"
Wrong Username
"
return
redirect
(
"
/login.html
"
)
if
__name__
==
"
__main__
"
:
app
.
run
(
debug
=
True
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment