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

Jkmarx/add config model #3177

Merged
merged 8 commits into from Jan 25, 2019
Merged

Jkmarx/add config model #3177

merged 8 commits into from Jan 25, 2019

Conversation

jkmarx
Copy link
Member

@jkmarx jkmarx commented Jan 17, 2019

  • Add model and api for getting and updating site profiles.


def partial_update(self, instance, validated_data):
"""
Update and return an existing `DataSet` instance, given the
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
Update and return an existing `DataSet` instance, given the
Update and return an existing `SiteProfile ` instance, given the

about_markdown = models.TextField(blank=True)
intro_markdown = models.TextField(blank=True)
twitter_username = models.CharField(max_length=100, blank=True)
yt_videos = models.TextField(blank=True)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe youtube_videos here instead?

Also rather than a TextField it looks like yt_videos could be better expressed through a relationship to another model?

Alternatives to that ^^^ would be:

instance.yt_videos = validated_data.get('yt_videos',
instance.yt_videos)
instance.save()
return instance
Copy link
Member

Choose a reason for hiding this comment

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

I think the shorthand for this would look like: instance.update(**validated_data)
Edit: Just kidding this wouldn't work... a QuerySet is required.

SiteProfile.objects.filter(pk=instance.pk).update(**validated_data) would probably work, but I haven't tried it out

return Response(serializer.data)

def patch(self, request):
if not request.user.is_superuser():
Copy link
Member

Choose a reason for hiding this comment

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

I'm sure you're thinking of adding this, but a test to ensure admin-only access would be great

@codecov
Copy link

codecov bot commented Jan 18, 2019

Codecov Report

Merging #3177 into develop will decrease coverage by <.01%.
The diff coverage is 89.5%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3177      +/-   ##
===========================================
- Coverage    61.98%   61.97%   -0.01%     
===========================================
  Files          438      438              
  Lines        27784    27676     -108     
  Branches      1285     1285              
===========================================
- Hits         17222    17153      -69     
+ Misses       10562    10523      -39
Impacted Files Coverage Δ
refinery/core/urls.py 100% <ø> (ø) ⬆️
refinery/core/models.py 78.51% <100%> (+0.14%) ⬆️
refinery/core/test_views.py 100% <100%> (ø) ⬆️
refinery/core/admin.py 85.41% <100%> (+0.47%) ⬆️
refinery/core/test_models.py 99.84% <100%> (ø) ⬆️
refinery/core/serializers.py 81.25% <64.28%> (-5.81%) ⬇️
refinery/core/views.py 50.69% <78.57%> (+2.18%) ⬆️
refinery/file_store/models.py 79.61% <0%> (-3.44%) ⬇️
refinery/file_store/tasks.py 58.15% <0%> (-1.92%) ⬇️
refinery/data_set_manager/views.py 62.04% <0%> (-0.32%) ⬇️
... and 4 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 ed06413...e040512. Read the comment docs.

@jkmarx jkmarx self-assigned this Jan 25, 2019
@jkmarx jkmarx added this to the Release 1.6.8 milestone Jan 25, 2019
This was referenced Jan 25, 2019
@@ -154,6 +154,10 @@ class SiteStatisticsAdmin(AdminFieldPopulator):
change_list_template = "admin/core/sitestatistics/change_list.html"


class SiteVideoAdmin(AdminFieldPopulator):
list_display = ['site_profile']
Copy link
Member

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 the site_profile or would it be useful to see the caption, source and source_id as well?

Copy link
Member Author

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?
screen shot 2019-01-25 at 9 33 00 am

class SiteVideo(models.Model):
caption = models.TextField(blank=True)
site_profile = models.ForeignKey(SiteProfile)
source = models.CharField(max_length=100, blank=True)
Copy link
Member

Choose a reason for hiding this comment

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

One thing that could be useful for the source field is the use of the choices arg.

class SiteVideo(models.Model):
    YOUTUBE = 'YT'

    VIDEO_SOURCE_CHOICES = (
        (YOUTUBE, 'Youtube'),
        ...
    )
    ...
    source = models.CharField(choices=VIDEO_SOURCE_CHOICES, max_length=100, blank=True)

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: youtube, Youtube, YouTube etc.

# delete unused videos
for video in db_site_videos:
if video.id not in new_video_list_ids:
video.delete()
Copy link
Member

Choose a reason for hiding this comment

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

If I'm reading this correctly an existing video will be deleted if its id isn't included in a given PATCH payload? So one would have to include all existing site_videos in a patch to preserve them even if they aren't being updated?

Copy link
Member Author

Choose a reason for hiding this comment

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

@scottx611x Yes. It makes sense to me since I'm doing it though the siteProfile api which has the entire list as a field.

db_video = SiteVideo.objects.get(
id=new_video_data.get('id')
)
except:
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to explicitly catch the DoesNotExist exception here

@jkmarx jkmarx merged commit 916a281 into develop Jan 25, 2019
@jkmarx jkmarx deleted the jkmarx/add-config-model branch January 25, 2019 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants