mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 02:49:15 +02:00
Resolve "An avatar for users"
This commit is contained in:
parent
b411df4f29
commit
af270f4abd
16 changed files with 374 additions and 17 deletions
|
@ -16,7 +16,11 @@ from django.utils import timezone
|
|||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from versatileimagefield.fields import VersatileImageField
|
||||
|
||||
from funkwhale_api.common import fields, preferences
|
||||
from funkwhale_api.common import utils as common_utils
|
||||
from funkwhale_api.common import validators as common_validators
|
||||
|
||||
|
||||
def get_token():
|
||||
|
@ -39,6 +43,9 @@ PERMISSIONS_CONFIGURATION = {
|
|||
PERMISSIONS = sorted(PERMISSIONS_CONFIGURATION.keys())
|
||||
|
||||
|
||||
get_file_path = common_utils.ChunkedPath("users/avatars", preserve_file_name=False)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class User(AbstractUser):
|
||||
|
||||
|
@ -88,6 +95,19 @@ class User(AbstractUser):
|
|||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
)
|
||||
avatar = VersatileImageField(
|
||||
upload_to=get_file_path,
|
||||
null=True,
|
||||
blank=True,
|
||||
max_length=150,
|
||||
validators=[
|
||||
common_validators.ImageDimensionsValidator(min_width=50, min_height=50),
|
||||
common_validators.FileValidator(
|
||||
allowed_extensions=["png", "jpg", "jpeg", "gif"],
|
||||
max_size=1024 * 1024 * 2,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.username
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue