Skip to content

Commit

Permalink
Merge pull request #64 from DakaraProject/update/django_lts
Browse files Browse the repository at this point in the history
Update Django to latest LTS
  • Loading branch information
Nadeflore authored May 20, 2018
2 parents d1f832e + f5ae9e5 commit 3a20775
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- Date when the entry is supposed to be played for playlist entries with `date_play`.
- End of playlist date with `date_end`.
- Limit to playlist size (default to 100 entries).
- Auto-generated documentation of the API: `/api-docs/`.

### Changed
- Playlist routes:
Expand All @@ -55,6 +56,7 @@
- Pagination information (`current` and `last`) for views that use a paginator are now gathered in the `pagination` key in the response.
- Song serialization no longer contains the `link_type_name` key (work link long name), the info has to be deduced from `link_type`.
- In the route `/playlist/entries`, the key to designate a song has changed: `song` > `song_id`.
- Users are now listed by their user name.

## 1.1.0 - 2018-01-25

Expand Down
4 changes: 4 additions & 0 deletions dakara_server/dakara_server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@

except ImportError:
from .default_settings import * # noqa F403

# if in debug mode, disable password validation
if DEBUG: # noqa F405
AUTH_PASSWORD_VALIDATORS = []
19 changes: 14 additions & 5 deletions dakara_server/dakara_server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.views.defaults import page_not_found
from django.contrib.staticfiles.views import serve
from rest_framework.authtoken.views import obtain_auth_token
from rest_framework.documentation import include_docs_urls

from library import views as library_views
from playlist import views as playlist_views
Expand Down Expand Up @@ -168,13 +169,21 @@
library_views.SongTagView.as_view(),
name='library-songtag-detail'
),

# API documentation routes
url(
r'^api-docs/',
include_docs_urls(title="Dakara server API")
),
]

if settings.DEBUG:
urlpatterns.extend([
# Default case for api routes
url(r'^api/', page_not_found),
# Default to main page
url(r'', 'django.contrib.staticfiles.views.serve', kwargs={
'path': 'index.html'})
url(
r'^(?!api/|api-docs/?)', # serve everything but the API routes
# API documentation routes
serve,
kwargs={'path': 'index.html'}
)
])
3 changes: 2 additions & 1 deletion dakara_server/library/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class Work(models.Model):
"""
title = models.CharField(max_length=255)
subtitle = models.CharField(max_length=255, blank=True)
work_type = models.ForeignKey('WorkType', null=True)
work_type = models.ForeignKey('WorkType', null=True,
on_delete=models.CASCADE)

def __str__(self):
return "{} ({})".format(
Expand Down
6 changes: 4 additions & 2 deletions dakara_server/playlist/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
class PlaylistEntry(models.Model):
"""Song in playlist
"""
song = models.ForeignKey('library.Song', null=False)
song = models.ForeignKey('library.Song', null=False,
on_delete=models.CASCADE)
date_created = models.DateTimeField(auto_now_add=True)
owner = models.ForeignKey(DakaraUser, null=False)
owner = models.ForeignKey(DakaraUser, null=False,
on_delete=models.CASCADE)
was_played = models.BooleanField(default=False, null=False)
date_played = models.DateTimeField(null=True)

Expand Down
18 changes: 8 additions & 10 deletions dakara_server/playlist/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,13 @@ def get_queryset(self):
class PlaylistEntryListView(ListCreateAPIView):
"""List of entries or creation of a new entry in the playlist
"""
serializer_class = serializers.PlaylistEntrySerializer
permission_classes = [
permissions.IsPlaylistUserOrReadOnly,
permissions.IsPlaylistAndLibraryManagerOrSongCanBeAdded,
permissions.KaraStatusIsNotStoppedOrReadOnly,
]

def get_serializer_class(self):
if self.request.method == 'POST':
return serializers.PlaylistEntrySerializer

return serializers.PlaylistEntriesWithDateEndSerializer

def get_queryset(self):
player = models.Player.get_or_create()
entry_id = player.playlist_entry_id
Expand All @@ -86,10 +81,13 @@ def get(self, request, *args, **kwargs):
playlist_entry.date_play = date
date += playlist_entry.song.duration

serializer = self.get_serializer({
'results': queryset,
'date_end': date,
})
serializer = serializers.PlaylistEntriesWithDateEndSerializer(
{
'results': queryset,
'date_end': date,
},
context={'request': request}
)

return Response(serializer.data)

Expand Down
36 changes: 36 additions & 0 deletions dakara_server/users/migrations/0002_auto_20180518_1532.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2018-05-18 15:32
from __future__ import unicode_literals

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='dakarauser',
name='username',
field=models.CharField(
error_messages={'unique': 'A user with that username \
already exists.'},
help_text='Required. 30 characters or fewer. Letters, \
digits and @/./+/-/_ only.',
max_length=30,
unique=True,
validators=[
django.core.validators.RegexValidator(
'^[\\w.@+-]+$',
'Enter a valid username. This value may contain \
only letters, numbers and @/./+/-/_ characters.'
)
],
verbose_name='username'
),
),
]
5 changes: 3 additions & 2 deletions dakara_server/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class UserListView(generics.ListCreateAPIView):
"""List and creation of users
"""
model = UserModel
queryset = UserModel.objects.all()
queryset = UserModel.objects.all().order_by('username')
serializer_class = serializers.UserSerializer
pagination_class = UsersPagination
permission_classes = [
Expand All @@ -52,7 +52,8 @@ class UserView(generics.RetrieveUpdateDestroyAPIView):
]

def get_serializer_class(self):
if self.request.method in ('PUT', 'PATCH'):
if self.request is not None and \
self.request.method in ('PUT', 'PATCH'):
return serializers.UserForManagerSerializer

return serializers.UserSerializer
Expand Down
2 changes: 1 addition & 1 deletion hooks/pre-commit.d/01_tests
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

echo "Running django tests"

(cd ./dakara_server && python ./manage.py test)
(cd ./dakara_server && python ./manage.py test --parallel)
14 changes: 9 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
Django==1.8.18
djangorestframework==3.3.1
pymediainfo==2.1.9
coreapi==2.3.3
flake8==3.5.0
Django==1.11.13
djangorestframework==3.6.4
Markdown==2.6.11
progressbar2==3.34.3
PyYAML==3.12
Pygments==2.2.0
pymediainfo==2.1.9
pysubs2==0.2.2
flake8==3.5.0
PyYAML==3.12
tblib==1.3.2

0 comments on commit 3a20775

Please sign in to comment.