Beispiel #1
0
def getPhoto(request):
        user = UserInfo.objects.get(id=request.user.user_info.id)
        s3 = S3Storage()
        if user.photo:
            return HttpResponseRedirect(s3.s3.generate_url(60, 'GET', bucket=s3.bucket.name, key='/%s' % user.photo.name))
        else:
            return HttpResponseRedirect("/static/img/profile/profile-thumb.jpg")
Beispiel #2
0
 def get(self, request, file_id):
     f = MessageFile.objects.get(id=file_id)
     s3 = S3Storage()
     return HttpResponseRedirect(
         s3.s3.generate_url(60,
                            'GET',
                            bucket=s3.bucket.name,
                            key='/%s' % f.thumbnail.name))
Beispiel #3
0
class MapTemplateModel(models.Model):
    s3 = S3Storage()
    map_template = models.FileField(
        storage=s3,
        upload_to="maps/",
        unique=True,
        verbose_name="map template",
        validators=[
            validators.FileExtensionValidator(allowed_extensions=("html", ))
        ],
        error_messages={"invalid_extension": "Only *.html files are allowed"})
    boat = models.OneToOneField("BoatModel",
                                on_delete=models.CASCADE,
                                verbose_name="parent "
                                "boat")

    class Meta:
        verbose_name = "map template"
        verbose_name_plural = "map templates"
 def handle(self, *args, **options):
     messagefiles=MessageFile.objects.all()
     for messagefile in messagefiles:
         if re.match("image/*", messagefile.mime_type.__str__()):
             s3 = S3Storage()
             url = s3.s3.generate_url(60, 'GET', bucket=s3.bucket.name, key='/%s' % messagefile.file.name)
             file = StringIO.StringIO(urllib.urlopen(url).read())
             img = Image.open(file)
             if img.mode not in ('L', 'RGB'):
                 img = img.convert('RGB')
             w = MessageFile.THUMBNAIL_SIZE[0]
             h = MessageFile.THUMBNAIL_SIZE[1]
             if img.size[0] > img.size[1]:
                 h = img.size[1]*w/img.size[0].__float__()
             else:
                 w = img.size[0]*h/img.size[1].__float__()
             thumb = img.resize((w.__int__(), h.__int__()), Image.ANTIALIAS)
             thumb_io = StringIO.StringIO()
             thumb.save(thumb_io, format='JPEG', quality=70)
             thumb_file = InMemoryUploadedFile(thumb_io, None, 'foo.jpg', 'image/jpeg', thumb_io.len, None)
             messagefile.thumbnail = thumb_file
             print messagefile.id, messagefile.file
             messagefile.save()
Beispiel #5
0
from django.db import models
from django_boto.s3.storage import S3Storage

s3 = S3Storage()


class Service(models.Model):
    '''Descriptions about services that the society provides'''

    title = models.CharField(max_length=128)
    description = models.TextField()
    image = models.ImageField(storage=s3, upload_to='uploads')

    def __unicode__(self):
        return self.title
# Generated by Django 2.0.5 on 2018-05-23 12:57

import django.contrib.postgres.fields
from django.db import migrations, models

import documents.models
import functools

try:
    from django_boto.s3.storage import S3Storage
    file_storage = S3Storage()
except AttributeError:
    from django.core.files.storage import FileSystemStorage
    file_storage = FileSystemStorage('/media/uploads/')


class Migration(migrations.Migration):

    dependencies = [
        ('documents', '0003_auto_20180517_0832'),
    ]

    operations = [
        migrations.AddField(
            model_name='document',
            name='user_uuid',
            field=models.CharField(blank=True,
                                   max_length=36,
                                   null=True,
                                   verbose_name='User UUID'),
        ),