-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: Add platform model and associated fields in Course and Program models #2699
Conversation
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.
I think we should also think ahead of time while adding this.
There are two things that are coming to my mind right now:
- Let's confirm if this is something we want the course team to manage in which case we might need to allow Partner model manipulation and association through Wagtail/CMS. Just like how we manage topics Django model through CMS. This will allow the course team to manage partners through Wagtail without involving the engineering team.
- Some time ago we added a partner logo in certificates at Partner logo in certificate template #2407. This is time we should think if we want to move that to this partner model.
courses/models.py
Outdated
@@ -209,6 +209,17 @@ def catalog_image_url(self): | |||
) | |||
|
|||
|
|||
class Partner(models.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.
Let's inherit this from TimestampedModel
I suggest that we keep the control in Django, and not on the CMS. This is a setting that should rarely be touched since we do not get a lot of new external partners.
Marketing does not want branding on the course catalog of the xPRO site. So we won't be needing this at least at the moment. Is this a complex thing to add? |
@cachob I think we can migrate the existing partners' logs if/when needed. In my opinion that should not be very hard, What I can think of right now is: (When we will need to associate partners with Logo)
|
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.
Just a couple of minor changes suggested.
I haven't tested it yet. I'll test it in the final review. Thanks for your patience on this.
courses/models.py
Outdated
Model for course partner | ||
""" | ||
|
||
name = models.CharField(max_length=255) |
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.
Let's make it unique(case-insensitive), I don't think we might need to ever support partners with the same name.
courses/admin.py
Outdated
@@ -377,6 +375,14 @@ class CourseTopicAdmin(ModelAdmin, admin.ModelAdmin): | |||
delete_view_class = TopicsWagtailDeleteView | |||
|
|||
|
|||
class PartnerAdmin(admin.ModelAdmin): |
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.
courses/factories.py
Outdated
class PartnerFactory(DjangoModelFactory): | ||
"""Factory for Company""" | ||
|
||
name = factory.Faker("partner") |
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.
Once we make the partner name unique, This will also be changed to have a prepending dynamic/random name.
courses/models.py
Outdated
@@ -220,6 +231,9 @@ class Program(TimestampedModel, PageProperties, ValidateOnSaveMixin): | |||
live = models.BooleanField(default=False) | |||
products = GenericRelation(Product, related_query_name="programs") | |||
is_external = models.BooleanField(default=False) | |||
partner = models.ForeignKey( |
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.
Ideally, We should have had a common model e.g. Courseware
having all the common fields from Course, Program
models e.g. live, title, readable_id
. And the Course, Program
models would inherit from that. Let me know what you think. Maybe we can keep this here for now and do a full refactor of all these in another PR?
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.
Yes, I think we should do this in a separate PR.
courses/serializers.py
Outdated
@@ -187,6 +188,10 @@ def get_format(self, instance): # pylint: disable=unused-argument | |||
# configurable. | |||
return "Online" | |||
|
|||
def get_partner(self, instance): | |||
"""Returns the partner of the course""" | |||
return instance.partner.name if instance.partner else None |
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.
nit:
return instance.partner.name if instance.partner else None | |
return getattr(instance.partner, "name", None) |
courses/serializers.py
Outdated
@@ -187,6 +188,10 @@ def get_format(self, instance): # pylint: disable=unused-argument | |||
# configurable. | |||
return "Online" | |||
|
|||
def get_partner(self, instance): | |||
"""Returns the partner of the course""" |
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.
"""Returns the partner of the course""" | |
"""Returns the partner name of the course""" |
courses/models.py
Outdated
Validates case insensitive partner name uniqueness. | ||
""" | ||
if ( | ||
self._state.adding |
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.
This should also be enabled for editing mode, Because you can still produce case insensitive partners by in edit mode.
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.
558aac7
to
d9ce219
Compare
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.
👍 Looks good. Thanks for your patience on this.
courses/models_test.py
Outdated
with pytest.raises(ValidationError): | ||
PartnerFactory.create(name="emeritus") | ||
|
||
PartnerFactory.create(name="Emirates") |
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.
nit: This line/creation might not be needed. I think the above assertion is enough.
Please hold off on merging this. I want to review the field name and make sure it's aligned with field names in MIT Open. |
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Partner", |
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.
For consistency with MIT Open, can we call this "Platform" instead of "Partner"
Sorry I didn't bring this up earlier.
@pdpinch Could you please have a look into this PR now? |
Pre-Flight checklist
What are the relevant tickets?
Fixes #2698
What's this PR do?
Adds a new model named
Platform
for course/program partners. Also, adds foreign key fields in the Course and Program models.How should this be manually tested?