Skip to content
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

Merged
merged 6 commits into from May 16, 2020

Conversation

sanjana-302
Copy link
Contributor

Fixes #6984

Short description of what this resolves:

Adds a generic get_new_slug method, prevents repetition of code.

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream development branch.
  • The unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All the functions created/modified in this PR contain relevant docstrings.

app/models/event_type.py Outdated Show resolved Hide resolved
@@ -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)

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 ','

@@ -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)

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 ','

@@ -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)

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 ','

@@ -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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace after ','

@sanjana-302 sanjana-302 reopened this May 15, 2020
@@ -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):
Copy link
Member

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)

Copy link
Contributor Author

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.

@lgtm-com
Copy link
Contributor

lgtm-com bot commented May 15, 2020

This pull request introduces 4 alerts when merging a9d9f52 into 1831bab - view on LGTM.com

new alerts:

  • 4 for Unused import

import uuid

from app.api.helpers.db import get_count
from app.api.helpers.db import get_count, get_new_slug

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

import uuid

from app.api.helpers.db import get_count
from app.api.helpers.db import get_count, get_new_slug

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

import uuid

from app.api.helpers.db import get_count
from app.api.helpers.db import get_count, get_new_slug

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

import uuid

from app.api.helpers.db import get_count
from app.api.helpers.db import get_count, get_new_slug

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
Copy link

codecov bot commented May 16, 2020

Codecov Report

Merging #7015 into development will increase coverage by 0.73%.
The diff coverage is 100.00%.

Impacted file tree graph

@@               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     
Impacted Files Coverage Δ
app/api/helpers/db.py 100.00% <100.00%> (+14.28%) ⬆️
app/models/event_location.py 91.66% <100.00%> (+2.19%) ⬆️
app/models/event_sub_topic.py 93.75% <100.00%> (-1.91%) ⬇️
app/models/event_topic.py 93.75% <100.00%> (+2.44%) ⬆️
app/models/event_type.py 92.85% <100.00%> (+2.38%) ⬆️
app/api/helpers/query.py 43.47% <0.00%> (-0.53%) ⬇️
app/api/helpers/payment.py 23.87% <0.00%> (-0.49%) ⬇️
app/api/tax.py 52.45% <0.00%> (ø)
app/api/roles.py 57.14% <0.00%> (ø)
app/api/users.py 29.82% <0.00%> (ø)
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 05fc6d2...95d3742. Read the comment docs.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.slug = get_new_slug(EventLocation, name=self.name)
self.slug = get_new_slug(EventLocation, self.name)

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same. Remove keyword argument

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@niranjan94
Copy link
Member

Codacy Here is an overview of what got changed by this pull request:

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

@iamareebjamal iamareebjamal changed the title ref: Deduplicate get_new_slug method refactor: Deduplicate get_new_slug method May 16, 2020
@iamareebjamal iamareebjamal merged commit 069d8f8 into fossasia:development May 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deduplicate get_new_slug method
4 participants