def deleteArtist(artist_id): if request.method == 'POST': db.artist.remove({"_id": ObjectId(artist_id)}) flash('You deleted the artist page', 'warning') return redirect_flask(url_for('.index')) return render_template('admin/artist/delete.html')
def wrap (*args, **kwargs): if 'logged_in' in session: return action (*args, **kwargs) else: flash('You need to log in first.', 'danger') session['next'] = request.path return redirect_flask(url_for('login'))
def update(view_id): artist = db.artist.find_one({"views._id": ObjectId(view_id)}) image = utils.find_where('_id', ObjectId(view_id), artist['views']) if image: form = forms.ArtistExhibitionView() if request.method == 'POST': if form.validate(): formdata = form.data image['exhibition_title'] = form.exhibition_title.data image['year'] = form.year.data image['institution'] = form.institution.data image['city'] = form.city.data image['country'] = form.country.data db.artist.update({'views._id': image['_id']}, {'$set': { 'views.$': image }}) db.artist.update({'selected_images._id': image['_id']}, {'$set': { 'selected_images.$': image }}) artist = db.artist.find_one({"_id": artist['_id']}) db.exhibitions.update({"artist._id": artist['_id']}, {"$set": { "artist": artist }}, multi=True) ## Should update this artist on group exhibitions as well db.exhibitions.update({"artists._id": artist['_id']}, {"$set": {"artists.$": artist}}, multi=True) flash('You just updated this images meta data', 'success') return redirect_flask(url_for('.index')) else: form = forms.ArtistExhibitionView(data=image) return render_template('admin/artist-exhib-views/edit.html', image=image, form=form)
def update(image_id): # Retreive exhibition which contains image exhibition = db.exhibitions.find_one({"images._id": ObjectId(image_id)}) image = utils.find_where('_id', ObjectId(image_id), exhibition['images']) form = forms.ExhibitionView() if request.method == 'POST': if form.validate(): formdata = form.data image['artist'] = form.artist.data image['exhibition_title'] = form.exhibition_title.data image['year'] = form.year.data image['institution'] = form.institution.data image['country'] = form.country.data db.exhibitions.update({'images._id': image['_id']}, {'$set': { 'images.$': image }}) # Update the image if it's visible on an artist page db.artist.update({'selected_images._id': image['_id']}, {'$set': { 'selected_images.$': image }}) flash(u'You just updated this views meta data', 'success') return redirect_flask(url_for('.individual_index', exhibition_id=str(exhibition['_id']))) else: form = forms.ExhibitionView(data=image) return render_template('admin/exhib-views/edit.html', image=image, form=form)
def update(image_id): artist = db.artist.find_one({"images._id": ObjectId(image_id)}) image = utils.find_where('_id', ObjectId(image_id), artist['images']) if image: form = forms.ImageUpdate() if request.method == 'POST': if form.validate(): formdata = form.data image['stock_number'] = form.stock_number.data image['title'] = form.title.data image['year'] = form.year.data image['medium'] = form.medium.data image['dimensions'] = form.dimensions.data image['edition'] = form.edition.data image['price'] = form.price.data db.artist.update({'images._id': image['_id']}, {'$set': { 'images.$': image }}) db.artist.update({'selected_images._id': image['_id']}, {'$set': { 'selected_images.$': image }}) db.exhibitions.update({'artworks._id': image['_id']}, {'$set': { 'artworks.$': image }}, multi=True) artist = db.artist.find_one({"_id": artist['_id']}) db.exhibitions.update({"artist._id": artist['_id']}, {"$set": { "artist": artist }}, multi=True) ## Should update this artist on group exhibitions as well db.exhibitions.update({"artists._id": artist['_id']}, {"$set": {"artists.$": artist}}, multi=True) flash('You just updated this images meta data', 'success') return redirect_flask(url_for('.index')) else: form = forms.ImageUpdate(data=image) return render_template('admin/image/edit.html', image=image, form=form)
def deleteOpeningHours(opening_hour_id): if request.method == 'POST': print(opening_hour_id) db.openinghours.remove({"_id": ObjectId(opening_hour_id)}) flash('You successfully deleted the opening hour entry', 'warning') return redirect_flask(url_for('listOpeningHours')) return render_template('admin/gallery/openinghours/galleryOpeningHoursDelete.html')
def deleteTeamMembers(teammember_id): if request.method == 'POST': print(teammember_id) db.teammember.remove({"_id": ObjectId(teammember_id)}) flash('You deleted the team member', 'warning') return redirect_flask(url_for('listTeamMembers')) return render_template('admin/gallery/teammembers/galleryTeamMemberDelete.html')
def deleteGroupExhibition(exhibition_id): if request.method == 'POST': print(exhibition_id) db.exhibitions.remove({"_id": ObjectId(exhibition_id)}) flash('You deleted the exhibition', 'warning') return redirect_flask(url_for('.index')) return render_template('admin/group-exhibition/exhibitionDelete.html')
def delete(image_id): if request.method == 'POST': exhibition = db.exhibitions.find_one({"images._id": ObjectId(image_id)}) image = utils.find_where('_id', ObjectId(image_id), exhibition['images']) os.remove(os.path.join(settings.appdir, image['path'])) db.image.remove({"_id": ObjectId(image_id)}) flash('You successfully deleted the image', 'success') return redirect_flask(url_for('.index')) return render_template('admin/image/delete.html')
def redirect(uri): """ http://arusahni.net/blog/2014/03/flask-nocache.html """ response = redirect_flask(uri) response.headers["Last-Modified"] = datetime.now() response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0" response.headers["Pragma"] = "no-cache" response.headers["Expires"] = "-1" return response
def createOpeningHours(): form = forms.GalleryHours() if form.validate_on_submit(): formdata = form.data openinghour = utils.handle_form_data({}, formdata) db.openinghours.insert(openinghour) flash('You successfully created the opening hour entry', 'success') return redirect_flask(url_for('listOpeningHours')) return render_template('admin/gallery/openinghours/galleryOpeningHoursCreate.html', form=form)
def createTeamMember(): form = forms.GalleryEmployees() if form.validate_on_submit(): formdata = form.data teammember = utils.handle_form_data({}, formdata) teammember['slug'] = utils.slugify(teammember['name']) db.teammember.insert(teammember) flash('You successfully created a new team member', 'success') return redirect_flask(url_for('listTeamMembers')) return render_template('admin/gallery/teammembers/galleryTeamMemberCreate.html', form=form)
def login(): error = None form = forms.Login() if form.is_submitted(): if validate_credentials(username=form.username.data, password=form.password.data): session['logged_in'] = True flash('You are logged in! Welcome', 'success') return redirect_flask(url_for('viewAdmin')) else: flash('Invalid credentials; Please try again.', 'danger') return render_template('general-login.html', error=error, form=form)
def regenerateThumbs(): import subprocess import shlex import time cmd = "sh /home/janssen/webapps/new_rodolphejanssen_com/Jason-Scraper/regenerateThumbs.sh" parsed_cmd = shlex.split(cmd) print(parsed_cmd) subprocess.call(parsed_cmd) print("removed all thumbs") time.sleep(5) flash('Thumbnail cache has been deleted, new thumbnails generated.', 'success') return redirect_flask(url_for('viewAdmin')) return render_template('admin.html')
def delete(view_id): if request.method == 'POST': artist = db.artist.find_one({"views._id": ObjectId(view_id)}) image = utils.find_where('_id', ObjectId(view_id), artist['views']) os.remove(os.path.join(settings.appdir, image['path'])) db.artist.update({ '_id': artist['_id'] }, { '$pull': { 'views': {'_id': image['_id'] }, 'selected_images': {'_id': image['_id'] } } }); artist = db.artist.find_one({"_id": artist['_id']}) db.exhibitions.update({"artist._id": artist['_id']}, {"$set": { "artist": artist }}, multi=True) ## Should update this artist on group exhibitions as well db.exhibitions.update({"artists._id": artist['_id']}, {"$set": {"artists.$": artist}}, multi=True) flash('You successfully deleted the image', 'success') return redirect_flask(url_for('.index')) return render_template('admin/artist-exhib-views/delete.html')
def updateOpeningHours(opening_hour_id): opening_hour = db.openinghours.find_one({"_id": ObjectId(opening_hour_id)}) if request.method == 'POST': form = forms.GalleryHours() if form.validate_on_submit(): formdata = form.data db.openinghours.update( { "_id": ObjectId(opening_hour_id) }, utils.handle_form_data(opening_hour, formdata), upsert=True ) flash('You successfully updated the opening hour entry', 'success') return redirect_flask(url_for('listOpeningHours')) else: form = forms.GalleryHours(data=opening_hour) return render_template('admin/gallery/openinghours/galleryOpeningHoursEdit.html', form=form, galleryHoursId=opening_hour_id)
def updateTeamMembers(teammember_id): teammember = db.teammember.find_one({"_id": ObjectId(teammember_id)}) if request.method == 'POST': form = forms.GalleryEmployees() if form.validate_on_submit(): formdata = form.data db.teammember.update( { "_id": ObjectId(teammember_id) }, utils.handle_form_data(teammember, formdata), upsert=True ) flash('You successfully updated the team member entry', 'success') return redirect_flask(url_for('listTeamMembers')) else: form = forms.GalleryEmployees(data=teammember) return render_template('admin/gallery/teammembers/galleryTeamMemberEdit.html', form=form, teamMemberId=teammember_id)
def create(): form = forms.Image() form.artist.choices = [(str(artist['_id']), artist['name']) for artist in db.artist.find().sort("artist_sort")] if form.validate_on_submit(): formdata = form.data artist = db.artist.find_one({'_id': ObjectId(formdata['artist'])}) image = { '_id': ObjectId(), 'path': utils.handle_uploaded_file( request.files['image_file'], config.upload['ARTWORK_IMAGE'], utils.setfilenameroot(request.files['image_file'].filename, artist['slug']) ), 'title': form.title.data, 'year': form.year.data, 'medium': form.medium.data, 'dimensions': form.dimensions.data, 'edition': form.edition.data, 'price': form.price.data } artist['images'].append(image) artist['selected_images'].append(image) db.artist.update({"_id": ObjectId(formdata['artist'])}, artist) ## Update this artist on exhibitions as well db.exhibitions.update({"artist._id": ObjectId(formdata['artist'])}, {"$set": { "artist": artist }}, multi=True) ## Should update this artist on group exhibitions as well db.exhibitions.update({"artists._id": ObjectId(formdata['artist'])}, {"$set": {"artists.$": artist}}, multi=True) flash('You successfully added an image', 'success') return redirect_flask(url_for('.index')) return render_template('admin/image/create.html', form=form)
def update(artist_id): artist = db.artist.find_one({"_id": ObjectId(artist_id)}) # All the images available_images = [image for image in artist['images']] for image in artist['views']: if image and not utils.find_where('_id', image['_id'], available_images): available_images.append(image) # Find all exhibitions this artist participates in exhibitions = db.exhibitions.find({ "$or": [{ 'artist._id': artist['_id'] }, { 'artists._id': artist['_id'] }] }) for exhibition in exhibitions: for image in exhibition['images']: if image and not utils.find_where('_id', image['_id'], available_images): available_images.append(image) if request.method == 'POST': form = forms.ArtistForm() if form.validate_on_submit(): formdata = form.data artist['slug'] = utils.slugify(artist['name']) artist = utils.handle_form_data( artist, formdata, ['press_release', 'biography_file']) if 'press_release' in request.files \ and request.files['press_release']: uploaded_file = request.files['press_release'] basepath = utils.setfilenameroot(uploaded_file.filename, artist['slug']) artist['press_release'] = utils.handle_uploaded_file( uploaded_file, config.upload['PRESS_RELEASE'], basepath) artist['press_release_size'] = utils.getfilesize( artist['press_release']) elif 'press_release' not in request.form \ and 'press_release' in artist: del artist['press_release'] if 'biography_file' in request.files \ and request.files['biography_file']: uploaded_file = request.files['biography_file'] basepath = utils.setfilenameroot(uploaded_file.filename, artist['slug']) artist['biography_file'] = utils.handle_uploaded_file( uploaded_file, config.upload['BIOGRAPHY'], basepath) artist['biography_size'] = utils.getfilesize( artist['biography_file']) elif 'biography_file' not in request.form \ and 'biography_file' in artist: del artist['biography_file'] if 'coverimage' in request.files: uploaded_image = request.files.getlist('coverimage')[0] basepath = utils.setfilenameroot(uploaded_image.filename, artist['slug']) artist['coverimage'] = { 'path': utils.handle_uploaded_file(uploaded_image, config.upload['COVER_IMAGE'], basepath) } elif 'coverimage' not in request.form: if 'coverimage' in artist: del artist['coverimage'] # Construct an array to fill with uploaded images uploaded_images = [] uploaded_views = [] if 'images' in request.files: for uploaded_image in request.files.getlist('images'): image_path = utils.handle_uploaded_file( uploaded_image, config.upload['ARTWORK_IMAGE'], utils.setfilenameroot(uploaded_image.filename, artist['slug'])) image = {'_id': ObjectId(), 'path': image_path} artist['images'].append(image) uploaded_images.append(image) if 'views' in request.files: for uploaded_image in request.files.getlist('views'): image_path = utils.handle_uploaded_file( uploaded_image, config.upload['EXTERNAL_EXHIBITION_VIEW'], utils.setfilenameroot(uploaded_image.filename, artist['slug'])) image = {'_id': ObjectId(), 'path': image_path} artist['views'].append(image) uploaded_views.append(image) artist['selected_images'] = [] if 'images' in request.form: # Find all the selected images for path in request.form.getlist('images'): if path.find('uploaded:') > -1: index = int(re.search(':(\d+)$', path).group(1)) # uploaded image if path.find(':artwork:') > -1: # artwork artist['selected_images'].append( uploaded_images[index]) else: # external view artist['selected_images'].append( uploaded_views[index]) else: image = utils.find_where('path', path, available_images) if image: artist['selected_images'].append(image) db.artist.update({"_id": ObjectId(artist_id)}, artist) # Update this artist on exhibitions as well db.exhibitions.update({"artist._id": ObjectId(artist_id)}, {"$set": { "artist": artist }}, multi=True) # Should update this artist on group exhibitions as well db.exhibitions.update({"artists._id": ObjectId(artist_id)}, {"$set": { "artists.$": artist }}, multi=True) flash('You\'ve updated the artist page successfully', 'success') if request.is_xhr: return bson_dumps(artist), 201 else: return redirect_flask(url_for('.index')) else: # Invalid if request.is_xhr: return json.dumps(form.errors), 400 else: return render_template( 'admin/artist/edit.html', form=form, images=utils.prepare_images(available_images), selected_images=utils.prepare_images( artist['selected_images'] if 'selected_images' in artist else []), exhibitions=exhibitions, coverimage=[artist['coverimage']] if 'coverimage' in artist else []) else: form = forms.ArtistForm(data=artist) return render_template( 'admin/artist/edit.html', form=form, images=utils.prepare_images(available_images), selected_images=utils.prepare_images( artist['selected_images'] if 'selected_images' in artist else []), exhibitions=exhibitions, coverimage=[artist['coverimage']] if 'coverimage' in artist else [])
def createGroupExhibition(): form = forms.GroupExhibitionForm() artist = db.artist.find() form.artists.choices = [(str(artist['_id']), artist['name']) for artist in db.artist.find().sort("artist_sort")] selectedArtworks = [] if form.is_submitted(): if form.validate(): formdata = form.data exhibition = utils.handle_form_data( {}, formdata, ['press_release', 'artists', 'extra_artists']) exhibition['artists'] = [ db.artist.find_one({'_id': ObjectId(artist_id)}) for artist_id in request.form.getlist('artists') ] exhibition['slug'] = utils.slugify(exhibition['exhibition_name']) exhibition_md = form.wysiwig_exhibition_description.data exhibition['is_group_expo'] = True extra_artists = list( zip(request.form.getlist('extra_artists_name'), request.form.getlist('extra_artists_sort'))) exhibition['extra_artists'] = [{ 'name': name, 'artist_sort': sort } for name, sort in extra_artists] exhibition['artworks'] = [] uploaded_artworks = [] if 'artworks' in request.files: for uploaded_image in request.files.getlist('artworks'): image_path = utils.handle_uploaded_file( uploaded_image, config.upload['ARTWORK_IMAGE'], utils.setfilenameroot( uploaded_image.filename, exhibition['artists'][0]['slug'])) exhibition['artists'][0]['images'].append({ '_id': ObjectId(), 'path': image_path, 'published': False }) uploaded_artworks.append(image_path) db.artist.update({'_id': exhibition['artists'][0]['_id']}, exhibition['artists'][0]) ## Update this artist on exhibitions as well db.exhibitions.update({"artist._id": ObjectId(artist_id)}, {"$set": { "artist": artist }}, multi=True) ## Should update this artist on group exhibitions as well db.exhibitions.update({"artists._id": ObjectId(artist_id)}, {"$set": { "artists.$": artist }}, multi=True) if 'artworks' in request.form: for artwork_image_path in request.form.getlist('artworks'): if artwork_image_path: if artwork_image_path[0:9] == 'uploaded:': artwork_index = int(artwork_image_path[9:]) artwork_image_path = uploaded_artworks[ artwork_index] for artist in exhibition['artists']: image = utils.find_where('path', artwork_image_path, artist['images']) if image: exhibition['artworks'].append(image) break if request.files['press_release']: exhibition['press_release'] = utils.handle_uploaded_file( request.files['press_release'], config.upload['PRESS_RELEASE'], utils.setfilenameroot( request.files['press_release'].filename, exhibition['slug'])) exhibition['press_release_size'] = utils.getfilesize( exhibition['press_release']) if 'coverimage' in request.files: uploaded_image = request.files.getlist('coverimage')[0] exhibition['coverimage'] = { 'path': utils.handle_uploaded_file( uploaded_image, config.upload['EXHIBITION_COVER_IMAGE'], utils.setfilenameroot(uploaded_image.filename, exhibition['slug'])) } exhibition['images'] = [] uploaded_images = [] if 'image' in request.files: for uploaded_image in request.files.getlist('image'): uploaded_images.append( utils.handle_uploaded_file( uploaded_image, config.upload['EXHIBITION_VIEW'], utils.setfilenameroot(uploaded_image.filename, exhibition['slug']))) if 'image' in request.form: for path in request.form.getlist('image'): if path[0:9] == 'uploaded:': image_index = int(path[9:]) path = uploaded_images[image_index] exhibition['images'].append({'path': path}) inserted_id = db.exhibitions.insert(exhibition) flash( 'You successfully created the group exhibition, <a href="{1}">{0}</a>' .format( exhibition['exhibition_name'], url_for('.updateGroupExhibition', exhibition_id=inserted_id)), 'success') if request.is_xhr: return bson_dumps(exhibition), 201 else: return redirect_flask(url_for('.index')) elif request.is_xhr: return json.dumps(form.errors), 400 selectedArtworks = request.form.getlist('artworks') return render_template('admin/group-exhibition/exhibitionCreate.html', form=form, selectedArtworks=json.dumps(selectedArtworks))
def create(): form = forms.ArtistForm() exhibitions = db.exhibitions.find() if request.method == 'POST': if form.validate(): formdata = form.data artist = utils.handle_form_data( {}, formdata, ['press_release', 'biography_file']) artist['slug'] = utils.slugify(artist['name']) if 'press_release' in request.files \ and request.files['press_release']: uploaded_file = request.files['press_release'] basepath = utils.setfilenameroot(uploaded_file.filename, artist['slug']) artist['press_release'] = utils.handle_uploaded_file( uploaded_file, config.upload['PRESS_RELEASE'], basepath) artist['press_release_size'] = utils.getfilesize( artist['press_release']) if 'biography_file' in request.files \ and request.files['biography_file']: uploaded_file = request.files['biography_file'] basepath = utils.setfilenameroot(uploaded_file.filename, artist['slug']) artist['biography_file'] = utils.handle_uploaded_file( uploaded_file, config.upload['BIOGRAPHY'], basepath) artist['biography_size'] = utils.getfilesize( artist['biography_file']) if 'coverimage' in request.files: uploaded_image = request.files.getlist('coverimage')[0] basepath = utils.setfilenameroot(uploaded_image.filename, artist['slug']) artist['coverimage'] = { 'path': utils.handle_uploaded_file(uploaded_image, config.upload['COVER_IMAGE'], basepath) } artist['images'] = [] artist['views'] = [] artist['selected_images'] = [] uploaded_views = request.files.getlist('views') uploaded_images = request.files.getlist('images') # Go through added images. Should only be uploaded images if 'images' in request.form: for image_name in request.form.getlist('images'): if image_name and image_name.find('uploaded:') > -1: index = int(re.search(':(\d+)$', image_name).group(1)) if image_name.find(':artwork:') > -1: # image is an artwork image_path = utils.handle_uploaded_file( uploaded_images[index], config.upload['ARTWORK_IMAGE'], utils.setfilenameroot( uploaded_images[index].filename, artist['slug'])) image = {'_id': ObjectId(), 'path': image_path} artist['images'].append(image) else: # image is a view image_path = utils.handle_uploaded_file( uploaded_views[index], config.upload['EXTERNAL_EXHIBITION_VIEW'], utils.setfilenameroot( uploaded_views[index].filename, artist['slug'])) image = {'_id': ObjectId(), 'path': image_path} artist['views'].append(image) artist['selected_images'].append(image) db.artist.insert(artist) flash('You successfully created an artist page', 'success') if (request.is_xhr): return bson_dumps(artist), 201 else: return redirect_flask(url_for('.index')) elif (request.is_xhr): # Invalid and xhr, return the errors, rather than full HTML return json.dumps(form.errors), 400 return render_template('admin/artist/create.html', form=form, exhibitions=exhibitions, selected_images=[], images=[])
def logout(): session.pop('logged_in', None) flash('You are logged out', 'warning') return redirect_flask(url_for('login'))