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
78 changes: 78 additions & 0 deletions proyecto_musica/api/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from authentication.models import User, Skills, User_Skills, Genres, User_Genres, User_Artists, User_Youtube, User_Vimeo, Nationality, User_Nationality, User_Videos
from rest_framework import response, status
from enum import Enum
import re
from api.models import Images
from api.models import Videos
import os
from proyecto_musica.settings import BASE_DIR
from pathlib import Path
import shutil
from api.models import Images, Videos



def validate_request(jd):
if len(jd) != 2:
res = {'success' : False, 'error': "you didnt add all of the parameters"}
return response.Response(res, status=status.HTTP_400_BAD_REQUEST)

if "title" not in jd:
res = {'success' : False, 'error' : "Title has to be specified in the request as a key"}
return response.Response(res, status=status.HTTP_400_BAD_REQUEST)

if "image" not in jd:
res = {'success' : False, 'error' : "Image has to be specified in the request as a key"}
return response.Response(res, status=status.HTTP_400_BAD_REQUEST)

return None


def validate_image_title(jd):
valid_titles = ["image_1","image_2","image_3","image_4","image_5","image_6", "profile_image"]

if jd['title'] not in valid_titles:
res = {'success' : False, 'error': "not a valid image title"}
return response.Response(res, status=status.HTTP_400_BAD_REQUEST)

return None


def deleteImage(img):
if len(img) == 0:
res = {'success' : False, 'error': 'image with that id does not exist'}
return response.Response(res)

imgeObj = img[0]
imgeObj.image.delete()
imgeObj.delete()
return None


def deleteVideo(vid):
if len(vid) == 0:
res = {'success' : False, 'error': 'video with that id does not exist'}
return response.Response(res)

videoObj = vid[0]
videoObj.video.delete()
videoObj.delete()
return None


def postVideo(currentUsrVideo):
if not currentUsrVideo:
res = {'success' : False, 'error' : "Request must contain video as a key."}
return response.Response(res, status=status.HTTP_400_BAD_REQUEST)

if len(currentUsrVideo) < 0:
res = {'success' : False, 'error' : "Request must contain video as a key."}
return response.Response(res, status=status.HTTP_400_BAD_REQUEST)

return None






60 changes: 1 addition & 59 deletions proyecto_musica/api/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# create user model
from django.shortcuts import render

from django.db import models
from authentication.models import User
from datetime import datetime
Expand All @@ -9,19 +7,10 @@
import random


# TODO: make cleaner
def get_uplaod_file_name(userpic, filename):
ext = filename.split('.')[-1]

# TODO: change the name of the file

newName = str(uuid.uuid4()) + '.' + ext

print("uid",)
print('here', u'photos/%s/profileImg//%s' % (str(userpic.user.id),newName))



if userpic.title == "profile_image":
return u'photos/%s/profileImg//%s' % (str(userpic.user.id),newName)
return u'photos/%s/%s' % (str(userpic.user.id),newName)
Expand All @@ -33,20 +22,8 @@ def get_uplaod_video_name(userpic, filename):
return u'videos/%s/vids//%s' % (str(userpic.user.id),newName)
return u'videos/%s/%s' % (str(userpic.user.id),newName)

# these are the images for the profile page
# image_1
# image_2
# image_3
# image_4
# image_5
# image_6
# Profile_image
# profile_image



# change name of image_One

class Images(models.Model):
image_id = models.BigAutoField(
auto_created=True,
Expand Down Expand Up @@ -91,10 +68,6 @@ class Videos(models.Model):
video = models.FileField(upload_to=get_uplaod_video_name)





# this contains all of the types of media that we can have
class Multimedia_type(models.Model):

multimedia_type_id = models.BigAutoField(
Expand All @@ -113,8 +86,7 @@ def __str__(self):
class Meta:
db_table = 'Multimedia_type'

# status multimedia of the multimedia
# ex. visible, hidden, deleted
# status multimedia of the multimedia, ex. visible, hidden, deleted
class Multimedia_status(models.Model):
multimedia_status_id = models.BigAutoField(
auto_created=True,
Expand Down Expand Up @@ -148,32 +120,6 @@ class Meta:
db_table = 'Format'


# imagen 1

# iimage 2

# iimage 3

# imagen_5

# iimage 5


# When updating I would have to image

# TODO: Validate the max amount permitted



'''
class Video:
multimedia_id
user_id

title = models.CharField(max_length=50)
video = models.Video('video/')
'''



# this is table is where we save all of our user multimedia files that are uploade
Expand All @@ -192,7 +138,6 @@ class Multimedia(models.Model):
verbose_name='user_id'
)


multimedia_type = models.ForeignKey(
Multimedia_type,
on_delete=models.CASCADE,
Expand All @@ -206,11 +151,8 @@ class Multimedia(models.Model):
)

url = models.CharField(max_length=200)

created_at = models.DateTimeField(auto_now_add=True)

description = models.CharField(max_length=200)

multimedia_status = models.ForeignKey(
Multimedia_status,
on_delete=models.CASCADE,
Expand Down
Loading