Kaydet (Commit) ecbedb42 authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya

default avatar system changed

üst 119ae653
......@@ -11,7 +11,6 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
......@@ -117,5 +116,5 @@ AUTH_USER_MODEL = 'social.SocialUser'
# Extra Settings
MAX_POST_LENGTH = 144 * 2
AVATAR = 'http://www.iconarchive.com/download/i106224/papirus-team/papirus-apps/python.ico'
AVATAR_BASE = 'img/avatars/avatar_{}.png'
DESC = "Apparently, this user prefers to keep an air of mystery about them."
......@@ -9,12 +9,12 @@ from social.models import Post, Link, Snippet
class SocialUserCreationForm(UserCreationForm):
class Meta:
model = get_user_model()
fields = ("username", "email", "avatar")
fields = ("username", "email")
class SocialUserChangeForm(UserChangeForm):
class Meta:
model = get_user_model()
fields = ("username", "email", "avatar")
fields = ("username", "email")
class CreatePostForm(forms.ModelForm):
class Meta:
......
# Generated by Django 2.2.1 on 2019-05-07 18:48
from django.db import migrations, models
import social.models
class Migration(migrations.Migration):
dependencies = [
('social', '0005_auto_20190506_0252'),
]
operations = [
migrations.AlterField(
model_name='socialuser',
name='avatar',
field=models.URLField(blank=True, default=social.models.get_avatar),
),
migrations.AlterField(
model_name='socialuser',
name='desc',
field=models.TextField(blank=True, default='Apparently, this user prefers to keep an air of mystery about them.'),
),
]
from pathlib import Path
from random import randint
from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.db import models
class SocialUser(AbstractUser):
avatar = models.URLField(blank=True)
desc = models.TextField(blank=True)
def get_avatar():
return settings.STATIC_URL / Path(settings.AVATAR_BASE.format(randint(1, 4)))
def save(self, *args, **kwargs):
self.avatar = settings.AVATAR
self.desc = settings.DESC
super().save(*args, **kwargs)
class SocialUser(AbstractUser):
avatar = models.URLField(blank=True, default=get_avatar)
desc = models.TextField(blank=True, default=settings.DESC)
@property
def slug(self):
......
from subprocess import run
COLORS = ("red", "green", "blue", "yellow")
def main(amount: int = 4, size: int = 400) -> None:
"""Generates a set of avatars from pure
colors."""
for color, opt in zip(COLORS, range(1, amount + 1)):
run(["convert", f"xc:{color}[{size}x{size}!]", f"avatar_{opt}.png"])
if __name__ == "__main__":
import sys
main(*sys.argv[1:])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment