mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-10 07:52:20 +01:00
Initial commit.
This commit is contained in:
0
marietje/songs/__init__.py
Normal file
0
marietje/songs/__init__.py
Normal file
8
marietje/songs/admin.py
Normal file
8
marietje/songs/admin.py
Normal file
@ -0,0 +1,8 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Song
|
||||
|
||||
|
||||
@admin.register(Song)
|
||||
class OrderAdmin(admin.ModelAdmin):
|
||||
list_display = ('artist', 'title', 'user')
|
||||
5
marietje/songs/apps.py
Normal file
5
marietje/songs/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SongsConfig(AppConfig):
|
||||
name = 'songs'
|
||||
32
marietje/songs/migrations/0001_initial.py
Normal file
32
marietje/songs/migrations/0001_initial.py
Normal file
@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-01-10 17:14
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Song',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('artist', models.TextField()),
|
||||
('title', models.TextField()),
|
||||
('hash', models.TextField()),
|
||||
('duration', models.IntegerField()),
|
||||
('old_id', models.TextField(blank=True, default=None, null=True)),
|
||||
('deleted', models.BooleanField(default=False)),
|
||||
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
marietje/songs/migrations/__init__.py
Normal file
0
marietje/songs/migrations/__init__.py
Normal file
20
marietje/songs/models.py
Normal file
20
marietje/songs/models.py
Normal file
@ -0,0 +1,20 @@
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Song(models.Model):
|
||||
user = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.SET_NULL,
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
artist = models.TextField()
|
||||
title = models.TextField()
|
||||
hash = models.TextField()
|
||||
duration = models.IntegerField()
|
||||
old_id = models.TextField(blank=True, null=True, default=None)
|
||||
deleted = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.artist + ' - ' + self.title
|
||||
28
marietje/songs/templates/songs/edit.html
Normal file
28
marietje/songs/templates/songs/edit.html
Normal file
@ -0,0 +1,28 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Manage{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form action="/songs/edit/{{ song.id }}" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<div class="row centered-form">
|
||||
<div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Edit Song</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<input type="text" id="artist" name="artist" class="form-control input-sm" placeholder="Artist" value="{{ song.artist }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="text" id="title" name="title" class="form-control input-sm" placeholder="Title" value="{{ song.title }}">
|
||||
</div>
|
||||
<input type="submit" value="Save" class="btn btn-primary btn-block">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
44
marietje/songs/templates/songs/manage.html
Normal file
44
marietje/songs/templates/songs/manage.html
Normal file
@ -0,0 +1,44 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Manage{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="table-responsive">
|
||||
<table id="request-table" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Artist</th>
|
||||
<th>Title</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><input id="search-artist" class="search-input" type="text"></th>
|
||||
<th><input id="search-title" class="search-input" type="text"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="3" class="ts-pager form-horizontal">
|
||||
<button type="button" class="btn first"><i class="icon-step-backward glyphicon glyphicon-step-backward"></i></button>
|
||||
<button type="button" class="btn prev"><i class="icon-arrow-left glyphicon glyphicon-backward"></i></button>
|
||||
<button type="button" class="btn next"><i class="icon-arrow-right glyphicon glyphicon-forward"></i></button>
|
||||
<button type="button" class="btn last"><i class="icon-step-forward glyphicon glyphicon-step-forward"></i></button>
|
||||
<select class="pagesize input-mini" title="Select page size">
|
||||
<option selected value="10">10</option>
|
||||
<option value="25">25</option>
|
||||
<option value="50">50</option>
|
||||
<option value="100">100</option>
|
||||
</select>
|
||||
<select class="pagenum input-mini" title="Select page number"></select>
|
||||
</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<script type="text/javascript" src="{% static 'js/manage.js' %}"></script>
|
||||
<script type="text/javascript">
|
||||
var csrf_token = "{{ csrf_token }}";
|
||||
</script>
|
||||
{% endblock %}
|
||||
56
marietje/songs/templates/songs/upload.html
Normal file
56
marietje/songs/templates/songs/upload.html
Normal file
@ -0,0 +1,56 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Upload{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-10 col-md-6 col-sm-offset-1 col-md-offset-3">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Upload</h3>
|
||||
</div>
|
||||
<div class="panel-body ">
|
||||
<div class="forms-container">
|
||||
<div class="panel panel-default uploadform">
|
||||
<div class="panel-body">
|
||||
<form action="/api/upload" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<div class="fileupload fileupload-new" data-provides="fileupload">
|
||||
<span class="btn btn-primary btn-file"><span class="fileupload-new">Select file</span>
|
||||
<span class="fileupload-exists">Change</span>
|
||||
<input class="filefield" type="file" name="file" accept="audio/*" />
|
||||
</span>
|
||||
<br>
|
||||
<span class="fileupload-preview"></span>
|
||||
<a href="#" class="close fileupload-exists" data-dismiss="fileupload" style="float: none">×</a>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="text" name="artist" class="form-control input-sm artist" placeholder="Artist">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="text" name="title" class="form-control input-sm title" placeholder="Title">
|
||||
</div>
|
||||
<span class="result-message"></span>
|
||||
<div class="progress">
|
||||
<div class="progress-bar progress-bar-info progress-bar-striped" role="progressbar" style="width: 0%;">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button id="add" class="btn btn-primary">+</button>
|
||||
<button id="remove" class="btn btn-primary">-</button>
|
||||
<br><br>
|
||||
<button id="upload" class="btn btn-primary btn-block">Upload</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<link rel="stylesheet" href="{% static 'css/upload.css' %}" />
|
||||
<script type="text/javascript" src="{% static 'js/upload.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'js/id3.min.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'js/jquery.form.min.js' %}"></script>
|
||||
{% endblock %}
|
||||
3
marietje/songs/tests.py
Normal file
3
marietje/songs/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
11
marietje/songs/urls.py
Normal file
11
marietje/songs/urls.py
Normal file
@ -0,0 +1,11 @@
|
||||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = 'songs'
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^upload/', views.upload, name='upload'),
|
||||
url(r'^manage/', views.manage, name='manage'),
|
||||
url(r'^edit/([0-9]+)', views.edit),
|
||||
]
|
||||
28
marietje/songs/views.py
Normal file
28
marietje/songs/views.py
Normal file
@ -0,0 +1,28 @@
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from .models import Song
|
||||
|
||||
|
||||
@login_required
|
||||
def upload(request):
|
||||
return render(request, 'songs/upload.html')
|
||||
|
||||
|
||||
@login_required
|
||||
def manage(request):
|
||||
return render(request, 'songs/manage.html')
|
||||
|
||||
|
||||
@login_required
|
||||
def edit(request, id):
|
||||
song = get_object_or_404(Song, pk=id, user=request.user)
|
||||
if not request.POST:
|
||||
return render(request, 'songs/edit.html', {'song': song})
|
||||
|
||||
# Save data.
|
||||
artist = request.POST.get('artist')
|
||||
title = request.POST.get('title')
|
||||
song.artist = artist
|
||||
song.title = title
|
||||
song.save()
|
||||
return redirect('songs:manage')
|
||||
Reference in New Issue
Block a user