Switch to unified view

a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
...
...
2
import os
2
import os
3
import os.path
3
import os.path
4
import difflib
4
import difflib
5
import urllib
5
import urllib
6
import re
6
import re
7
import Image
8
import json
7
import json
9
import logging
8
import logging
10
from hashlib import sha1
9
from hashlib import sha1
11
from datetime import datetime
10
from datetime import datetime
12
11
...
...
248
    artifact.remove_tags(removed_tags)
247
    artifact.remove_tags(removed_tags)
249
    # Update the Tag index
248
    # Update the Tag index
250
    M.Tag.add(aref, user, added_tags)
249
    M.Tag.add(aref, user, added_tags)
251
    M.Tag.remove(aref, user, removed_tags)
250
    M.Tag.remove(aref, user, removed_tags)
252
251
253
def square_image(image):
254
    # image is wider than tall, so center horizontally
255
    height = image.size[0]
256
    width = image.size[1]
257
    if height < width:
258
        new_image = Image.new("RGB", (width, width), 'white')
259
        new_image.paste(image, ((width-height)/2, 0))
260
        image = new_image
261
    # image is taller than wide, so center vertically
262
    elif height > width:
263
        new_image = Image.new("RGB", (height, height), 'white')
264
        new_image.paste(image, (0, (height-width)/2))
265
        image = new_image
266
    return image
267
268
def supported_by_PIL(file_type):
269
    return str(file_type).lower() in ['image/jpg','image/png','image/jpeg','image/gif']
270
271
def save_image(icon, file_class, square=False, thumbnail_size=None, meta=None,
272
               save_original=False, original_meta=None):
273
    if icon is not None and icon != '':
274
        if supported_by_PIL(icon.type):
275
            if not meta:
276
                meta = dict()
277
            filename = icon.filename
278
            if icon.type: content_type = icon.type
279
            else: content_type = 'application/octet-stream'
280
            image = Image.open(icon.file)
281
            format = image.format
282
            if save_original:
283
                if not original_meta:
284
                    original_meta = dict()
285
                with file_class.create(
286
                    content_type=content_type,
287
                    filename=filename,
288
                    **original_meta) as fp:
289
                    filename = fp.name
290
                    image.save(fp, format)
291
            if square_image:
292
                image = square_image(image)
293
            if thumbnail_size:
294
                image.thumbnail(thumbnail_size, Image.ANTIALIAS)
295
            with file_class.create(
296
                content_type=content_type,
297
                filename=filename,
298
                **meta) as fp:
299
                image.save(fp, format)
300
        else:
301
            tg.flash('The icon must be jpg, png, or gif format.')
302
303
class DateTimeConverter(FancyValidator):
252
class DateTimeConverter(FancyValidator):
304
253
305
    def _to_python(self, value, state):
254
    def _to_python(self, value, state):
306
        try:
255
        try:
307
            return parse(value)
256
            return parse(value)