-
Notifications
You must be signed in to change notification settings - Fork 19
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
WIP implement clone method #37
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
clone_services_unrequired_fields = { | ||
"Advertiser": ["id", "name", "profile_id"], | ||
} | ||
|
||
|
||
class CloneMixin(): | ||
|
||
def clone(self, **kwargs): | ||
try: | ||
payload = {} | ||
for field in self.__dict__.keys(): | ||
if field not in clone_services_unrequired_fields[type(self).__name__]: | ||
payload[field] = self.__dict__[field] | ||
return self.create(payload, **kwargs) | ||
except KeyError: | ||
raise NotImplementedError("Clone method isn't yet available for {} service." | ||
.format(self.service_name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The message isn't correlated to the actual error. |
||
|
||
|
||
__all__ = ["CloneMixin", "clone_services_unrequired_fields"] |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ | |||||||
from thingy import Thingy | ||||||||
|
||||||||
from appnexus.client import AppNexusClient, client, services_list | ||||||||
from appnexus.clone_mixin import CloneMixin, clone_services_unrequired_fields | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for a module just for this mixin. :) |
||||||||
from appnexus.utils import classproperty, normalize_service_name | ||||||||
|
||||||||
logger = logging.getLogger("appnexus-client") | ||||||||
|
@@ -172,6 +173,8 @@ def create_models(services_list): | |||||||
if service_name in ("AdQualityRule", "Advertiser", "Campaign", | ||||||||
"Creative", "LineItem", "PaymentRule"): | ||||||||
ancestors.append(ProfileMixin) | ||||||||
if service_name in clone_services_unrequired_fields.keys(): | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
ancestors.append(CloneMixin) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
model = type(service_name, tuple(ancestors), {}) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
globals().setdefault(service_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.