Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project creation feature #4

Merged
merged 7 commits into from
Dec 17, 2020
Merged
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
3 changes: 2 additions & 1 deletion zubhub_backend/zubhub/APIS/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
urlpatterns = [
path('rest-auth/', include('rest_auth.urls')),
path('rest-auth/registration/',include('rest_auth.registration.urls')),
path('creators/', include('creators.urls', namespace="creators"))
path('creators/', include('creators.urls', namespace="creators")),
path('projects/', include('projects.urls', namespace="projects"))
]
3 changes: 1 addition & 2 deletions zubhub_backend/zubhub/creators/adapter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from allauth.account.adapter import DefaultAccountAdapter
from .models import Location

class CustomAccountAdapter(DefaultAccountAdapter):

Expand All @@ -11,4 +10,4 @@ def save_user(self, request, user, form, commit=False):
creator.dateOfBirth = data.get('dateOfBirth')
creator.location = location
creator.save()
return creator
return creator
1 change: 0 additions & 1 deletion zubhub_backend/zubhub/creators/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

Creator = get_user_model()


class CreatorSerializer(serializers.ModelSerializer):

class Meta:
Expand Down
1 change: 0 additions & 1 deletion zubhub_backend/zubhub/creators/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
path('locations/', LocationListAPIView.as_view(), name='location_list'),
path('<str:username>/', UserProfileAPIView.as_view(), name='user_profile')
]

7 changes: 3 additions & 4 deletions zubhub_backend/zubhub/creators/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from .permissions import IsOwner
from .models import Location


Creator = get_user_model()


Expand All @@ -23,14 +22,14 @@ class UserProfileAPIView(RetrieveAPIView):
lookup_field = "username"
permission_classes = [AllowAny]


class EditCreatorAPIView(UpdateAPIView):
queryset = Creator.objects.all()
serializer_class = CreatorSerializer
permission_classes = [IsAuthenticated, IsOwner]

def patch(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)
def patch(self,request,*args,**kwargs):
return self.update(request,*args,**kwargs)

def get_object(self):
queryset = self.filter_queryset(self.get_queryset())
Expand Down
Empty file.
7 changes: 7 additions & 0 deletions zubhub_backend/zubhub/projects/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from .models import Project

# Register your models here.


admin.site.register(Project)
5 changes: 5 additions & 0 deletions zubhub_backend/zubhub/projects/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ProjectsConfig(AppConfig):
name = 'projects'
35 changes: 35 additions & 0 deletions zubhub_backend/zubhub/projects/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.db import models
from django.contrib.auth import get_user_model
from django.utils.text import slugify
import uuid
from math import floor


Creator = get_user_model()


class Project(models.Model):
id = models.UUIDField(
primary_key=True, default=uuid.uuid4, editable=False, unique=True)
creator = models.ForeignKey(
Creator, on_delete=models.CASCADE, related_name="creators")
title = models.CharField(max_length=100)
description = models.CharField(max_length=10000, blank=True, null=True)
video = models.URLField(max_length=1000, blank=True, null=True)
materials_used = models.CharField(max_length=10000)
slug = models.SlugField(unique=True)
created_on = models.DateTimeField(auto_now=True)

def save(self, *args, **kwargs):
if(self.video.find("youtube.com") != -1):
self.video = "embed/".join(self.video.split("watch?v="))
if self.slug:
pass
else:
uid = str(uuid.uuid4())
uid = uid[0: floor(len(uid)/2)]
self.slug = slugify(self.title) + "-" + uid
super().save(*args, **kwargs)

def __str__(self):
return self.title
15 changes: 15 additions & 0 deletions zubhub_backend/zubhub/projects/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers
from .models import Project
from creators.serializers import CreatorSerializer

class ProjectCreateSerializer(serializers.ModelSerializer):
creator = CreatorSerializer(read_only=True)
class Meta:
model = Project
fields = [
"creator",
"title",
"description",
"video",
"materials_used"
]
3 changes: 3 additions & 0 deletions zubhub_backend/zubhub/projects/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
8 changes: 8 additions & 0 deletions zubhub_backend/zubhub/projects/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from .views import ProjectCreateAPIView

app_name = "projects"

urlpatterns = [
path('create/', ProjectCreateAPIView.as_view(), name = 'create_project')
]
13 changes: 13 additions & 0 deletions zubhub_backend/zubhub/projects/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from rest_framework.generics import ListCreateAPIView
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from .models import Project
from .serializers import ProjectCreateSerializer


class ProjectCreateAPIView(ListCreateAPIView):
queryset = Project.objects.all()
serializer_class = ProjectCreateSerializer
permission_classes = [IsAuthenticatedOrReadOnly]

def perform_create(self, serializer):
serializer.save(creator=self.request.user)
3 changes: 2 additions & 1 deletion zubhub_backend/zubhub/zubhub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
'crispy_forms',
'debug_toolbar',
'APIS.apps.ApisConfig',
'creators.apps.CreatorsConfig'
'creators.apps.CreatorsConfig',
'projects.apps.ProjectsConfig'
]


Expand Down
1 change: 1 addition & 0 deletions zubhub_frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

debug.log
package-lock.json

Expand Down
9 changes: 5 additions & 4 deletions zubhub_frontend/zubhub/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import PasswordReset from './components/pages/user_auth/PasswordReset';
import PasswordResetConfirm from './components/pages/user_auth/PasswordResetConfirm';
import EmailConfirm from './components/pages/user_auth/EmailConfirm';
import Profile from './components/pages/profile/Profile';
import CreateProject from './components/pages/projects/projects_components/CreateProject';

// import Artists from './components/pages/artists/Artists';
// import Artist from './components/pages/artists/Artist';
Expand All @@ -29,7 +30,6 @@ import Profile from './components/pages/profile/Profile';
// import Cart from './components/pages/cart/Cart';

class App extends Component {


render(){
let apiProps = this.props;
Expand Down Expand Up @@ -82,19 +82,20 @@ return(
</PageWrapper>
)}/>

<Route path="/profile/:username"
<Route path="/profile"
render={props=>(
<PageWrapper>
<Profile {...Object.assign({}, props, apiProps)}/>
</PageWrapper>
)}/>

<Route path="/profile"
<Route path="/projects/create"
render={props=>(
<PageWrapper>
<Profile {...Object.assign({}, props, apiProps)}/>
<CreateProject {...Object.assign({}, props, apiProps)}/>
</PageWrapper>
)}/>

</Switch>
</Router>
);
Expand Down
6 changes: 2 additions & 4 deletions zubhub_frontend/zubhub/src/components/PageWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { withAPI } from './api';

import { ToastContainer, toast } from 'react-toastify';

import * as AuthActions from '../store/actions/authActions'

import * as AuthActions from '../store/actions/authActions';

import unstructuredLogo from '../assets/images/logos/unstructured-logo.png';
import logo from '../assets/images/logos/logo.png';
Expand Down Expand Up @@ -63,8 +62,7 @@ return (
</>
:
<>
<Link to={`/profile/${this.props.auth.username}`}>
<img src={`https://robohash.org/${this.props.auth.username}`} className="profile_image" aria-label="creator profile"/></Link>
<Link to="/profile"><img src={`https://robohash.org/${this.props.auth.username}`} className="profile_image" aria-label="creator profile"/></Link>
<Link className="btn btn-danger" onClick={this.logout}>Logout</Link>
</>
}
Expand Down
1 change: 1 addition & 0 deletions zubhub_frontend/zubhub/src/components/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ get_auth_user=(token)=>{
return this.request({url, token})
.then(res=>res.json())
}

/********************************************************************/


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React,{Component} from 'react';
import {connect} from 'react-redux';


class Home extends Component{
constructor(props){
super(props);
Expand Down
10 changes: 10 additions & 0 deletions zubhub_frontend/zubhub/src/components/pages/profile/Profile.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React,{Component} from 'react';
import {connect} from 'react-redux';
import { ToastContainer, toast } from 'react-toastify';
import { Link, withRouter } from 'react-router-dom';
import EditProfile from './profile_components/EditProfile';
import * as AuthActions from '../../../store/actions/authActions';

Expand Down Expand Up @@ -41,6 +42,8 @@ class Profile extends Component{

render(){
let {profile, loading, readOnly} = this.state;

if(this.props.auth.token){

if(loading){
return <div>
Expand All @@ -54,6 +57,8 @@ class Profile extends Component{
:
<EditProfile profile={profile} setProfile={value=>this.setProfile(value)}
setReadOnly={value=>this.setReadOnly(value)} {...this.props} />

<button><Link to="/projects/create">Create Project</Link></button>
:
null
}
Expand All @@ -63,6 +68,7 @@ class Profile extends Component{
<div>Username: {profile.username}</div>



<div>{this.props.auth.username === profile.username ? `Email: ${profile.email}` : null}</div>

<div>{this.props.auth.username === profile.username ? `Date Of Birth: ${profile.dateOfBirth}` : null}</div>
Expand All @@ -76,6 +82,10 @@ class Profile extends Component{
Couldn't fetch profile, try again later
</div>
}
} else {
return <div>You are not logged in. Click on sign in to get started</div>
}

}
}

Expand Down
Loading