mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 03:21:05 +00:00
upload avatars (nonfunctional)
This commit is contained in:
parent
dae9b5c023
commit
5080de9c6b
8 changed files with 49 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 3.0.2 on 2020-01-28 04:47
|
# Generated by Django 3.0.2 on 2020-01-28 06:21
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import django.contrib.auth.models
|
import django.contrib.auth.models
|
||||||
|
@ -38,6 +38,7 @@ class Migration(migrations.Migration):
|
||||||
('actor', models.CharField(max_length=255)),
|
('actor', models.CharField(max_length=255)),
|
||||||
('local', models.BooleanField(default=True)),
|
('local', models.BooleanField(default=True)),
|
||||||
('localname', models.CharField(blank=True, max_length=255, null=True, unique=True)),
|
('localname', models.CharField(blank=True, max_length=255, null=True, unique=True)),
|
||||||
|
('avatar', models.ImageField(blank=True, null=True, upload_to='uploads/')),
|
||||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
('created_date', models.DateTimeField(auto_now_add=True)),
|
||||||
('updated_date', models.DateTimeField(auto_now=True)),
|
('updated_date', models.DateTimeField(auto_now=True)),
|
||||||
('followers', models.ManyToManyField(to=settings.AUTH_USER_MODEL)),
|
('followers', models.ManyToManyField(to=settings.AUTH_USER_MODEL)),
|
||||||
|
|
|
@ -21,6 +21,7 @@ class User(AbstractUser):
|
||||||
blank=True,
|
blank=True,
|
||||||
unique=True
|
unique=True
|
||||||
)
|
)
|
||||||
|
avatar = models.ImageField(upload_to='uploads/', blank=True, null=True)
|
||||||
# TODO: a field for if non-local users are readers or others
|
# TODO: a field for if non-local users are readers or others
|
||||||
followers = models.ManyToManyField('self', symmetrical=False)
|
followers = models.ManyToManyField('self', symmetrical=False)
|
||||||
created_date = models.DateTimeField(auto_now_add=True)
|
created_date = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
|
@ -128,3 +128,5 @@ USE_TZ = True
|
||||||
# https://docs.djangoproject.com/en/2.0/howto/static-files/
|
# https://docs.djangoproject.com/en/2.0/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
|
MEDIA_URL = '/images/'
|
||||||
|
MEDIA_ROOT = os.path.join(BASE_DIR, MEDIA_URL)
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
<div id="account">
|
<div id="account">
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<form name="logout" action="/logout/" method="post">
|
<form name="logout" action="/logout/" method="post">
|
||||||
Welcome, {{ request.user.username }}
|
Welcome, {% if request.user.localname %}{{ request.user.localname }}{% else %}{{ request.user.username }}{% endif %}
|
||||||
<input type="submit" value="Log out"></input>
|
<input type="submit" value="Log out"></input>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
<div id="main">
|
<div id="main">
|
||||||
<div class="user-profile">
|
<div class="user-profile">
|
||||||
<img class="user-pic" src="/static/images/profile.jpg">
|
<img class="user-pic" src="/static/images/profile.jpg">
|
||||||
<h1>{{ user.username }}</h1>
|
<h1>{% if user.localname %}{{ user.localname }}{% else %}{{ user.username }}{% endif %}</h1>
|
||||||
|
{% if is_self %}<a href="/user/{{ user.localname }}/edit">Edit profile</a>
|
||||||
<p>Since {{ user.created_date }}</p>
|
<p>Since {{ user.created_date }}</p>
|
||||||
|
{% endif %}
|
||||||
{% if not is_self %}
|
{% if not is_self %}
|
||||||
{% if not following %}
|
{% if not following %}
|
||||||
<form action="/follow/" method="post">
|
<form action="/follow/" method="post">
|
||||||
|
|
|
@ -15,7 +15,8 @@ Including another URLconf
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
from fedireads import federation, openlibrary, views
|
from fedireads import federation, views, settings
|
||||||
|
from django.conf.urls.static import static
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
@ -23,6 +24,7 @@ urlpatterns = [
|
||||||
path('login/', views.user_login),
|
path('login/', views.user_login),
|
||||||
path('logout/', views.user_logout),
|
path('logout/', views.user_logout),
|
||||||
path('user/<str:username>', views.user_profile),
|
path('user/<str:username>', views.user_profile),
|
||||||
|
path('user/<str:username>/edit/', views.user_profile_edit),
|
||||||
path('book/<str:book_identifier>', views.book_page),
|
path('book/<str:book_identifier>', views.book_page),
|
||||||
|
|
||||||
path('review/', views.review),
|
path('review/', views.review),
|
||||||
|
@ -30,9 +32,10 @@ urlpatterns = [
|
||||||
path('follow/', views.follow),
|
path('follow/', views.follow),
|
||||||
path('unfollow/', views.unfollow),
|
path('unfollow/', views.unfollow),
|
||||||
path('search/', views.search),
|
path('search/', views.search),
|
||||||
|
path('upload-avatar/', views.upload_avatar),
|
||||||
|
|
||||||
path('api/u/<str:username>', federation.get_actor),
|
path('api/u/<str:username>', federation.get_actor),
|
||||||
path('api/u/<str:username>/inbox', federation.inbox),
|
path('api/u/<str:username>/inbox', federation.inbox),
|
||||||
path('api/u/<str:username>/outbox', federation.outbox),
|
path('api/u/<str:username>/outbox', federation.outbox),
|
||||||
path('.well-known/webfinger', federation.webfinger),
|
path('.well-known/webfinger', federation.webfinger),
|
||||||
]
|
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|
|
@ -5,6 +5,7 @@ from django.db.models import Avg, FilteredRelation, Q
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from django.http import HttpResponseNotFound
|
||||||
from fedireads import models, openlibrary
|
from fedireads import models, openlibrary
|
||||||
from fedireads import federation as api
|
from fedireads import federation as api
|
||||||
from fedireads.settings import DOMAIN
|
from fedireads.settings import DOMAIN
|
||||||
|
@ -67,7 +68,14 @@ def user_logout(request):
|
||||||
@login_required
|
@login_required
|
||||||
def user_profile(request, username):
|
def user_profile(request, username):
|
||||||
''' profile page for a user '''
|
''' profile page for a user '''
|
||||||
user = models.User.objects.get(username=username)
|
try:
|
||||||
|
user = models.User.objects.get(localname=username)
|
||||||
|
except models.User.DoesNotExist:
|
||||||
|
try:
|
||||||
|
user = models.User.objects.get(username=username)
|
||||||
|
except models.User.DoesNotExist:
|
||||||
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
books = models.Book.objects.filter(shelves__user=user)
|
books = models.Book.objects.filter(shelves__user=user)
|
||||||
data = {
|
data = {
|
||||||
'user': user,
|
'user': user,
|
||||||
|
@ -77,6 +85,31 @@ def user_profile(request, username):
|
||||||
return TemplateResponse(request, 'user.html', data)
|
return TemplateResponse(request, 'user.html', data)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def user_profile_edit(request, username):
|
||||||
|
''' profile page for a user '''
|
||||||
|
try:
|
||||||
|
user = models.User.objects.get(localname=username)
|
||||||
|
except models.User.DoesNotExist:
|
||||||
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'user': user,
|
||||||
|
}
|
||||||
|
return TemplateResponse(request, 'edit_user.html', data)
|
||||||
|
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@login_required
|
||||||
|
def upload_avatar(request):
|
||||||
|
''' les get fancy with images '''
|
||||||
|
if not request.method == 'POST':
|
||||||
|
return redirect('/')
|
||||||
|
request.user.avatar = request.FILES['avatar']
|
||||||
|
request.user.save()
|
||||||
|
return redirect('/user/%s' % request.user.localname)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def book_page(request, book_identifier):
|
def book_page(request, book_identifier):
|
||||||
''' info about a book '''
|
''' info about a book '''
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
Django==3.0.2
|
Django==3.0.2
|
||||||
|
Pillow-7.0.0
|
||||||
psycopg2==2.8.4
|
psycopg2==2.8.4
|
||||||
pycryptodome==3.9.4
|
pycryptodome==3.9.4
|
||||||
requests==2.22.0
|
requests==2.22.0
|
||||||
|
|
Loading…
Reference in a new issue