add login, logout, signup, delete account, file listing, file upload(partial)
closed kairos03/2018-1-d.cloud#4 closed kairos03/2018-1-d.cloud#5 closed kairos03/2018-1-d.cloud#6 closed kairos03/2018-1-d.cloud#7 closed kairos03/2018-1-d.cloud#10 kairos03/2018-1-d.cloud#8
Showing
14 changed files
with
36 additions
and
106 deletions
... | @@ -4,9 +4,11 @@ from django.contrib.auth import views | ... | @@ -4,9 +4,11 @@ from django.contrib.auth import views |
4 | 4 | ||
5 | urlpatterns = [ | 5 | urlpatterns = [ |
6 | url(r'^admin/', admin.site.urls), | 6 | url(r'^admin/', admin.site.urls), |
7 | - url(r'^accounts/login/$', views.login, name='login'), | ||
8 | - url(r'^accounts/logout/$', views.logout, name='logout', kwargs={'next_page': '/'}), | ||
9 | url(r'^restapi/', include('restful.urls')), | 7 | url(r'^restapi/', include('restful.urls')), |
10 | url(r'^', include('website.urls')), | 8 | url(r'^', include('website.urls')), |
9 | + | ||
10 | + url(r'^accounts/login/$', views.login, name='login'), | ||
11 | + url(r'^accounts/logout/$', views.logout, name='logout', kwargs={'next_page': '/'}), | ||
12 | + | ||
11 | ] | 13 | ] |
12 | 14 | ... | ... |
1 | from django.contrib import admin | 1 | from django.contrib import admin |
2 | -from website.models import Post | 2 | +# from website.models import Post |
3 | 3 | ||
4 | -admin.site.register(Post) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
4 | +# admin.site.register(Post) | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | -from django.contrib.auth import login, authenticate | 1 | +from django.contrib.auth import login, authenticate, logout |
2 | from django.contrib.auth.forms import UserCreationForm | 2 | from django.contrib.auth.forms import UserCreationForm |
3 | from django.shortcuts import render, redirect | 3 | from django.shortcuts import render, redirect |
4 | from django.contrib.auth.decorators import login_required | 4 | from django.contrib.auth.decorators import login_required |
... | @@ -32,5 +32,6 @@ def delete_account(request): | ... | @@ -32,5 +32,6 @@ def delete_account(request): |
32 | def delete_account_success(request): | 32 | def delete_account_success(request): |
33 | if request.method == 'GET': | 33 | if request.method == 'GET': |
34 | # TODO Add delete account | 34 | # TODO Add delete account |
35 | + logout(request) | ||
35 | return render(request, 'registration/delete_account_success.html') | 36 | return render(request, 'registration/delete_account_success.html') |
36 | 37 | ... | ... |
1 | from django import forms | 1 | from django import forms |
2 | -from website.models import Post | ||
3 | 2 | ||
4 | -class PostForm(forms.ModelForm): | ||
5 | - class Meta: | ||
6 | - model = Post | ||
7 | - fields = ('title', 'text') | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
3 | +# class PostForm(forms.ModelForm): | ||
4 | +# class Meta: | ||
5 | +# model = Post | ||
6 | +# fields = ('title', 'text') | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | -{% load staticfiles %} | ||
2 | -<html> | ||
3 | - <head> | ||
4 | - <title>Django Girls blog</title> | ||
5 | - <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | ||
6 | - <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"> | ||
7 | - <link href="//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css"> | ||
8 | - <link rel="stylesheet" href="{% static 'css/posts.css' %}"> | ||
9 | - </head> | ||
10 | - <body> | ||
11 | - <div class="page-header"> | ||
12 | - {% if user.is_authenticated %} | ||
13 | - <a href="{% url 'post_new' %}" class="top-menu"><span class="glyphicon glyphicon-plus"></span></a> | ||
14 | - <a href="{% url 'post_draft_list' %}" class="top-menu"><span class="glyphicon glyphicon-edit"></span></a> | ||
15 | - <p class="top-menu">Hello {{ user.username }} <small>(<a href="{% url 'logout' %}">Log out</a>)</small></p> | ||
16 | - {% else %} | ||
17 | - <a href="{% url 'login' %}" class="top-menu"><span class="glyphicon glyphicon-lock"></span></a> | ||
18 | - {% endif %} | ||
19 | - <h1><a href="/">Django Girls Blog</a></h1> | ||
20 | - </div> | ||
21 | - <div class="content container"> | ||
22 | - <div class="row"> | ||
23 | - <div class="col-md-8"> | ||
24 | - {% block content %} | ||
25 | - {% endblock %} | ||
26 | - </div> | ||
27 | - </div> | ||
28 | - </div> | ||
29 | - </body> | ||
30 | -</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
7 | {% if user.is_authenticated %} | 7 | {% if user.is_authenticated %} |
8 | <p class="top-menu">Hello {{ user.username }} <small>(<a href="{% url 'logout' %}">Log out</a>)</small></p> | 8 | <p class="top-menu">Hello {{ user.username }} <small>(<a href="{% url 'logout' %}">Log out</a>)</small></p> |
9 | {% else %} | 9 | {% else %} |
10 | - <a href="{% url 'login' %}" class="top-menu"><span class="glyphicon glyphicon-lock"></span></a> | 10 | + <a href="{% url 'login' %}" class="top-menu">Log in<span class="glyphicon glyphicon-lock"></span></a> |
11 | {% endif %} | 11 | {% endif %} |
12 | <h1><a href="/">D.cloud</a></h1> | 12 | <h1><a href="/">D.cloud</a></h1> |
13 | </div> | 13 | </div> | ... | ... |
... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
2 | 2 | ||
3 | {% block content %} | 3 | {% block content %} |
4 | {% for file in files %} | 4 | {% for file in files %} |
5 | - <h1>{{file.title}}</h1> | 5 | + <h1>{{file.name}}</h1> |
6 | - <p>{{file.object_key}}</p> | 6 | + <p>{{file.type}}</p> |
7 | {% endfor %} | 7 | {% endfor %} |
8 | {% endblock %} | 8 | {% endblock %} |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
dcloud/website/templates/website/home.html
0 → 100644
1 | -{% extends 'website/base.html' %} | ||
2 | - | ||
3 | -{% block content %} | ||
4 | - | ||
5 | - <div class="post"> | ||
6 | - {% if post.published_date %} | ||
7 | - <div class="date"> | ||
8 | - {{ post.published_date }} | ||
9 | - </div> | ||
10 | - {% else %} | ||
11 | - <a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a> | ||
12 | - {% endif %} | ||
13 | - {% if user.is_authenticated %} | ||
14 | - <a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-pencil"></span></a> | ||
15 | - {% endif %} | ||
16 | - <h1>{{ post.title }}</h1> | ||
17 | - <p>{{ post.text|linebreaksbr }}</p> | ||
18 | - </div> | ||
19 | -{% endblock %} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | -{% extends 'website/base.html' %} | ||
2 | - | ||
3 | -{% block content %} | ||
4 | - {% for post in posts %} | ||
5 | - <div class="post"> | ||
6 | - <p class="date">created: {{ post.created_date|date:'d-m-Y' }}</p> | ||
7 | - <h1><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></h1> | ||
8 | - <p>{{ post.text|truncatechars:200 }}</p> | ||
9 | - </div> | ||
10 | - {% endfor %} | ||
11 | -{% endblock %} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | -{% extends 'website/base.html' %} | ||
2 | - | ||
3 | -{% block content %} | ||
4 | - <h1>New post</h1> | ||
5 | - <form method="POST" class="post-form">{% csrf_token %} | ||
6 | - {{ form.as_p }} | ||
7 | - <button type="submit" class="save btn btn-default">Save</button> | ||
8 | - </form> | ||
9 | -{% endblock %} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | -{% extends 'website/base.html' %} | ||
2 | - | ||
3 | -{% block content %} | ||
4 | - {% for post in posts %} | ||
5 | - <div class="post"> | ||
6 | - <div class="date"> | ||
7 | - <p>published: {{ post.published_date }}</p> | ||
8 | - </div> | ||
9 | - <h1> | ||
10 | - <h1><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></h1> | ||
11 | - </h1> | ||
12 | - <p>{{ post.text|linebreaksbr }}</p> | ||
13 | - </div> | ||
14 | - {% endfor %} | ||
15 | -{% endblock %} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | from django.conf.urls import url | 1 | from django.conf.urls import url |
2 | -from website import views, auth_views | ||
3 | from django.shortcuts import redirect | 2 | from django.shortcuts import redirect |
3 | +from website import views, auth_views | ||
4 | 4 | ||
5 | urlpatterns = [ | 5 | urlpatterns = [ |
6 | - # blog | 6 | + |
7 | - url(r'^$', redirect('login')), | ||
8 | - url(r'^files/', views.file_list, name='file_list'), | ||
9 | url(r'^accounts/signup/$', auth_views.signup, name='signup'), | 7 | url(r'^accounts/signup/$', auth_views.signup, name='signup'), |
10 | url(r'^accounts/delete_account/$', auth_views.delete_account, name='delete_account'), | 8 | url(r'^accounts/delete_account/$', auth_views.delete_account, name='delete_account'), |
11 | url(r'^accounts/delete_account_success/$', auth_views.delete_account_success, name='delete_account_success'), | 9 | url(r'^accounts/delete_account_success/$', auth_views.delete_account_success, name='delete_account_success'), |
10 | + | ||
11 | + # blog | ||
12 | + url(r'^$', views.home), | ||
13 | + url(r'^files/', views.file_list, name='file_list'), | ||
12 | ] | 14 | ] |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | -from django.shortcuts import render, get_object_or_404, redirect | 1 | +from django.shortcuts import render, get_object_or_404, redirect, Http404 |
2 | from django.utils import timezone | 2 | from django.utils import timezone |
3 | from django.contrib.auth.decorators import login_required | 3 | from django.contrib.auth.decorators import login_required |
4 | -from website.models import Post | ||
5 | from restful.models import File | 4 | from restful.models import File |
6 | -from website.forms import PostForm | 5 | +import requests |
6 | + | ||
7 | + | ||
8 | +def home(request): | ||
9 | + return render(request, 'website/home.html') | ||
10 | + | ||
7 | 11 | ||
8 | @login_required | 12 | @login_required |
9 | def file_list(request): | 13 | def file_list(request): |
10 | - files = File.objects.all() | 14 | + files = requests.get('http://localhost:8000/restapi/files') |
11 | - return render(request, 'website/file_list.html', {'files': files}) | 15 | + files = files.json() |
16 | + return render(request, 'website/file_list.html', files) | ... | ... |
-
Please register or login to post a comment