def add(self) -> Album: album = Album() album.user = current_user.id album.name = self.name album.description = self.description album.save() return album
def new_album(self): form = NewAlbumForm(request.form or None) if request.method == 'POST' and form.validate(): album = Album() album_title = request.form['title'] album_description = request.form['description'] album_path, album_thumb = self.gal_man.create_album(album_title) album.title = album_title album.description = album_description album.album_path = album_path album.thumb_path = album_thumb album.save() return redirect(url_for('.show_album', album_id=album.id)) return self.render('admin/new_album.html', form=form)
def post(self): user = get_user() if user: album = Album(parent=DEFAULT_DOMAIN_KEY) album.author = user.key album.name = self.request.get('album_name') album.description = self.request.get('album_desc') album.put() self.redirect('/album/%s/view' % album.key.integer_id()) else: self.redirect_to_login()
def new_album(self): form = NewAlbumForm(request.form or None) if request.method == 'POST' and form.validate(): album = Album() album_title = request.form['title'] album_description = request.form['description'] album_path, album_thumb = self.gal_man.create_album(album_title) album.title = album_title album.description = album_description album.album_path = album_path album.thumb_path = album_thumb album.save() return redirect(url_for('.show_album', album_id=album.id)) return self.render('admin/new_album.html', form=form)
def new(): """ Create a new album. --- tags: - Albums security: - OAuth2: - write responses: 200: description: Returns id and slug. """ current_user = current_token.user if not current_user: return jsonify({"error": "Unauthorized"}), 403 # Check artwork file size if "artwork" in request.files: artwork_uploaded = request.files["artwork"] artwork_uploaded.seek(0, os.SEEK_END) artwork_size = artwork_uploaded.tell() artwork_uploaded.seek(0) if artwork_size > Reel2bitsDefaults.artwork_size_limit: return jsonify({"error": "artwork too big, 2MB maximum" }), 413 # Request Entity Too Large else: artwork_uploaded = None form = AlbumForm() if form.validate_on_submit(): rec = Album() rec.user_id = current_user.id rec.title = form.title.data rec.private = form.private.data rec.description = form.description.data rec.genre = form.genre.data # Save the artwork if artwork_uploaded: artwork_filename = get_hashed_filename(artwork_uploaded.filename) artworkalbums.save(artwork_uploaded, folder=current_user.slug, name=artwork_filename) rec.artwork_filename = artwork_filename # Handle tags tags = form.tags.data.split(",") # Clean tags = [t.strip() for t in tags if t] # For each tag get it or create it for tag in tags: dbt = SoundTag.query.filter(SoundTag.name == tag).first() if not dbt: dbt = SoundTag(name=tag) db.session.add(dbt) rec.tags.append(dbt) db.session.add(rec) db.session.commit() # log add_user_log(rec.id, rec.user_id, "albums", "info", "Created {0} -- {1}".format(rec.id, rec.title)) return jsonify({"id": rec.flake_id, "slug": rec.slug}) return jsonify({"error": json.dumps(form.errors)}), 400