add: profiles.all()
This commit is contained in:
parent
54afa8aae5
commit
0edcd97f94
@ -1,5 +1,6 @@
|
|||||||
import { Account } from "./account.js";
|
import { Account } from "./account.js";
|
||||||
import { Profile } from "./profile.js";
|
import { Profile } from "./profile.js";
|
||||||
|
import { Profiles } from "./profiles.js";
|
||||||
|
|
||||||
function getCookie(name)
|
function getCookie(name)
|
||||||
{
|
{
|
||||||
@ -17,6 +18,7 @@ class Client
|
|||||||
{
|
{
|
||||||
this._url = url;
|
this._url = url;
|
||||||
this.account = new Account(this);
|
this.account = new Account(this);
|
||||||
|
this.profiles = new Profiles(this);
|
||||||
this._logged = undefined;
|
this._logged = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
class Profile
|
class Profile
|
||||||
{
|
{
|
||||||
constructor (client)
|
constructor (client, username = undefined, avatar_url = undefined, user_id = undefined)
|
||||||
{
|
{
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.username = undefined;
|
this.username = username;
|
||||||
this.avatar_url = undefined
|
this.avatar_url = avatar_url
|
||||||
|
this.user_id = user_id
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(id)
|
async init(id)
|
||||||
|
23
frontend/static/js/api/profiles.js
Normal file
23
frontend/static/js/api/profiles.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { Profile } from "./profile.js";
|
||||||
|
|
||||||
|
class Profiles
|
||||||
|
{
|
||||||
|
constructor (client)
|
||||||
|
{
|
||||||
|
this.client = client
|
||||||
|
}
|
||||||
|
|
||||||
|
async all()
|
||||||
|
{
|
||||||
|
let response = await this.client._get("/api/profiles/");
|
||||||
|
let response_data = await response.json();
|
||||||
|
|
||||||
|
let profiles = []
|
||||||
|
response_data.forEach((profile) => {
|
||||||
|
profiles.push(new Profile(this.client, profile.username, profile.avatar_url, profile.user_id))
|
||||||
|
});
|
||||||
|
console.log(profiles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {Profiles}
|
@ -8,4 +8,4 @@ class ProfileSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ProfileModel
|
model = ProfileModel
|
||||||
fields = ["username", "avatar_url"]
|
fields = ["username", "avatar_url", "user_id"]
|
@ -6,5 +6,6 @@ from . import viewsets
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("<int:pk>", viewsets.ProfileViewSet.as_view({'get': 'retrieve', 'patch': 'partial_update'}), name="profile_page"),
|
path("<int:pk>", viewsets.ProfileViewSet.as_view({'get': 'retrieve', 'patch': 'partial_update'}), name="profile_page"),
|
||||||
|
path("", viewsets.ProfileViewSet.as_view({'get': 'list'}), name="profiles_list"),
|
||||||
#path("me", viewsets.ProfileViewSet.as_view(), name="my_profile_page"),
|
#path("me", viewsets.ProfileViewSet.as_view(), name="my_profile_page"),
|
||||||
] + static("/static/avatars/", document_root="./avatars")
|
] + static("/static/avatars/", document_root="./avatars")
|
@ -22,6 +22,12 @@ class ProfileViewSet(viewsets.ModelViewSet):
|
|||||||
return Response(self.serializer_class(instance).data,
|
return Response(self.serializer_class(instance).data,
|
||||||
status=status.HTTP_200_OK)
|
status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
profiles = ProfileModel.objects.all()
|
||||||
|
for profile in profiles:
|
||||||
|
profile.avatar_url.name = profile.avatar_url.name.replace("profiles", "", 1)
|
||||||
|
return profiles
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
serializer.save(user=self.request.user)
|
serializer.save(user=self.request.user)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user