-
Notifications
You must be signed in to change notification settings - Fork 1
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
Imgee V2 #59
Changes from 34 commits
441629f
7337d16
ba53794
412e44b
9a49863
127da69
be447ac
3b54fbd
6cd46ce
57a99f0
643e476
9ab5a45
d57fec0
e0f547f
cb7b9bd
c6c4645
b3ff9f4
c663086
e4ae277
eb5cab0
b4a14c1
6fabf71
fc28fea
edc1bf9
95c1615
95adecf
4451fb0
4635676
838d1ec
418e080
f112e6c
cc369e6
380bb87
f2c6fd6
23007ec
59bb581
d31b027
ff390de
6731ef9
3dcb9e5
d2c1228
88457f5
102e603
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
# The imports in this file are order-sensitive | ||
|
||
import os | ||
from celery import Celery | ||
|
||
from flask import Flask, redirect, url_for | ||
from flask_lastuser import Lastuser | ||
|
@@ -16,41 +15,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, app.config.get('UPLOADED_FILES_DIR')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use werkzeug's secure_filename here. |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from coaster.sqlalchemy import BaseNameMixin, BaseScopedNameMixin | ||
import imgee | ||
from imgee import app, url_for | ||
from imgee.models import db | ||
from imgee.utils import newid, guess_extension | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use dotted syntax as far as possible: from .. import app, url_for
from . import db
from ..utils import newid, guess_extension Also, what is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any advantage of using the relative import over absolute one? I usually feel a little confused whenever I face relative import. If the module name is present instead, it's clear on first glance where it's being imported from. And yeah, that's the same from flask. |
||
|
||
|
@@ -58,7 +58,33 @@ 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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's an inbuilt filter of jinja. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it needs a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want the binary format? By default it's |
||
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): | ||
new_labels = set(labels) | ||
old_labels = set(self.labels) | ||
if new_labels != old_labels: | ||
self.labels = labels | ||
|
||
if new_labels == old_labels: | ||
status, diff = '0', [] | ||
elif new_labels > old_labels: | ||
status, diff = '+', (new_labels - old_labels) | ||
elif (old_labels > new_labels): | ||
status, diff = '-', (old_labels - new_labels) | ||
else: | ||
status, diff = '', new_labels | ||
|
||
return status, list(diff) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if you had both additions and deletions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part of the code is a bit hairy. I think it can be handled better. I'll try something and show you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No change here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What goes in this folder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uploads made during running the tests.