12 changed files with 1 additions and 237 deletions
-
76accounts_app/migrations/0001_initial.py
-
26accounts_app/migrations/0002_auto_20180413_1839.py
-
21accounts_app/migrations/0003_auto_20180425_1135.py
-
1djing/settings.py
-
3docs/install.md
-
0photo_app/__init__.py
-
5photo_app/admin.py
-
24photo_app/migrations/0001_initial.py
-
0photo_app/migrations/__init__.py
-
71photo_app/models.py
-
10photo_app/urls.py
-
1photo_app/views.py
@ -1,76 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# Generated by Django 1.11 on 2018-02-26 00:20 |
|
||||
from __future__ import unicode_literals |
|
||||
|
|
||||
import django.core.validators |
|
||||
from django.db import migrations, models |
|
||||
import django.db.models.deletion |
|
||||
|
|
||||
|
|
||||
class Migration(migrations.Migration): |
|
||||
initial = True |
|
||||
|
|
||||
dependencies = [ |
|
||||
('auth', '0008_alter_user_username_max_length'), |
|
||||
('group_app', '0001_initial'), |
|
||||
('photo_app', '0001_initial'), |
|
||||
] |
|
||||
|
|
||||
operations = [ |
|
||||
migrations.CreateModel( |
|
||||
name='BaseAccount', |
|
||||
fields=[ |
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
|
||||
('password', models.CharField(max_length=128, verbose_name='password')), |
|
||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), |
|
||||
('is_superuser', models.BooleanField(default=False, |
|
||||
help_text='Designates that this user has all permissions without explicitly assigning them.', |
|
||||
verbose_name='superuser status')), |
|
||||
('username', models.CharField(max_length=127, unique=True, verbose_name='profile username')), |
|
||||
('fio', models.CharField(max_length=256, verbose_name='fio')), |
|
||||
('birth_day', models.DateField(auto_now_add=True, verbose_name='birth day')), |
|
||||
('is_active', models.BooleanField(default=True, verbose_name='Is active')), |
|
||||
('is_admin', models.BooleanField(default=False)), |
|
||||
('telephone', models.CharField(max_length=16, validators=[ |
|
||||
django.core.validators.RegexValidator('^\\+[7,8,9,3]\\d{10,11}$')], verbose_name='Telephone')), |
|
||||
], |
|
||||
options={ |
|
||||
'db_table': 'base_accounts', |
|
||||
}, |
|
||||
), |
|
||||
migrations.CreateModel( |
|
||||
name='UserProfile', |
|
||||
fields=[ |
|
||||
('baseaccount_ptr', |
|
||||
models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, |
|
||||
primary_key=True, serialize=False, to='accounts_app.BaseAccount')), |
|
||||
('email', models.EmailField(default='admin@example.ru', max_length=254)), |
|
||||
('avatar', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, |
|
||||
to='photo_app.Photo')), |
|
||||
('responsibility_groups', |
|
||||
models.ManyToManyField(blank=True, to='group_app.Group', verbose_name='Responsibility groups')), |
|
||||
], |
|
||||
options={ |
|
||||
'verbose_name': 'Staff account profile', |
|
||||
'verbose_name_plural': 'Staff account profiles', |
|
||||
'ordering': ['fio'], |
|
||||
'permissions': (('can_view_userprofile', 'Can view staff profile'),), |
|
||||
}, |
|
||||
bases=('accounts_app.baseaccount',), |
|
||||
), |
|
||||
migrations.AddField( |
|
||||
model_name='baseaccount', |
|
||||
name='groups', |
|
||||
field=models.ManyToManyField(blank=True, |
|
||||
help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', |
|
||||
related_name='user_set', related_query_name='user', to='auth.Group', |
|
||||
verbose_name='groups'), |
|
||||
), |
|
||||
migrations.AddField( |
|
||||
model_name='baseaccount', |
|
||||
name='user_permissions', |
|
||||
field=models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', |
|
||||
related_name='user_set', related_query_name='user', to='auth.Permission', |
|
||||
verbose_name='user permissions'), |
|
||||
), |
|
||||
] |
|
||||
@ -1,26 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# Generated by Django 1.11 on 2018-04-13 18:39 |
|
||||
from __future__ import unicode_literals |
|
||||
|
|
||||
import django.core.validators |
|
||||
from django.db import migrations, models |
|
||||
|
|
||||
|
|
||||
class Migration(migrations.Migration): |
|
||||
|
|
||||
dependencies = [ |
|
||||
('accounts_app', '0001_initial'), |
|
||||
] |
|
||||
|
|
||||
operations = [ |
|
||||
migrations.AlterField( |
|
||||
model_name='baseaccount', |
|
||||
name='username', |
|
||||
field=models.CharField(max_length=127, unique=True, validators=[django.core.validators.RegexValidator('^\\w{1,127}$')], verbose_name='profile username'), |
|
||||
), |
|
||||
migrations.AlterField( |
|
||||
model_name='userprofile', |
|
||||
name='avatar', |
|
||||
field=models.ImageField(default=None, null=True, upload_to='user/avatar', verbose_name='Avatar'), |
|
||||
), |
|
||||
] |
|
||||
@ -1,21 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# Generated by Django 1.11 on 2018-04-25 11:35 |
|
||||
from __future__ import unicode_literals |
|
||||
|
|
||||
import django.core.validators |
|
||||
from django.db import migrations, models |
|
||||
|
|
||||
|
|
||||
class Migration(migrations.Migration): |
|
||||
|
|
||||
dependencies = [ |
|
||||
('accounts_app', '0002_auto_20180413_1839'), |
|
||||
] |
|
||||
|
|
||||
operations = [ |
|
||||
migrations.AlterField( |
|
||||
model_name='baseaccount', |
|
||||
name='telephone', |
|
||||
field=models.CharField(blank=True, max_length=16, validators=[django.core.validators.RegexValidator('^(\\+[7,8,9,3]\\d{10,11})?$')], verbose_name='Telephone'), |
|
||||
), |
|
||||
] |
|
||||
@ -1,5 +0,0 @@ |
|||||
from django.contrib import admin |
|
||||
|
|
||||
from . import models |
|
||||
|
|
||||
admin.site.register(models.Photo) |
|
||||
@ -1,24 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
# Generated by Django 1.11 on 2018-02-26 00:20 |
|
||||
from __future__ import unicode_literals |
|
||||
|
|
||||
from django.db import migrations, models |
|
||||
|
|
||||
|
|
||||
class Migration(migrations.Migration): |
|
||||
initial = True |
|
||||
|
|
||||
dependencies = [ |
|
||||
] |
|
||||
|
|
||||
operations = [ |
|
||||
migrations.CreateModel( |
|
||||
name='Photo', |
|
||||
fields=[ |
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
|
||||
('image', models.ImageField(height_field='heigt', upload_to='', width_field='wdth')), |
|
||||
('wdth', models.PositiveSmallIntegerField(blank=True, default='759', editable=False, null=True)), |
|
||||
('heigt', models.PositiveSmallIntegerField(blank=True, editable=False, null=True)), |
|
||||
], |
|
||||
), |
|
||||
] |
|
||||
@ -1,71 +0,0 @@ |
|||||
# -*- coding:utf-8 -*- |
|
||||
import os |
|
||||
import time |
|
||||
import hashlib |
|
||||
|
|
||||
from django.db import models |
|
||||
from PIL import Image |
|
||||
from django.conf import settings |
|
||||
|
|
||||
BASE_DIR = getattr(settings, 'BASE_DIR', '.') |
|
||||
|
|
||||
|
|
||||
class Photo(models.Model): |
|
||||
image = models.ImageField(width_field='wdth', height_field='heigt') |
|
||||
wdth = models.PositiveSmallIntegerField(null=True, blank=True, editable=False, default="759") |
|
||||
heigt = models.PositiveSmallIntegerField(null=True, blank=True, editable=False) |
|
||||
|
|
||||
def __str__(self): |
|
||||
return "{0}".format(self.image) |
|
||||
|
|
||||
def big(self): |
|
||||
return self.image.url |
|
||||
|
|
||||
def min(self): |
|
||||
pth = self.image.url.split('/')[-1:][0] |
|
||||
return "/media/min/%s" % pth |
|
||||
|
|
||||
def save(self, *args, **kwargs): |
|
||||
if not self.image: |
|
||||
return |
|
||||
super(Photo, self).save(*args, **kwargs) |
|
||||
im = Image.open(self.image.path) |
|
||||
im.thumbnail((759, 759), Image.ANTIALIAS) |
|
||||
|
|
||||
hs = hashlib.md5(str(time.time()).encode()).hexdigest() |
|
||||
ext = self.image.path.split('.')[1:][0] |
|
||||
path = "%s/media" % BASE_DIR |
|
||||
fname = "%s/%s.%s" % (path, hs, ext) |
|
||||
if not os.path.exists(path): |
|
||||
os.makedirs(path) |
|
||||
if not os.path.exists(path + '/min'): |
|
||||
os.makedirs(path + '/min') |
|
||||
im.save(fname) |
|
||||
os.remove(self.image.path) |
|
||||
self.image = "media/%s.%s" % (hs, ext) |
|
||||
super(Photo, self).save(*args, **kwargs) |
|
||||
|
|
||||
# class Meta: |
|
||||
# unique_together = (('image',),) |
|
||||
|
|
||||
|
|
||||
def resize_image(sender, instance, **kwargs): |
|
||||
if not kwargs['created']: |
|
||||
im = Image.open(instance.image.path) |
|
||||
im.thumbnail((200, 121), Image.ANTIALIAS) |
|
||||
pth = instance.image.path.split('/')[-1:][0] |
|
||||
fullpath = "%s/media/min/%s" % (BASE_DIR, pth) |
|
||||
im.save(fullpath) |
|
||||
|
|
||||
|
|
||||
def post_delete_photo(sender, instance, **kwargs): |
|
||||
min_fname = instance.image.path.split('/')[-1:][0] |
|
||||
try: |
|
||||
os.remove('%s/media/min/%s' % (BASE_DIR, min_fname)) |
|
||||
os.remove(instance.image.path) |
|
||||
except OSError: |
|
||||
pass |
|
||||
|
|
||||
|
|
||||
models.signals.post_save.connect(resize_image, sender=Photo) |
|
||||
models.signals.post_delete.connect(post_delete_photo, sender=Photo) |
|
||||
@ -1,10 +0,0 @@ |
|||||
# -*- coding:utf-8 -*- |
|
||||
|
|
||||
urlpatterns = [ |
|
||||
# url(r'^$', 'photo_albums', name='media_home_link'), |
|
||||
# url(r'^(?P<id>\d+)$', 'photo_albums', name='media_home_link_by_id'), |
|
||||
# url(r'^album(?P<id>\d+)$', 'photos', name='media_photos_link'), |
|
||||
|
|
||||
# url(r'^newalbum/$', 'add_album', name='add_media_album_link'), |
|
||||
# url(r'^newphoto/$', 'add_photo_to_album', name='add_media_photo_link') |
|
||||
] |
|
||||
@ -1 +0,0 @@ |
|||||
# -*- coding:utf-8 -*- |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue