-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gaoshan
committed
Apr 5, 2022
0 parents
commit 5ce84dc
Showing
606 changed files
with
201,220 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AjaximageConfig(AppConfig): | ||
name = 'ajaximage' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#-*- coding: utf-8 -*- | ||
from django.core.files.storage import default_storage | ||
from django.db.models.fields.files import FileDescriptor, FieldFile | ||
from django.db.models import Field | ||
from django.conf import settings | ||
from .widgets import AjaxImageWidget | ||
|
||
|
||
class AjaxImageField(Field): | ||
|
||
storage = default_storage | ||
attr_class = FieldFile | ||
descriptor_class = FileDescriptor | ||
|
||
def __init__(self, *args, **kwargs): | ||
upload_to = kwargs.pop('upload_to', '') | ||
max_height = kwargs.pop('max_height', 0) | ||
max_width = kwargs.pop('max_width', 0) | ||
crop = kwargs.pop('crop', False) | ||
crop = 1 if crop is True else 0 | ||
|
||
if crop is 1 and (max_height is 0 or max_width is 0): | ||
raise Exception('Both max_width and max_height are needed if cropping') | ||
|
||
self.widget = AjaxImageWidget( | ||
upload_to=upload_to, | ||
max_width=max_width, | ||
max_height=max_height, | ||
crop=crop | ||
) | ||
super(AjaxImageField, self).__init__(*args, **kwargs) | ||
|
||
def contribute_to_class(self, cls, name, virtual_only=False): | ||
super(AjaxImageField, self).contribute_to_class(cls, name, virtual_only) | ||
setattr(cls, self.name, self.descriptor_class(self)) | ||
|
||
def get_prep_value(self, value): | ||
"""Returns field's value prepared for saving into a database.""" | ||
# Need to convert File objects provided via a form to unicode for database insertion | ||
if value is None: | ||
return None | ||
return str(value) | ||
|
||
def get_internal_type(self): | ||
return "TextField" | ||
|
||
def formfield(self, **kwargs): | ||
defaults = {'widget': self.widget} | ||
defaults.update(kwargs) | ||
return super(AjaxImageField, self).formfield(**defaults) | ||
|
||
def url(self): | ||
return 'a' | ||
|
||
|
||
if 'south' in settings.INSTALLED_APPS: | ||
from south.modelsinspector import add_introspection_rules | ||
add_introspection_rules([], ["^ajaximage\.fields\.AjaxImageField"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django import forms | ||
|
||
|
||
class FileForm(forms.Form): | ||
file = forms.FileField() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
from PIL import Image, ImageOps | ||
try: | ||
from StringIO import StringIO as IO | ||
except ImportError: | ||
from io import BytesIO as IO | ||
|
||
from django.core.files.base import ContentFile | ||
from django.core.files.uploadedfile import SimpleUploadedFile | ||
|
||
|
||
def resize(file_, max_width=0, max_height=0, crop=0): | ||
max_width = int(max_width) | ||
max_height = int(max_height) | ||
crop = int(crop) | ||
|
||
if(max_width == 0 and max_height == 0): | ||
return file_ | ||
|
||
max_width = 9999 if max_width == 0 else max_width | ||
max_height = 9999 if max_height == 0 else max_height | ||
|
||
size = (max_width, max_height) | ||
image = Image.open(file_) | ||
|
||
if(image.mode == 'RGBA'): | ||
image.load() | ||
background = Image.new('RGB', image.size, (255, 255, 255)) | ||
background.paste(image, mask=image.split()[3]) | ||
image = background | ||
|
||
temp = IO() | ||
|
||
if(crop == 1): | ||
image = ImageOps.fit(image, size, Image.ANTIALIAS) | ||
else: | ||
image.thumbnail(size, Image.ANTIALIAS) | ||
|
||
image.save(temp, 'jpeg') | ||
temp.seek(0) | ||
|
||
return SimpleUploadedFile(file_.name, | ||
temp.read(), | ||
content_type='image/jpeg') |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# SOME DESCRIPTIVE TITLE. | ||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | ||
# This file is distributed under the same license as the PACKAGE package. | ||
# Sergey Panasenko <[email protected]>, 2018. | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: \n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2018-04-19 20:35+0300\n" | ||
"PO-Revision-Date: 2018-04-18 12:02+0300\n" | ||
"Last-Translator: Sergey Panasenko <[email protected]>\n" | ||
"Language-Team: \n" | ||
"Language: ru\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" | ||
"%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n" | ||
"%100>=11 && n%100<=14)? 2 : 3);\n" | ||
"X-Generator: Poedit 1.8.7.1\n" | ||
|
||
#: ajaximage/widgets.py:24 | ||
msgid "Remove" | ||
msgstr "Удалить" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.ajaximage { | ||
float: left; | ||
} | ||
|
||
.ajaximage .progress { | ||
background: #333; | ||
width: 200px; | ||
} | ||
|
||
.ajaximage img { | ||
width: 200px; | ||
padding: 5px 0; | ||
display: block; | ||
margin-bottom: 3px; | ||
} | ||
|
||
.ajaximage a.file-link:hover img { | ||
opacity: 0.8; | ||
} | ||
|
||
.ajaximage .progress, | ||
.ajaximage .file-link, | ||
.ajaximage .file-remove, | ||
.ajaximage .file-input { | ||
display: none; | ||
} | ||
|
||
.ajaximage.progress-active .progress, | ||
.ajaximage.img-active .file-link, | ||
.ajaximage.img-active .file-remove, | ||
.ajaximage.form-active .file-input { | ||
display: block; | ||
} |
Oops, something went wrong.