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/ ...@@ -11,7 +11,6 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
""" """
import os import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
...@@ -117,5 +116,5 @@ AUTH_USER_MODEL = 'social.SocialUser' ...@@ -117,5 +116,5 @@ AUTH_USER_MODEL = 'social.SocialUser'
# Extra Settings # Extra Settings
MAX_POST_LENGTH = 144 * 2 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." DESC = "Apparently, this user prefers to keep an air of mystery about them."
...@@ -9,12 +9,12 @@ from social.models import Post, Link, Snippet ...@@ -9,12 +9,12 @@ from social.models import Post, Link, Snippet
class SocialUserCreationForm(UserCreationForm): class SocialUserCreationForm(UserCreationForm):
class Meta: class Meta:
model = get_user_model() model = get_user_model()
fields = ("username", "email", "avatar") fields = ("username", "email")
class SocialUserChangeForm(UserChangeForm): class SocialUserChangeForm(UserChangeForm):
class Meta: class Meta:
model = get_user_model() model = get_user_model()
fields = ("username", "email", "avatar") fields = ("username", "email")
class CreatePostForm(forms.ModelForm): class CreatePostForm(forms.ModelForm):
class Meta: 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.conf import settings
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from django.db import models from django.db import models
def get_avatar():
class SocialUser(AbstractUser): return settings.STATIC_URL / Path(settings.AVATAR_BASE.format(randint(1, 4)))
avatar = models.URLField(blank=True)
desc = models.TextField(blank=True)
def save(self, *args, **kwargs): class SocialUser(AbstractUser):
self.avatar = settings.AVATAR avatar = models.URLField(blank=True, default=get_avatar)
self.desc = settings.DESC desc = models.TextField(blank=True, default=settings.DESC)
super().save(*args, **kwargs)
@property @property
def slug(self): 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