def category_submit(name): form = SubmitForm(request.form) category = db.session.query(Category).filter_by(name=name).one() if request.method == 'POST' and form.validate(): file = request.files['image'] if not file: filename = form.link.data else: filename = file.filename image = Image(session['user'], category, form.name.data, form.text.data, form.link.data, filename) db.session.add(image) db.session.flush() if file and image.allowed: image.save(file) elif image.allowed: image.save() else: db.session.rollback() flash(local.category_submit['INVALID_IMAGE'], 'error') return render('category_submit.html', title=local.category['TITLE_SUBMIT'], category=category, form=form) image.save_thumbnail() image.save_exif() # Self upvote image.vote(1, session['user']) db.session.commit() flash(local.category_submit['IMAGE_POSTED'], 'success') return redirect(url_for('category_one', name=name)) flash_errors(form) return render('category_submit.html', title=local.category['TITLE_SUBMIT'], category=category, form=form)
users = User.query.all() categories = Category.query.all() for user in users: chance = random.randint(1, 100) if chance > 95: try: # Add image name = ''.join(random.choice(string.ascii_lowercase + ' -_') for x in range(1, random.randint(4, 30))) text = ''.join(random.choice(string.ascii_lowercase + ' -_') for x in range(1, random.randint(20, 200))) filename = 'http://i.imgur.com/7ZVtcSs.jpg' image = Image(user.id, categories[random.randint(0, len(categories)-1)], name, text, filename, filename) db.session.add(image) db.session.flush() image.save() image.save_thumbnail() image.save_exif() image.vote(1, user.id) db.session.commit() except: pass if imageactions: users = User.query.all() images = Image.query.all() i = 0 for user in users: i += 1 print 'User {} of {}'.format(i, len(users))