Compare commits
No commits in common. "c178556a2ed3a981b47a0b2423908d564d6bfea1" and "08093627c9fa384690056f6f658fb7c351bec780" have entirely different histories.
c178556a2e
...
08093627c9
@ -1,7 +1,6 @@
|
|||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from rest_framework import permissions, status
|
from rest_framework import permissions, status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from django.contrib.auth import logout
|
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from rest_framework.authentication import SessionAuthentication
|
from rest_framework.authentication import SessionAuthentication
|
||||||
|
|
||||||
@ -17,5 +16,4 @@ class DeleteView(APIView):
|
|||||||
if (request.user.check_password(password) == False):
|
if (request.user.check_password(password) == False):
|
||||||
return Response({"password": ["Password wrong."]})
|
return Response({"password": ["Password wrong."]})
|
||||||
request.user.delete()
|
request.user.delete()
|
||||||
logout(request)
|
|
||||||
return Response("user deleted", status=status.HTTP_200_OK)
|
return Response("user deleted", status=status.HTTP_200_OK)
|
@ -1,17 +0,0 @@
|
|||||||
#app img
|
|
||||||
{
|
|
||||||
max-height: 100px;
|
|
||||||
max-width: 100px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app ul
|
|
||||||
{
|
|
||||||
margin: 5px 0 0 0;
|
|
||||||
padding: 0 0 0 0;
|
|
||||||
list-style-type: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app li
|
|
||||||
{
|
|
||||||
margin: 10px 10px 0 0;
|
|
||||||
}
|
|
@ -1,57 +1,35 @@
|
|||||||
import AbstractView from "./AbstractView.js";
|
import AbstractAuthentifiedView from "./AbstractAuthentifiedView.js";
|
||||||
import {client} from "../index.js";
|
import {client} from "../index.js";
|
||||||
|
|
||||||
export default class extends AbstractView {
|
export default class extends AbstractAuthentifiedView {
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
super(params, "Search");
|
super(params, "Search");
|
||||||
}
|
}
|
||||||
|
|
||||||
async postInit() {
|
async postInit() {
|
||||||
|
let profiles = await client.profiles.all();
|
||||||
|
console.log(profiles);
|
||||||
|
let users = ["cramptéMan", "cacaMan", "chatteWomen"]
|
||||||
|
|
||||||
let search = document.getElementById("form");
|
let list_users = document.getElementById('list_users');
|
||||||
search.addEventListener("input", this.users)
|
for (const user of users) {
|
||||||
|
var new_user = document.createElement("li");
|
||||||
this.users();
|
new_user.appendChild(document.createTextNode(user));
|
||||||
|
list_users.appendChild(new_user);
|
||||||
|
}
|
||||||
|
console.log(list_users);
|
||||||
}
|
}
|
||||||
|
|
||||||
async users() {
|
async leavePage() {
|
||||||
|
|
||||||
let search = document.getElementById("form").value;
|
|
||||||
|
|
||||||
|
|
||||||
let users = await client.profiles.all();
|
|
||||||
let list_users = document.getElementById('list_users');
|
|
||||||
list_users.innerHTML = "";
|
|
||||||
|
|
||||||
users.filter(user => user.username.startsWith(search) == true).forEach((user) => {
|
|
||||||
var new_user = document.createElement("li");
|
|
||||||
|
|
||||||
// username
|
|
||||||
let username = document.createElement("a");
|
|
||||||
username.href = `/profiles/${user.user_id}`;
|
|
||||||
username.appendChild(document.createTextNode(user.username));
|
|
||||||
new_user.appendChild(username);
|
|
||||||
|
|
||||||
// break line
|
|
||||||
new_user.appendChild(document.createElement("br"));
|
|
||||||
|
|
||||||
// avatar
|
|
||||||
var img = document.createElement("img");
|
|
||||||
img.src = user.avatar_url;
|
|
||||||
new_user.appendChild(img);
|
|
||||||
|
|
||||||
list_users.appendChild(new_user);
|
|
||||||
});
|
|
||||||
console.log(list_users);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHtml() {
|
async getHtml() {
|
||||||
return `
|
return `
|
||||||
<link rel="stylesheet" href="/static/css/search.css">
|
<h1>Search</h1>
|
||||||
|
|
||||||
<input id="form" type="text" name="message" placeholder="userbozo"/>
|
<form id="form">
|
||||||
|
<input type="text" name="message" placeholder="user name to crampte"/>
|
||||||
|
</form>
|
||||||
|
|
||||||
<div id="users">
|
<div id="users">
|
||||||
<ul id="list_users">
|
<ul id="list_users">
|
||||||
|
@ -11,7 +11,7 @@ def upload_to(instance, filename: str):
|
|||||||
# Create your models here.
|
# Create your models here.
|
||||||
class ProfileModel(models.Model):
|
class ProfileModel(models.Model):
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
avatar_url = models.ImageField(upload_to=upload_to, default="./profiles/static/avatars/default.avif") #blank=True, null=True)
|
avatar_url = models.ImageField(upload_to=upload_to, default="../static/avatars/default.avif") #blank=True, null=True)
|
||||||
|
|
||||||
@receiver(post_save, sender=User)
|
@receiver(post_save, sender=User)
|
||||||
def on_user_created(sender, instance, created, **kwargs):
|
def on_user_created(sender, instance, created, **kwargs):
|
||||||
|
@ -38,7 +38,7 @@ class ProfileViewSet(viewsets.ModelViewSet):
|
|||||||
profile: ProfileModel = ProfileModel.objects.get(pk=self.request.user.pk)
|
profile: ProfileModel = ProfileModel.objects.get(pk=self.request.user.pk)
|
||||||
avatar = self.request.data.get("file", None)
|
avatar = self.request.data.get("file", None)
|
||||||
if (avatar is not None):
|
if (avatar is not None):
|
||||||
if (profile.avatar_url.name != "./profiles/static/avatars/default.avif"):
|
if (profile.avatar_url.name != "default.avif"):
|
||||||
profile.avatar_url.storage.delete(profile.avatar_url.name)
|
profile.avatar_url.storage.delete(profile.avatar_url.name)
|
||||||
profile.avatar_url = avatar
|
profile.avatar_url = avatar
|
||||||
profile.save()
|
profile.save()
|
Loading…
Reference in New Issue
Block a user