Initial commit

This commit is contained in:
2018-10-04 14:36:11 +03:00
commit 784d4deec8
36 changed files with 11520 additions and 0 deletions

0
YtManagerApp/__init__.py Normal file
View File

6
YtManagerApp/admin.py Normal file
View File

@ -0,0 +1,6 @@
from django.contrib import admin
from .models import SubscriptionFolder, Subscription, Video
admin.site.register(SubscriptionFolder)
admin.site.register(Subscription)
admin.site.register(Video)

5
YtManagerApp/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class YtmanagerappConfig(AppConfig):
name = 'YtManagerApp'

View File

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-10-03 09:12
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Subscription',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
],
),
migrations.CreateModel(
name='SubscriptionFolder',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='YtManagerApp.SubscriptionFolder')),
],
),
migrations.AddField(
model_name='subscription',
name='parent_folder',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='YtManagerApp.SubscriptionFolder'),
),
]

View File

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-10-03 09:23
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('YtManagerApp', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Video',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField()),
('ytid', models.TextField()),
('downloaded_path', models.TextField(null=True)),
('watched', models.BooleanField(default=False)),
],
),
migrations.AddField(
model_name='subscription',
name='url',
field=models.TextField(default='', unique=True),
preserve_default=False,
),
migrations.AlterField(
model_name='subscription',
name='parent_folder',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='YtManagerApp.SubscriptionFolder'),
),
migrations.AlterField(
model_name='subscriptionfolder',
name='parent',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='YtManagerApp.SubscriptionFolder'),
),
migrations.AddField(
model_name='video',
name='subscription',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='YtManagerApp.Subscription'),
),
]

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-10-03 18:25
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('YtManagerApp', '0002_auto_20181003_0923'),
]
operations = [
migrations.AlterField(
model_name='subscription',
name='parent_folder',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='YtManagerApp.SubscriptionFolder'),
),
migrations.AlterField(
model_name='subscriptionfolder',
name='parent',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='YtManagerApp.SubscriptionFolder'),
),
]

View File

28
YtManagerApp/models.py Normal file
View File

@ -0,0 +1,28 @@
from django.db import models
class SubscriptionFolder(models.Model):
name = models.TextField(null=False)
parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True)
def __str__(self):
return self.name
class Subscription(models.Model):
name = models.TextField(null=False)
parent_folder = models.ForeignKey(SubscriptionFolder, on_delete=models.SET_NULL, null=True, blank=True)
url = models.TextField(null=False, unique=True)
def __str__(self):
return self.name
class Video(models.Model):
name = models.TextField(null=False)
ytid = models.TextField(null=False)
downloaded_path = models.TextField(null=True, blank=True)
watched = models.BooleanField(default=False, null=False)
subscription = models.ForeignKey(Subscription, on_delete=models.CASCADE)
def __str__(self):
return self.name

View File

@ -0,0 +1,9 @@
/* Some material font helpers */
.material-folder::before {
content: "\e2c7";
}
.material-person::before {
content: "\e7fd";
}

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/><path d="M0 0h24v24H0z" fill="none"/></svg>

After

Width:  |  Height:  |  Size: 229 B

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/><path d="M0 0h24v24H0z" fill="none"/></svg>

After

Width:  |  Height:  |  Size: 247 B

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,50 @@
function onSelectionChanged(e, data)
{
node = data.instance.get_selected(true)[0];
}
function validateChange(operation, node, parent, position, more)
{
if (more.dnd)
{
// create_node, rename_node, delete_node, move_node and copy_node
if (operation === "copy_node" || operation === "move_node")
{
if (more.ref.type === "sub")
return false;
}
}
return true;
}
function setupTree(dataIn)
{
$("#tree-wrapper").jstree({
core : {
data : {
url : 'ajax/get_children'
},
check_callback : validateChange,
themes : {
dots : false
},
},
types : {
folder : {
icon : "material-icons material-folder"
},
sub : {
icon : "material-icons material-person",
max_depth : 0
}
},
plugins : [ "types", "wholerow", "dnd" ]
});
$("#tree-wrapper").on("changed.jstree", onSelectionChanged);
}
$(document).ready(function ()
{
setupTree();
})

View File

@ -0,0 +1,31 @@
<div id="folder_edit_dialog" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit folder</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group row">
<label class="col-sm-4" for="folder_edit_dialog_name">Name</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="folder_edit_dialog_name" placeholder="Folder name">
</div>
</div>
<div class="form-check row">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Check me out</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,30 @@
{% extends "YtManagerApp/main_master_detail.html" %}
{% load static %}
{% block stylesheets %}
<link rel="stylesheet" href="{% static 'YtManagerApp/import/jstree/themes/default/style.min.css' %}" />
{% endblock %}
{% block scripts %}
<script src="{% static 'YtManagerApp/import/jstree/jstree.js' %}"></script>
<script src="{% static 'YtManagerApp/js/subtree.js' %}"></script>
{% endblock %}
{% block master %}
<div class="btn-toolbar" role="toolbar" aria-label="Subscriptions toolbar">
<div class="btn-group btn-group-sm mr-2" role="group">
<button type="button" class="btn btn-secondary">
<i class="material-icons" aria-hidden="true">add</i>
</button>
<button type="button" class="btn btn-secondary">
<i class="material-icons" aria-hidden="true">create_new_folder</i>
</button>
</div>
</div>
<div id="tree-wrapper">
<p>Loading...</p>
</div>
{% endblock %}

View File

@ -0,0 +1,32 @@
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>{% block title %}YouTube Subscription Manager{% endblock %}</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="{% static 'YtManagerApp/css/style.css' %}">
{% block stylesheets %}
{% endblock %}
</head>
<body>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
{% block scripts %}
{% endblock %}
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="{% url 'home' %}">YouTube Manager</a>
</nav>
<div class="container-fluid">
{% block body %}
{% endblock %}
</div>
</body>
</html>

View File

@ -0,0 +1,16 @@
{% extends "YtManagerApp/main_default.html" %}
{% block body %}
<div class="row">
<div class="col-sm-3">
{% block master %}
{% endblock %}
</div>
<div class="col-sm-9">
{% block detail %}
{% endblock %}
</div>
</div>
{% endblock %}

3
YtManagerApp/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

48
YtManagerApp/views.py Normal file
View File

@ -0,0 +1,48 @@
from django.shortcuts import render
from django.http import HttpResponse, HttpRequest, JsonResponse
from .models import SubscriptionFolder, Subscription
def get_children_recurse(parent_id):
children = []
for folder in SubscriptionFolder.objects.filter(parent_id=parent_id).order_by('name'):
children.append({
"id" : "folder" + str(folder.id),
"text" : folder.name,
"type" : "folder",
"children" : get_children_recurse(folder.id)
})
for sub in Subscription.objects.filter(parent_folder_id=parent_id).order_by('name'):
children.append({
"id" : "sub" + str(sub.id),
"type" : "sub",
"text" : sub.name
})
return children
def get_folders(parent_id, path = ""):
folders = []
for folder in SubscriptionFolder.objects.filter(parent_id=parent_id).order_by('name'):
folder_path = path + "/" + folder.name
folders.append({
"id" : "folder" + str(folder.id),
"text" : folder_path
})
folders.extend(get_folders(folder.id, folder_path))
return folders
def ajax_get_children(request: HttpRequest):
return JsonResponse(get_children_recurse(None), safe=False)
def ajax_get_folders(request: HttpRequest):
return JsonResponse(get_folders(None), safe=False)
def index(request: HttpRequest):
context = {}
return render(request, 'YtManagerApp/index.html', context)