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
f2b60fe0
Commit
f2b60fe0
authored
3 years ago
by
robban64
Browse files
Options
Downloads
Patches
Plain Diff
fix: delete image conflict
parent
f84d4e6d
No related branches found
No related tags found
No related merge requests found
Pipeline
#45937
passed
3 years ago
Stage: setup
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/app/apis/media.py
+9
-0
9 additions, 0 deletions
server/app/apis/media.py
server/app/database/models.py
+5
-5
5 additions, 5 deletions
server/app/database/models.py
with
14 additions
and
5 deletions
server/app/apis/media.py
+
9
−
0
View file @
f2b60fe0
...
@@ -69,6 +69,15 @@ class ImageList(Resource):
...
@@ -69,6 +69,15 @@ class ImageList(Resource):
"""
Deletes the specified image.
"""
"""
Deletes the specified image.
"""
item
=
dbc
.
get
.
one
(
Media
,
media_id
)
item
=
dbc
.
get
.
one
(
Media
,
media_id
)
if
len
(
item
.
image_components
)
>
0
:
api
.
abort
(
codes
.
CONFLICT
,
"
Component depends on this Image
"
)
if
len
(
item
.
competition_background_images
)
>
0
:
api
.
abort
(
codes
.
CONFLICT
,
"
Competition background image depends on this Image
"
)
if
len
(
item
.
slide_background_images
)
>
0
:
api
.
abort
(
codes
.
CONFLICT
,
"
Slide background image depends on this Image
"
)
try
:
try
:
files
.
delete_image_and_thumbnail
(
item
.
filename
)
files
.
delete_image_and_thumbnail
(
item
.
filename
)
dbc
.
delete
.
default
(
item
)
dbc
.
delete
.
default
(
item
)
...
...
This diff is collapsed.
Click to expand it.
server/app/database/models.py
+
5
−
5
View file @
f2b60fe0
...
@@ -7,6 +7,7 @@ each other.
...
@@ -7,6 +7,7 @@ each other.
from
app.core
import
bcrypt
,
db
from
app.core
import
bcrypt
,
db
from
app.database.types
import
IMAGE_COMPONENT_ID
,
QUESTION_COMPONENT_ID
,
TEXT_COMPONENT_ID
from
app.database.types
import
IMAGE_COMPONENT_ID
,
QUESTION_COMPONENT_ID
,
TEXT_COMPONENT_ID
from
sqlalchemy.ext.hybrid
import
hybrid_method
,
hybrid_property
from
sqlalchemy.ext.hybrid
import
hybrid_method
,
hybrid_property
from
sqlalchemy.orm
import
backref
STRING_SIZE
=
254
# Default size of string Columns (varchar)
STRING_SIZE
=
254
# Default size of string Columns (varchar)
...
@@ -126,6 +127,10 @@ class Media(db.Model):
...
@@ -126,6 +127,10 @@ class Media(db.Model):
type_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
media_type.id
"
),
nullable
=
False
)
type_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
media_type.id
"
),
nullable
=
False
)
upload_by_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
user.id
"
),
nullable
=
False
)
upload_by_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
user.id
"
),
nullable
=
False
)
image_components
=
db
.
relationship
(
"
ImageComponent
"
,
backref
=
"
media
"
)
competition_background_images
=
db
.
relationship
(
"
Competition
"
,
backref
=
"
background_image
"
)
slide_background_images
=
db
.
relationship
(
"
Slide
"
,
backref
=
"
background_image
"
)
def
__init__
(
self
,
filename
,
type_id
,
upload_by_id
):
def
__init__
(
self
,
filename
,
type_id
,
upload_by_id
):
self
.
filename
=
filename
self
.
filename
=
filename
self
.
type_id
=
type_id
self
.
type_id
=
type_id
...
@@ -146,14 +151,11 @@ class Competition(db.Model):
...
@@ -146,14 +151,11 @@ class Competition(db.Model):
city_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
city.id
"
),
nullable
=
False
)
city_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
city.id
"
),
nullable
=
False
)
background_image_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
media.id
"
),
nullable
=
True
)
background_image_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
media.id
"
),
nullable
=
True
)
background_image
=
db
.
relationship
(
"
Media
"
,
uselist
=
False
)
slides
=
db
.
relationship
(
"
Slide
"
,
backref
=
"
competition
"
)
slides
=
db
.
relationship
(
"
Slide
"
,
backref
=
"
competition
"
)
teams
=
db
.
relationship
(
"
Team
"
,
backref
=
"
competition
"
)
teams
=
db
.
relationship
(
"
Team
"
,
backref
=
"
competition
"
)
codes
=
db
.
relationship
(
"
Code
"
,
backref
=
"
competition
"
)
codes
=
db
.
relationship
(
"
Code
"
,
backref
=
"
competition
"
)
background_image
=
db
.
relationship
(
"
Media
"
,
uselist
=
False
)
def
__init__
(
self
,
name
,
year
,
city_id
):
def
__init__
(
self
,
name
,
year
,
city_id
):
self
.
name
=
name
self
.
name
=
name
self
.
year
=
year
self
.
year
=
year
...
@@ -200,7 +202,6 @@ class Slide(db.Model):
...
@@ -200,7 +202,6 @@ class Slide(db.Model):
competition_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
competition.id
"
),
nullable
=
False
)
competition_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
competition.id
"
),
nullable
=
False
)
background_image_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
media.id
"
),
nullable
=
True
)
background_image_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
media.id
"
),
nullable
=
True
)
background_image
=
db
.
relationship
(
"
Media
"
,
uselist
=
False
)
components
=
db
.
relationship
(
"
Component
"
,
backref
=
"
slide
"
)
components
=
db
.
relationship
(
"
Component
"
,
backref
=
"
slide
"
)
questions
=
db
.
relationship
(
"
Question
"
,
backref
=
"
questions
"
)
questions
=
db
.
relationship
(
"
Question
"
,
backref
=
"
questions
"
)
...
@@ -336,7 +337,6 @@ class ImageComponent(Component):
...
@@ -336,7 +337,6 @@ class ImageComponent(Component):
"""
"""
media_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
media.id
"
),
nullable
=
True
)
media_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
"
media.id
"
),
nullable
=
True
)
media
=
db
.
relationship
(
"
Media
"
,
uselist
=
False
)
# __tablename__ = None
# __tablename__ = None
__mapper_args__
=
{
"
polymorphic_identity
"
:
IMAGE_COMPONENT_ID
}
__mapper_args__
=
{
"
polymorphic_identity
"
:
IMAGE_COMPONENT_ID
}
...
...
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