Skip to content

Commit

Permalink
Renaming _type to pulp_type
Browse files Browse the repository at this point in the history
  • Loading branch information
fao89 authored and daviddavis committed Oct 9, 2019
1 parent 96bb65e commit 14fe483
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGES/5454.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change `_type` to `pulp_type`
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Migration(migrations.Migration):

dependencies = [
('core', '0008_published_metadata_as_content'),
('core', '0009_remove_task_non_fatal_errors'),
]

operations = [
Expand Down Expand Up @@ -42,6 +42,11 @@ class Migration(migrations.Migration):
old_name='_last_updated',
new_name='pulp_last_updated',
),
migrations.RenameField(
model_name='basedistribution',
old_name='_type',
new_name='pulp_type',
),
migrations.RenameField(
model_name='content',
old_name='_created',
Expand All @@ -57,6 +62,11 @@ class Migration(migrations.Migration):
old_name='_last_updated',
new_name='pulp_last_updated',
),
migrations.RenameField(
model_name='content',
old_name='_type',
new_name='pulp_type',
),
migrations.RenameField(
model_name='contentappstatus',
old_name='_created',
Expand Down Expand Up @@ -102,6 +112,11 @@ class Migration(migrations.Migration):
old_name='_last_updated',
new_name='pulp_last_updated',
),
migrations.RenameField(
model_name='contentguard',
old_name='_type',
new_name='pulp_type',
),
migrations.RenameField(
model_name='createdresource',
old_name='_created',
Expand Down Expand Up @@ -132,6 +147,11 @@ class Migration(migrations.Migration):
old_name='_last_updated',
new_name='pulp_last_updated',
),
migrations.RenameField(
model_name='exporter',
old_name='_type',
new_name='pulp_type',
),
migrations.RenameField(
model_name='progressreport',
old_name='_created',
Expand Down Expand Up @@ -162,6 +182,11 @@ class Migration(migrations.Migration):
old_name='_last_updated',
new_name='pulp_last_updated',
),
migrations.RenameField(
model_name='publication',
old_name='_type',
new_name='pulp_type',
),
migrations.RenameField(
model_name='publishedartifact',
old_name='_created',
Expand Down Expand Up @@ -192,6 +217,11 @@ class Migration(migrations.Migration):
old_name='_last_updated',
new_name='pulp_last_updated',
),
migrations.RenameField(
model_name='publisher',
old_name='_type',
new_name='pulp_type',
),
migrations.RenameField(
model_name='remote',
old_name='_created',
Expand All @@ -207,6 +237,11 @@ class Migration(migrations.Migration):
old_name='_last_updated',
new_name='pulp_last_updated',
),
migrations.RenameField(
model_name='remote',
old_name='_type',
new_name='pulp_type',
),
migrations.RenameField(
model_name='remoteartifact',
old_name='_created',
Expand Down
18 changes: 9 additions & 9 deletions pulpcore/app/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ class MasterModel(Model, metaclass=MasterModelMeta):
Attributes:
TYPE (str): Default constant value saved into the ``_type``
TYPE (str): Default constant value saved into the ``pulp_type``
field of Model instances
Fields:
_type: The user-facing string identifying the detail type of this model
pulp_type: The user-facing string identifying the detail type of this model
Warning:
Subclasses of this class rely on there being no other parent/child Model
Expand All @@ -83,27 +83,27 @@ class MasterModel(Model, metaclass=MasterModelMeta):
# It can also be used for filtering across a relation where a model is related to a Master
# model. Set this to something reasonable in Master and Detail model classes, e.g. when
# create a master model, like "Remote", its TYPE value could be "remote". Then, when
# creating a Remote Detail class like PackageRemote, its _type value could be "package",
# creating a Remote Detail class like PackageRemote, its pulp_type value could be "package",
# not "package_remote", since "package_remote" would be redundant in the context of
# a remote Master model.
TYPE = None

# This field must have a value when models are saved, and defaults to the value of
# the TYPE attribute on the Model being saved (seen above).
_type = models.TextField(null=False, default=None)
pulp_type = models.TextField(null=False, default=None)

class Meta:
abstract = True

def save(self, *args, **kwargs):
# instances of "detail" models that subclass MasterModel are exposed
# on instances of MasterModel by the string stored in that model's TYPE attr.
# Storing this _type in a column on the MasterModel next to makes it trivial
# Storing this pulp_type in a column on the MasterModel next to makes it trivial
# to filter for specific detail model types across master's relations.
# Prepend the TYPE defined on a detail model with a django app label.
# If a plugin sets the type field themselves, it's used as-is.
if not self._type:
self._type = '{app_label}.{type}'.format(app_label=self._meta.app_label,
if not self.pulp_type:
self.pulp_type = '{app_label}.{type}'.format(app_label=self._meta.app_label,
type=self.TYPE)
return super().save(*args, **kwargs)

Expand Down Expand Up @@ -147,9 +147,9 @@ def __str__(self):
return super().__str__()

try:
return '<{} (_type={}): {}>'.format(self._meta.object_name, cast.TYPE, cast.name)
return '<{} (pulp_type={}): {}>'.format(self._meta.object_name, cast.TYPE, cast.name)
except AttributeError:
return '<{} (_type={}): pk={}>'.format(self._meta.object_name, cast.TYPE, cast.pk)
return '<{} (pulp_type={}): pk={}>'.format(self._meta.object_name, cast.TYPE, cast.pk)


# Add properties to model _meta info to support master/detail models
Expand Down
8 changes: 4 additions & 4 deletions pulpcore/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,10 @@ def compute_counts(self):
qs = self.content
elif value == RepositoryVersionContentDetails.REMOVED:
qs = self.removed()
annotated = qs.values('_type').annotate(count=models.Count('_type'))
annotated = qs.values('pulp_type').annotate(count=models.Count('pulp_type'))
for item in annotated:
count_obj = RepositoryVersionContentDetails(
content_type=item['_type'],
content_type=item['pulp_type'],
repository_version=self,
count=item['count'],
count_type=value,
Expand Down Expand Up @@ -561,9 +561,9 @@ def content_href(self):
Args:
obj (pulpcore.app.models.RepositoryVersion): The RepositoryVersion being serialized.
Returns:
dict: {<_type>: <url>}
dict: {<pulp_type>: <url>}
"""
ctype_model = Content.objects.filter(_type=self.content_type).first().cast().__class__
ctype_model = Content.objects.filter(pulp_type=self.content_type).first().cast().__class__
ctype_view = get_view_name_for_model(ctype_model, 'list')
try:
ctype_url = reverse(ctype_view)
Expand Down
6 changes: 3 additions & 3 deletions pulpcore/app/serializers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ def to_representation(self, obj):
dict: The dictionary has the following format.::
{
'added': {<_type>: {'count': <count>, 'href': <href>},
'removed': {<_type>: {'count': <count>, 'href': <href>},
'present': {<_type>: {'count': <count>, 'href': <href>},
'added': {<pulp_type>: {'count': <count>, 'href': <href>},
'removed': {<pulp_type>: {'count': <count>, 'href': <href>},
'present': {<pulp_type>: {'count': <count>, 'href': <href>},
}
"""
Expand Down
2 changes: 1 addition & 1 deletion pulpcore/app/tasks/orphan.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def orphan_cleanup():
# Content cleanup
content = Content.objects.exclude(pk__in=RepositoryContent.objects.values_list('content_id',
flat=True))
content = content.exclude(_type='core.{}'.format(PublishedMetadata.TYPE))
content = content.exclude(pulp_type='core.{}'.format(PublishedMetadata.TYPE))
progress_bar = ProgressReport(message='Clean up orphan Content', total=content.count(),
code='clean-up.content', done=0, state='running')
progress_bar.save()
Expand Down

0 comments on commit 14fe483

Please sign in to comment.