-
Notifications
You must be signed in to change notification settings - Fork 24
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
Jkmarx/add config model #3177
Jkmarx/add config model #3177
Changes from 7 commits
2f70b2c
99016d7
c2406c4
740702d
8727f81
5fb8cf2
435fc4b
e040512
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,44 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0028_auto_20180611_1640'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='SiteVideo', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, | ||
auto_created=True, primary_key=True)), | ||
('caption', models.TextField(blank=True)), | ||
('source', models.CharField(max_length=100, blank=True)), | ||
('source_id', models.CharField(max_length=100)), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='siteprofile', | ||
name='about_markdown', | ||
field=models.TextField(blank=True), | ||
), | ||
migrations.AddField( | ||
model_name='siteprofile', | ||
name='intro_markdown', | ||
field=models.TextField(blank=True), | ||
), | ||
migrations.AddField( | ||
model_name='siteprofile', | ||
name='twitter_username', | ||
field=models.CharField(max_length=100, blank=True), | ||
), | ||
migrations.AddField( | ||
model_name='sitevideo', | ||
name='site_profile', | ||
field=models.ForeignKey(to='core.SiteProfile'), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2221,6 +2221,9 @@ class SiteProfile(models.Model): | |
|
||
site = models.OneToOneField(Site, related_name='profile') | ||
repo_mode_home_page_html = models.TextField(blank=True) | ||
about_markdown = models.TextField(blank=True) | ||
intro_markdown = models.TextField(blank=True) | ||
twitter_username = models.CharField(max_length=100, blank=True) | ||
|
||
def __unicode__(self): | ||
return self.site.name | ||
|
@@ -2340,6 +2343,13 @@ def get_aggregate_sum(field_name): | |
] | ||
|
||
|
||
class SiteVideo(models.Model): | ||
caption = models.TextField(blank=True) | ||
site_profile = models.ForeignKey(SiteProfile) | ||
source = models.CharField(max_length=100, blank=True) | ||
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. One thing that could be useful for the
Even if we don't envision videos coming from too many different sources, this would still solve the problem of potentially having many differing entries like: |
||
source_id = models.CharField(max_length=100) | ||
|
||
|
||
class Event(models.Model): | ||
date_time = models.DateTimeField(default=timezone.now) | ||
data_set = models.ForeignKey(DataSet, null=True) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
from rest_framework import serializers | ||
from rest_framework.validators import UniqueValidator | ||
|
||
from .models import DataSet, Event, User, UserProfile, Workflow | ||
from .models import (DataSet, Event, SiteProfile, SiteVideo, User, | ||
UserProfile, Workflow) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -82,6 +83,52 @@ def partial_update(self, instance, validated_data): | |
return instance | ||
|
||
|
||
class SiteVideoSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = SiteVideo | ||
fields = ('caption', 'site_profile', 'source', 'source_id', 'id') | ||
|
||
def create(self, validated_data): | ||
return SiteVideo.objects.create(**validated_data) | ||
|
||
def partial_update(self, instance, validated_data): | ||
instance.caption = validated_data.get('caption', instance.caption) | ||
instance.source = validated_data.get('source', instance.source) | ||
instance.source_id = validated_data.get('source_id', | ||
instance.source_id) | ||
instance.save() | ||
return instance | ||
|
||
|
||
class SiteProfileSerializer(serializers.ModelSerializer): | ||
site_videos = serializers.SerializerMethodField() | ||
|
||
def get_site_videos(self, site_profile): | ||
site_videos = site_profile.sitevideo_set.all() | ||
serializer = SiteVideoSerializer(site_videos, many=True) | ||
return serializer.data | ||
|
||
class Meta: | ||
model = SiteProfile | ||
fields = ('about_markdown', 'site', 'intro_markdown', | ||
'twitter_username', 'site_videos') | ||
|
||
def partial_update(self, instance, validated_data): | ||
""" | ||
Update and return an existing `SiteProfile` instance, given the | ||
validated data. | ||
""" | ||
instance.about_markdown = validated_data.get('about_markdown', | ||
instance.about_markdown) | ||
instance.intro_markdown = validated_data.get('intro_markdown', | ||
instance.intro_markdown) | ||
instance.twitter_username = validated_data.get( | ||
'twitter_username', instance.twitter_username | ||
) | ||
instance.save() | ||
return instance | ||
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. I think the shorthand for this would look like:
|
||
|
||
|
||
class UserProfileSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
|
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.
AdminFieldPopulator
by default will expose all of a Model's fields in the Admin UI. Do we just want to show thesite_profile
or would it be useful to see thecaption
,source
andsource_id
as well?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.
@scottx611x It's displaying as I would expect below. Can you clarify?