-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Deduplicate get_new_slug method #7015
refactor: Deduplicate get_new_slug method #7015
Conversation
app/models/event_topic.py
Outdated
@@ -34,7 +17,7 @@ class EventTopic(SoftDeletionModel): | |||
|
|||
def __init__(self, **kwargs): | |||
super().__init__(**kwargs) | |||
self.slug = get_new_slug(name=self.name) | |||
self.slug = get_new_slug(name=self.name,EventTopic) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SyntaxError: positional argument follows keyword argument
missing whitespace after ','
app/models/event_sub_topic.py
Outdated
@@ -37,7 +19,7 @@ class EventSubTopic(SoftDeletionModel): | |||
|
|||
def __init__(self, **kwargs): | |||
super().__init__(**kwargs) | |||
self.slug = get_new_slug(name=self.name) | |||
self.slug = get_new_slug(name=self.name,EventSubTopic) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SyntaxError: positional argument follows keyword argument
missing whitespace after ','
app/models/event_location.py
Outdated
@@ -30,7 +13,7 @@ class EventLocation(db.Model): | |||
|
|||
def __init__(self, **kwargs): | |||
super().__init__(**kwargs) | |||
self.slug = get_new_slug(name=self.name) | |||
self.slug = get_new_slug(name=self.name,EventLocation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SyntaxError: positional argument follows keyword argument
missing whitespace after ','
app/api/helpers/db.py
Outdated
@@ -115,3 +116,23 @@ def get_count(query): | |||
count_q = query.statement.with_only_columns([func.count()]).order_by(None) | |||
count = query.session.execute(count_q).scalar() | |||
return count | |||
|
|||
|
|||
def get_new_slug(name,model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing whitespace after ','
app/api/helpers/db.py
Outdated
@@ -115,3 +116,23 @@ def get_count(query): | |||
count_q = query.statement.with_only_columns([func.count()]).order_by(None) | |||
count = query.session.execute(count_q).scalar() | |||
return count | |||
|
|||
|
|||
def get_new_slug(name, model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, but this should take (model, name)
, so it can be called like get_new_slug(EventLocation, name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.I will do it.
This pull request introduces 4 alerts when merging a9d9f52 into 1831bab - view on LGTM.com new alerts:
|
app/models/event_type.py
Outdated
import uuid | ||
|
||
from app.api.helpers.db import get_count | ||
from app.api.helpers.db import get_count, get_new_slug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'app.api.helpers.db.get_count' imported but unused
app/models/event_topic.py
Outdated
import uuid | ||
|
||
from app.api.helpers.db import get_count | ||
from app.api.helpers.db import get_count, get_new_slug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'app.api.helpers.db.get_count' imported but unused
app/models/event_sub_topic.py
Outdated
import uuid | ||
|
||
from app.api.helpers.db import get_count | ||
from app.api.helpers.db import get_count, get_new_slug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'app.api.helpers.db.get_count' imported but unused
app/models/event_location.py
Outdated
import uuid | ||
|
||
from app.api.helpers.db import get_count | ||
from app.api.helpers.db import get_count, get_new_slug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'app.api.helpers.db.get_count' imported but unused
Black would make changes.
Codecov Report
@@ Coverage Diff @@
## development #7015 +/- ##
===============================================
+ Coverage 59.82% 60.55% +0.73%
===============================================
Files 259 260 +1
Lines 12875 12875
===============================================
+ Hits 7702 7797 +95
+ Misses 5173 5078 -95
Continue to review full report at Codecov.
|
app/models/event_location.py
Outdated
@@ -30,7 +13,7 @@ class EventLocation(db.Model): | |||
|
|||
def __init__(self, **kwargs): | |||
super().__init__(**kwargs) | |||
self.slug = get_new_slug(name=self.name) | |||
self.slug = get_new_slug(EventLocation, name=self.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.slug = get_new_slug(EventLocation, name=self.name) | |
self.slug = get_new_slug(EventLocation, self.name) |
app/models/event_sub_topic.py
Outdated
@@ -37,7 +19,7 @@ class EventSubTopic(SoftDeletionModel): | |||
|
|||
def __init__(self, **kwargs): | |||
super().__init__(**kwargs) | |||
self.slug = get_new_slug(name=self.name) | |||
self.slug = get_new_slug(EventSubTopic, name=self.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same. Remove keyword argument
app/models/event_topic.py
Outdated
@@ -34,7 +17,7 @@ class EventTopic(SoftDeletionModel): | |||
|
|||
def __init__(self, **kwargs): | |||
super().__init__(**kwargs) | |||
self.slug = get_new_slug(name=self.name) | |||
self.slug = get_new_slug(EventTopic, name=self.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
app/models/event_type.py
Outdated
@@ -32,7 +15,7 @@ class EventType(SoftDeletionModel): | |||
|
|||
def __init__(self, **kwargs): | |||
super().__init__(**kwargs) | |||
self.slug = get_new_slug(name=self.name) | |||
self.slug = get_new_slug(EventType, name=self.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
Complexity decreasing per file
==============================
+ app/models/event_location.py -1
+ app/models/event_type.py -1
+ app/models/event_sub_topic.py -1
+ app/models/event_topic.py -1
Clones removed
==============
+ app/models/event_type.py -1
+ app/models/event_sub_topic.py -1
+ app/models/event_topic.py -1
See the complete overview on Codacy |
Fixes #6984
Short description of what this resolves:
Adds a generic get_new_slug method, prevents repetition of code.
development
branch.