Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
**.DS_Store
lte_extras/media/app/
BUILD/
*__pycache__*
.vscode
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ WEBSERVICES_VERSION=0.9.10
WEBGUI_VERSION=0.9.10
WEBADMIN_VERSION=0.9.1

YOUTUBE_VERSION=0.9

TARGET_DIR=./BUILD/

build_deps:
Expand Down Expand Up @@ -151,3 +153,24 @@ webadmin: target
./package/webadmin/colte-webadmin.service=/etc/systemd/system/colte-webadmin.service \
./package/webadmin/webadmin.env=/usr/local/etc/colte/webadmin.env

### Locally-Hosted Webservices Start Here ###
ourtube: target
fpm --input-type dir \
--output-type deb \
--force \
--vendor uw-ictd \
--config-files /usr/bin/ourtube_data/conf/ourtube.config \
--maintainer durandn@cs.washington.edu \
--description "Locally-Hosted Open Source Video Sharing App" \
--url "https://github.com/uw-ictd/colte" \
--name ourtube \
--version $(YOUTUBE_VERSION) \
--package $(TARGET_DIR) \
--depends 'python3, python3-pip' \
--after-install ./package/ourtube/postinst \
--after-remove ./package/ourtube/postrm \
./lte_extras/ourtube/=/usr/bin/ourtube_data \
./package/ourtube/ourtube=/usr/bin/ourtube \
./package/ourtube/ourtube.service=/etc/systemd/system/ourtube.service \
./package/ourtube/ourtube.config=/usr/local/etc/ourtube.config

1 change: 1 addition & 0 deletions lte_extras/ourtube/conf/ourtube.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PORT=8100
15 changes: 15 additions & 0 deletions lte_extras/ourtube/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python
import os
import sys

if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'video_webapp.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
Binary file added lte_extras/ourtube/media/default.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lte_extras/ourtube/media/default_thumbnail.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
17 changes: 17 additions & 0 deletions lte_extras/ourtube/posts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.contrib import admin
from django.db import models
from .models import Post, Comment
from django.forms import TextInput, Textarea

class CustomModelAdmin(admin.ModelAdmin):
formfield_overrides = {
models.CharField: {'widget': TextInput(attrs={'size':1000})},
models.TextField: {'widget': Textarea(attrs={'rows':1000,
'cols':1000,
'style':'resize:none;'})},
}

admin.site.register(Comment, CustomModelAdmin)

# Register your models here.
admin.site.register(Post)
5 changes: 5 additions & 0 deletions lte_extras/ourtube/posts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class PostsConfig(AppConfig):
name = 'posts'
26 changes: 26 additions & 0 deletions lte_extras/ourtube/posts/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django import forms
from .models import Comment

class CommentCreationForm(forms.ModelForm):
# Type of field used in rendered form
comment = forms.CharField(label="", help_text="", widget=forms.Textarea(attrs={'rows':5,'cols':20, 'style':'resize:none;'}))

class Meta:
# Model to save comment as
model = Comment

# Fields to display in the rendered form
fields = ('comment',)

class CommentUpdateForm(forms.ModelForm):
comment = forms.CharField(label="", help_text="", widget=forms.Textarea(attrs={'rows':5,'cols':20, 'style':'resize:none;'}))

class Meta:
model = Comment
fields = ('comment',)

class CommentDeleteForm(forms.ModelForm):
class Meta:
model = Comment
fields = []

54 changes: 54 additions & 0 deletions lte_extras/ourtube/posts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from django.db import models
from django.utils import timezone
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.core.validators import FileExtensionValidator
from PIL import Image

# Helper function to get local time
def get_local_time():
return timezone.localtime(timezone.now())

# The Post class is a model for creating genereic posts
# These posts must include a title and content, but
# not a video or video thumbnail
class Post(models.Model):
title = models.CharField(max_length=100)
content = models.TextField()
date_posted = models.DateTimeField(default=get_local_time) # passing in function for timezone
author = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) # CASCADE will delete post if user is deleted

# Optional video fields
# blank means that it is not required on the form when posting
# null allows the database to not have an entry (i.e. no default)
video = models.FileField(blank=True, null=True, upload_to='videos/%Y/%m/%d/', verbose_name='Video (optional)',
validators=[FileExtensionValidator(allowed_extensions=['mp4', 'ogb', 'webm'])])

video_thumbnail = models.ImageField(blank=True, default='default_thumbnail.jpg', verbose_name='Video Thumbnail (optional)',
upload_to='thumbnails/%Y/%m/%d/')

# For resizing thumnail
def save(self, *args, **kwargs):
# Use the original save first
super().save(*args, **kwargs)

# Resize the thumbnail
thumbnail = Image.open(self.video_thumbnail.path)
output_size = (160, 90)
thumbnail.thumbnail(output_size)
thumbnail.save(self.video_thumbnail.path)

# Use title as the string
def __str__(self):
return self.title

def get_absolute_url(self):
return reverse('post-detail', kwargs={'pk': self.pk})

# The comment model is for creating comments within the post model
class Comment(models.Model):
post = models.ForeignKey(Post, on_delete=models.CASCADE)
author = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
comment = models.TextField(verbose_name=u"")
date_posted = models.DateTimeField(default=get_local_time)

Loading