Commit ff5f1b2d authored by onny's avatar onny
Browse files

login required for view

parent f1101d2e
......@@ -16,7 +16,7 @@ Including another URLconf
from django.conf.urls import url, include
from django.contrib import admin
from rest_framework import routers
from openart.views import index_page, add_page, artists_page, projects_page, entries_page, artist_page
from openart.views import index_page, add_page, artists_page, projects_page, entries_page, artist_page, login
from openart.views import ArtistViewSet, ProjectViewSet, EntryViewSet
# Routers provide an easy way of automatically determining the URL conf.
......@@ -34,4 +34,5 @@ urlpatterns = [
url(r'^projects/', projects_page),
url(r'^entries/', entries_page),
url(r'^api/', include(router.urls)),
url(r'^login/$', login)
]
......@@ -29,8 +29,8 @@ class Artist(models.Model):
while Artist.objects.filter(name=self.name).exists():
self.name = re.sub(' \(.*?\)','', self.name) + f" ({count})"
count = count + 1
slug = self.name.lower().replace(' ','-')
self.slug = re.sub('[()]','', slug) # FIXME
self.slug = self.name.lower().replace(' ','-')
self.slug = re.sub('[()]','', self.slug) # FIXME
print(self.slug)
super(Artist, self).save(*args, **kwargs)
......
......@@ -2,14 +2,11 @@ from .models import Artist, Project, Entry
from rest_framework import serializers
class ArtistSerializer(serializers.ModelSerializer):
slug = serializers.SerializerMethodField(read_only=True)
def get_slug(self, obj):
name = obj.name
name = name.replace(" ","-")
name = name.lower()
return name
class Meta:
model = Artist
fields = ('id', 'name')
class ArtistReadSerializer(serializers.ModelSerializer):
class Meta:
model = Artist
fields = ('id', 'name', 'slug')
......
......@@ -2,14 +2,17 @@ from django.template.response import TemplateResponse
from django.http import HttpResponse
from .models import Artist, Project, Entry
from rest_framework import viewsets
from .serializers import ArtistSerializer, ProjectSerializer, ProjectReadSerializer, EntrySerializer, EntryReadSerializer
from .serializers import ArtistSerializer, ArtistReadSerializer, ProjectSerializer, ProjectReadSerializer, EntrySerializer, EntryReadSerializer
from .forms import ArtistForm, ProjectForm, EntryForm, MediaForm
from django.conf import settings
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.decorators import login_required
def index_page(request):
html = TemplateResponse(request, 'index.html')
return HttpResponse(html.render())
@login_required
def add_page(request):
if request.method == 'POST':
......@@ -57,11 +60,12 @@ def entries_page(request):
return HttpResponse(html.render())
class ArtistViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows artists to be viewed or edited.
"""
queryset = Artist.objects.all()
serializer_class = ArtistSerializer
def get_serializer_class(self):
if self.request.method in ['GET']:
return ArtistReadSerializer
return ArtistSerializer
class ProjectViewSet(viewsets.ModelViewSet):
queryset = Project.objects.all()
......@@ -78,3 +82,19 @@ class EntryViewSet(viewsets.ModelViewSet):
if self.request.method in ['GET']:
return EntryReadSerializer
return EntrySerializer
def login(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')
user = authenticate(username=username, password=raw_password)
login(request, user)
return redirect('home')
else:
form = UserCreationForm()
html = TemplateResponse(request, 'login.html', {'form': form})
return HttpResponse(html.render())
......@@ -3,7 +3,7 @@ body {
padding: 0 !important;
}
article {
content {
min-height: 100vh;
display: grid;
grid-template-rows: auto 1fr auto;
......@@ -11,7 +11,6 @@ article {
}
header {
padding: 1rem;
border-bottom: 1px solid;
border-color: #d6d6d6;
......@@ -23,13 +22,47 @@ header {
header > div {
margin: 0 auto 0 auto;
width: 90%;
width: 80%;
display: flex;
justify-content: left;
align-items: center;
border-left: 1px solid;
border-right: 1px solid;
border-color: #d6d6d6;
}
.logo {
float: left;
padding: 10px 30px;
border-right: 1px solid;
border-color: #d6d6d6;
}
.search {
padding: 10px 30px;
border-right: 1px solid;
border-color: #d6d6d6;
flex: 1;
}
.lang {
padding: 10px 30px;
border-right: 1px solid;
border-color: #d6d6d6;
}
.login {
padding: 10px 30px;
}
input {
width: 100%;
}
#sidebar {
padding: 1rem;
margin-left: 70px;
margin-left: 140px;
grid-column-start: 2;
grid-column-end: 2;
grid-row-start: 2;
......@@ -38,7 +71,7 @@ header > div {
main {
padding: 1rem;
padding-left: 60px;
padding-left: 150px;
grid-column-start: 3;
......@@ -60,7 +93,7 @@ footer {
footer > div {
margin: 0 auto 0 auto;
width: 90%;
width: 80%;
}
.flex-container {
......
......@@ -87,7 +87,7 @@ var demo = new Vue({
});
},
addMedia: function () {
const file = event.target.files[0]
/* const file = event.target.files[0]
axios.post('/add', file, {
headers: {
'Content-Type': 'multipart/form-data'
......@@ -98,8 +98,8 @@ var demo = new Vue({
})
.catch(error => {
print_message('.media', 'error', 'Error while uploading media, please report');
});
};
}); */
},
removeArtist: function (index) {
axios
.delete('http://127.0.0.1:8000/api/artist/'.concat(this.artist[index].id));
......
......@@ -10,12 +10,23 @@
</head>
<body>
<article id="app">
<content id="app">
<header>
<div>
<b><a href="/">[[ apptitle ]]</a></b>
<br>
<small>Tech demo 0.1</small>
<div class='logo'>
<b><a href="/">[[ apptitle ]]</a></b>
<br>
<small>Tech demo 0.1</small>
</div>
<div class='search'>
<input type='text'>
</div>
<div class='lang'>
<b>EN</b>
</div>
<div class='login'>
<b><a href='/login'>SIGN IN</a></b>
</div>
</div>
</header>
<div id="sidebar">
......@@ -35,7 +46,7 @@
<small>Tech demo 0.1</small>
</div>
</footer>
</article>
</content>
<!-- <script type="text/javascript" src="{% static 'js/vue-2.6.10.min.js' %}"></script> -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment