Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imgee V2 #59

Merged
merged 43 commits into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
441629f
removed celery as dependency
Apr 7, 2017
7337d16
fixed - was missing folder name when downloading file
Apr 10, 2017
ba53794
handling multiple resize request for same file
Apr 11, 2017
412e44b
removed print statements
Apr 11, 2017
9a49863
if there is an error while processing a file, raise it
Apr 11, 2017
127da69
fixed comment
Apr 11, 2017
be447ac
removed all tests
Apr 11, 2017
3b54fbd
removed more unnecessary things
Apr 11, 2017
6cd46ce
removed unnecessary imports and minor cleanup
Apr 11, 2017
57a99f0
renamed async.py
Apr 11, 2017
643e476
Merge pull request #56 from hasgeek/celery-removal
shreyas-satish Apr 12, 2017
9ab5a45
added label tests
Apr 14, 2017
d57fec0
separating label logic
Apr 14, 2017
e0f547f
fixed label tests
Apr 14, 2017
cb7b9bd
more cleanup, moved some views out of index.py
Apr 17, 2017
c6c4645
cleaned up label saving codes a little
Apr 17, 2017
b3ff9f4
added tests for upload and delete
Apr 17, 2017
c663086
updated status code for delete test
Apr 17, 2017
e4ae277
mixed couple of migrations and showing error
Apr 17, 2017
eb5cab0
Merge pull request #57 from hasgeek/new-tests
shreyas-satish Apr 17, 2017
b4a14c1
some more cleanups
Apr 18, 2017
6fabf71
Merge pull request #58 from hasgeek/new-tests
shreyas-satish Apr 18, 2017
fc28fea
using get_image_url to create image url
Apr 18, 2017
edc1bf9
not showing delete label button if not logged in
Apr 18, 2017
95c1615
importing only the needed forms
Apr 18, 2017
95adecf
added tests for resizing files and testing with multiple file types
Apr 20, 2017
4451fb0
comparing redirect location with generated thumbnail url
Apr 20, 2017
4635676
added redis to travis
Apr 20, 2017
838d1ec
fixed conflicts
May 4, 2017
418e080
Merge branch 'master' of github.com:hasgeek/imgee into imgee-v2
May 9, 2017
f112e6c
fixed fixtures file to use new init_app behavior
May 9, 2017
cc369e6
fixed conflict
Jun 1, 2017
380bb87
Function name fix, using uuid1mc, time format fix, TaskRegistry fix (…
Jun 23, 2017
f2c6fd6
fixed conflict
Jun 23, 2017
23007ec
lot of minor fixes
Jun 29, 2017
59bb581
using dotted relative import syntax everywhere, added tests for regis…
Jun 30, 2017
d31b027
cleaning up queries and imports
Jul 5, 2017
ff390de
cleanup of os.path and more comments on thumbnail
Jul 13, 2017
6731ef9
fixed typo
Jul 13, 2017
3dcb9e5
added buildspec.yml file for testing AWS CodeBuild
Jul 13, 2017
d2c1228
setting env varialbe manually for aws codebuild
Jul 13, 2017
88457f5
removed buildspec.yml file
Jul 17, 2017
102e603
showing loading spinner if file is still processing
Jul 17, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ baseframe-packed.css
baseframe-packed.js
error.log
imgee/static/uploads
imgee/static/test_uploads
*.bak
instance/production.env.sh
imgee/static/gen
26 changes: 16 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env:
global:
env:
global:
- secure: |-
G5Dn+zkbN/BeNoopxtM2idC2Hy1ebJxRxprD7XEAmH6VO26ANgWYLI1dMrdH
uQc9F317STawQ/Um6KnqjErOKkC2BUYTOTj8AzoPVFz6NcK/Ca4d9Vfbtf5u
Expand All @@ -8,17 +8,23 @@ env:
SQ9lTuSD5jg3NSM8yMfMU58ppAYBgd+6VQP01wUPFrV/JSsbfgnVjMTm/Nbk
EGeHYvQUiyAg7zM4KdNJr6txj+jBE8MAeh7EwYNHoh9B7Vx//GxmXFnWyjXV
9cJkFroDW1Zfs2SZjLtzMQC8YXE30jmMxg+XHCQewKzRa4u1320=
# this is already being set in runtests.sh,
# but need to set it for `./manage.py init` too.
# could set it before running manage.py, but chose to put it here
- FLASK_ENV=TESTING
language: python
python:
python:
- 2.7
before_script:
- mkdir imgee/static/test_uploads
script:
- nosetests --with-coverage
install:
- sudo apt-get -qq install zlib1g-dev libfreetype6-dev liblcms1-dev libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev libtiff4-dev librsvg2-dev ghostscript imagemagick pandoc
services:
- redis-server
install:
- sudo apt-get -qq install zlib1g-dev libfreetype6-dev liblcms1-dev libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev libtiff4-dev librsvg2-dev ghostscript imagemagick pandoc inkscape
- pip install -r requirements.txt
- pip install nose coverage BeautifulSoup4 Pillow
- pip install -r test_requirements.txt
before_script:
- ./manage.py init # creates the test upload directory
script:
- ./runtests.sh
notifications:
email: false
slack:
Expand Down
27 changes: 8 additions & 19 deletions imgee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

# The imports in this file are order-sensitive

import os
from celery import Celery
import os.path

from werkzeug.utils import secure_filename

from flask import Flask, redirect, url_for
from flask_lastuser import Lastuser
Expand All @@ -16,41 +17,29 @@
version = Version(__version__)
app = Flask(__name__, instance_relative_config=True)
lastuser = Lastuser()
celery = Celery()

assets['imgee.css'][version] = 'css/app.css'

from . import models, views
from .models import db
from .api import api
from .async import TaskRegistry
from .tasks import TaskRegistry

registry = TaskRegistry()

def mkdir_p(dirname):
if not os.path.exists(dirname):
os.makedirs(dirname)


# Configure the app

# Configure the application
coaster.app.init_app(app)
migrate = Migrate(app, db)
baseframe.init_app(app, requires=['baseframe', 'picturefill', 'imgee'])
lastuser.init_app(app)
lastuser.init_usermanager(UserManager(db, models.User))
registry.init_app(app)


@app.errorhandler(403)
def error403(error):
return redirect(url_for('login'))

if app.config.get('MEDIA_DOMAIN') and (
app.config['MEDIA_DOMAIN'].startswith('http:') or
app.config['MEDIA_DOMAIN'].startswith('https:')):
if app.config.get('MEDIA_DOMAIN', '').lower().startswith(('http://', 'https://')):
app.config['MEDIA_DOMAIN'] = app.config['MEDIA_DOMAIN'].split(':', 1)[1]
mkdir_p(app.config['UPLOADED_FILES_DEST'])

celery.conf.add_defaults(app.config)
registry.set_connection()
app.register_blueprint(api, url_prefix='/api/1')
app.upload_folder = os.path.join(app.static_folder, secure_filename(app.config.get('UPLOADED_FILES_DIR')))
60 changes: 0 additions & 60 deletions imgee/api.py

This file was deleted.

107 changes: 0 additions & 107 deletions imgee/async.py

This file was deleted.

16 changes: 8 additions & 8 deletions imgee/forms.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# -*- coding: utf-8 -*-

import os.path
from coaster.utils import make_name
from flask_wtf import Form
from baseframe.forms import Form
from wtforms.validators import Required, ValidationError, Length
from wtforms import (FileField, TextField, HiddenField,
SelectMultipleField, SelectField)
from wtforms import (FileField, TextField, HiddenField, SelectField)

from imgee import app
from imgee.models import Label
from imgee.utils import get_file_type, is_file_allowed
from .models import Label
from .utils import is_file_allowed


def valid_file(form, field):
if not is_file_allowed(field.data.stream):
if not is_file_allowed(field.data.stream, field.data.mimetype, field.data.filename):
raise ValidationError("Sorry, unknown image format. Please try uploading another file.")


Expand All @@ -28,8 +26,9 @@ class DeleteImageForm(Form):
class PurgeCacheForm(Form):
pass


def reserved_words():
"""get all words which can't be used as labels"""
"""Get all words which can't be used as labels"""
words = []
for rule in app.url_map.iter_rules():
r = rule.rule
Expand Down Expand Up @@ -67,6 +66,7 @@ class EditTitleForm(Form):
file_name = HiddenField('file_name')
file_title = TextField('title', validators=[Required(), Length(max=250)])


class UpdateTitle(Form):
title = TextField('Title', validators=[Required(), Length(max=250)])

Expand Down
2 changes: 1 addition & 1 deletion imgee/models/profile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from coaster.sqlalchemy import BaseNameMixin
from flask_lastuser.sqlalchemy import ProfileMixin
from imgee.models import db
from . import db


class Profile(ProfileMixin, BaseNameMixin, db.Model):
Expand Down
42 changes: 35 additions & 7 deletions imgee/models/stored_file.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
from flask import url_for

from coaster.sqlalchemy import BaseNameMixin, BaseScopedNameMixin
import imgee
from imgee.models import db
from imgee.utils import newid, guess_extension
from .. import app
from . import db
from ..utils import newid, guess_extension


image_labels = db.Table('image_labels',
Expand Down Expand Up @@ -58,7 +59,34 @@ def __repr__(self):
def extn(self):
return guess_extension(self.mimetype, self.orig_extn) or ''

def is_queued_for_deletion(self):
if imgee.app.config.get('CELERY_ALWAYS_EAGER'):
return False
return imgee.registry.is_queued_for_deletion(self.name+self.extn)
@property
def filename(self):
return self.name + self.extn

def dict_data(self):
return dict(
title=self.title,
uploaded=self.created_at.isoformat() + 'Z',
filesize=app.jinja_env.filters['filesizeformat'](self.size),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just call this function directly? Unless it's an inbuilt Jinja filter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an inbuilt filter of jinja.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it needs a binary parameter too. https://github.com/pallets/jinja/blob/master/jinja2/filters.py#L459

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the binary format? By default it's False.

imgsize=u'%s×%s px' % (self.width, self.height),
url=url_for('view_image', profile=self.profile.name, image=self.name),
thumb_url=url_for('get_image', image=self.name, size=app.config.get('THUMBNAIL_SIZE'))
)

def add_labels(self, labels):
status = {
'+': [],
'-': [],
'': []
}

new_labels = set(labels)
old_labels = set(self.labels)
if new_labels != old_labels:
self.labels = labels

status['+'] = new_labels - old_labels # added labels
status['-'] = old_labels - new_labels # removed labels
status[''] = old_labels.intersection(new_labels) # unchanged labels

return status
4 changes: 2 additions & 2 deletions imgee/models/thumbnail.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-

from coaster.sqlalchemy import BaseMixin
from imgee.models import db
from imgee.utils import newid
from . import db
from ..utils import newid


class Thumbnail(BaseMixin, db.Model):
Expand Down
Loading