Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
teknikattan-scoring-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tddd96-grupp1
teknikattan-scoring-system
Commits
27f86c26
Commit
27f86c26
authored
3 years ago
by
Josef Olsson
Browse files
Options
Downloads
Patches
Plain Diff
Add documentation for dbc.add
parent
3838b1ab
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/app/database/controller/add.py
+47
-1
47 additions, 1 deletion
server/app/database/controller/add.py
with
47 additions
and
1 deletion
server/app/database/controller/add.py
+
47
−
1
View file @
27f86c26
"""
This file contains functionality to add data to the database.
"""
import
app.core.http_codes
as
codes
from
app.core
import
db
from
app.database.controller
import
utils
...
...
@@ -22,6 +26,11 @@ from flask_restx import abort
def
db_add
(
item
):
"""
Internal function. Adds item to the database
and handles comitting and refreshing.
"""
db
.
session
.
add
(
item
)
db
.
session
.
commit
()
db
.
session
.
refresh
(
item
)
...
...
@@ -33,55 +42,88 @@ def db_add(item):
def
blacklist
(
jti
):
"""
Adds a blacklist to the database.
"""
return
db_add
(
Blacklist
(
jti
))
def
mediaType
(
name
):
"""
Adds a media type to the database.
"""
return
db_add
(
MediaType
(
name
))
def
questionType
(
name
):
"""
Adds a question type to the database.
"""
return
db_add
(
QuestionType
(
name
))
def
componentType
(
name
):
"""
Adds a component type to the database.
"""
return
db_add
(
ComponentType
(
name
))
def
viewType
(
name
):
"""
Adds a view type to the database.
"""
return
db_add
(
ViewType
(
name
))
def
role
(
name
):
"""
Adds a role to the database.
"""
return
db_add
(
Role
(
name
))
def
city
(
name
):
"""
Adds a city to the database.
"""
return
db_add
(
City
(
name
))
def
component
(
type_id
,
item_slide
,
data
,
x
=
0
,
y
=
0
,
w
=
0
,
h
=
0
):
"""
Adds a component to the slide at the specified coordinates with the
provided size and data .
"""
return
db_add
(
Component
(
item_slide
.
id
,
type_id
,
data
,
x
,
y
,
w
,
h
))
def
image
(
filename
,
user_id
):
"""
Adds an image to the database and keeps track of who called the function.
"""
return
db_add
(
Media
(
filename
,
1
,
user_id
))
def
user
(
email
,
password
,
role_id
,
city_id
,
name
=
None
):
"""
Adds a user to the database using the provided arguments.
"""
return
db_add
(
User
(
email
,
password
,
role_id
,
city_id
,
name
))
def
question
(
name
,
total_score
,
type_id
,
item_slide
):
"""
Adds a question to the specified slide using the provided arguments.
"""
return
db_add
(
Question
(
name
,
total_score
,
type_id
,
item_slide
.
id
))
def
code
(
pointer
,
view_type_id
):
"""
Adds a code to the database using the provided arguments.
"""
code_string
=
utils
.
generate_unique_code
()
return
db_add
(
Code
(
code_string
,
pointer
,
view_type_id
))
def
team
(
name
,
item_competition
):
"""
Adds a team with the specified name to the provided competition.
"""
item
=
db_add
(
Team
(
name
,
item_competition
.
id
))
# Add code for the team
...
...
@@ -91,11 +133,15 @@ def team(name, item_competition):
def
slide
(
item_competition
):
"""
Adds a slide to the provided competition.
"""
order
=
Slide
.
query
.
filter
(
Slide
.
competition_id
==
item_competition
.
id
).
count
()
# first element has index 0
return
db_add
(
Slide
(
order
,
item_competition
.
id
))
def
competition
(
name
,
year
,
city_id
):
"""
Adds a competition to the database using the provided arguments.
"""
item_competition
=
db_add
(
Competition
(
name
,
year
,
city_id
))
# Add one slide for the competition
...
...
@@ -107,7 +153,7 @@ def competition(name, year, city_id):
# Add code for Audience view
code
(
item_competition
.
id
,
3
)
# Add two teams
#
TODO:
Add two teams
utils
.
refresh
(
item_competition
)
return
item_competition
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