def statistics(): current_path = "Statistics" result = SideNavHelper.set_active_side_nav_element(current_path, side_nav_elements, app.logger) # The data on the x scale will be all available tags # The data on the y will be the count for how many times that tag occurs across all galleries # Load from json... galleries = GalleryHelper.load_from_json(app.logger) # Get all unique tags from all the galleries in a sorted order tags = GalleryHelper.get_unique_tags(galleries, app.logger) x = tags y = GalleryHelper.get_tags_count(galleries, tags, app.logger) # We are pessimistic and assume that we have no bar_chart_to_show bar_chart = None if len(tags) > 0: bar_chart = ChartHelper.generate_bar_chart(x, y, "Most used Tags overall") return render_template("statistics.html", side_nav_elements=result, current_path=current_path, tags_chart=bar_chart)
def create_new_gallery(): # Load from json... galleries = GalleryHelper.load_from_json(app.logger) current_path = "Create" result = SideNavHelper.set_active_side_nav_element(current_path, side_nav_elements, app.logger) # This happens when the user has entered all relevant data for a gallery if request.method == "POST": try: # Create from request object new_gallery = GalleryHelper.create_gallery_from_request( request, app.logger) # Add to existing galleries galleries.append(new_gallery) # Save as json file... GalleryHelper.save_to_json(galleries, app.logger) return redirect(url_for("my_galleries")) except Exception as error: return redirect( url_for("error", message=str(error), rescue_link=url_for('create_new_gallery'))) return render_template("create_new_gallery.html", side_nav_elements=result, current_path=current_path, requires_show_uploaded_files=True)
def search(): current_path = "Search" result = SideNavHelper.set_active_side_nav_element(current_path, side_nav_elements, app.logger) # Load from json... galleries = GalleryHelper.load_from_json(app.logger) # Get all unique tags from all the galleries in a sorted order tags = GalleryHelper.get_unique_tags(galleries, app.logger) if request.method == "POST": # Search for the galleries with the data from the POST request search_title = request.form.get("search-title", "") tags_to_include = request.form.getlist("tag-to-include") or [] found_galleries = GalleryHelper.filter_galleries( galleries, search_title, tags_to_include) return render_template("search_result.html", side_nav_elements=result, current_path=current_path, galleries=found_galleries) return render_template("search.html", side_nav_elements=result, current_path=current_path, tags=tags)
def my_galleries(): current_path = "My Galleries" result = SideNavHelper.set_active_side_nav_element(current_path, side_nav_elements, app.logger) # Load from json... galleries = GalleryHelper.load_from_json(app.logger) return render_template("my_galleries.html", side_nav_elements=result, current_path=current_path, galleries=galleries)
def look_at_gallery(gallery_name=""): current_path = "My Galleries" result = SideNavHelper.set_active_side_nav_element(current_path, side_nav_elements, app.logger) galleries = GalleryHelper.load_from_json(app.logger) found_gallery = GalleryHelper.get_gallery_with_name( galleries, gallery_name, app.logger) return render_template("look_at_gallery.html", side_nav_elements=result, current_path=current_path, gallery=found_gallery, requires_init_masonry=True)
def error(): current_path = "" # We extract the information directly from the request as encoding the rescue link in the route itself does not work # See: https://stackoverflow.com/questions/24892035/how-can-i-get-the-named-parameters-from-a-url-using-flask message = request.args.get("message", "") rescue_link = request.args.get("rescue_link", None) result = SideNavHelper.set_active_side_nav_element(current_path, side_nav_elements, app.logger) return render_template("error.html", side_nav_elements=result, current_path=current_path, message=message, rescue_link=rescue_link)
def favourites(): current_path = "Favourites" result = SideNavHelper.set_active_side_nav_element(current_path, side_nav_elements, app.logger) # Load from json... all_galleries = GalleryHelper.load_from_json(app.logger) # Filter out non favourite galleries galleries = [] for gallery in all_galleries: if gallery.is_favourite == True: galleries.append(gallery) return render_template("favourite_galleries.html", side_nav_elements=result, current_path=current_path, galleries=galleries)
def edit_gallery(gallery_name=""): current_path = "My Galleries" result = SideNavHelper.set_active_side_nav_element(current_path, side_nav_elements, app.logger) # Load from json... galleries = GalleryHelper.load_from_json(app.logger) # Find the gallery with the corresponding name found_gallery = GalleryHelper.get_gallery_with_name( galleries, gallery_name, app.logger) if request.method == "POST": try: updated_gallery = GalleryHelper.update_gallery_from_request( found_gallery, request, app.logger) # Remove the unedited one from galleries galleries.remove(found_gallery) # Add the newly edited one to galleries galleries.append(updated_gallery) # Save as json file... GalleryHelper.save_to_json(galleries, app.logger) return redirect(url_for("my_galleries")) except Exception as error: return redirect( url_for("error", message=str(error), rescue_link=url_for('edit_gallery', gallery_name=gallery_name))) return render_template("edit_gallery.html", side_nav_elements=result, current_path=current_path, gallery=found_gallery, requires_show_uploaded_files=True)
def delete_gallery(gallery_name=""): current_path = "My Galleries" result = SideNavHelper.set_active_side_nav_element(current_path, side_nav_elements, app.logger) # Load from json... galleries = GalleryHelper.load_from_json(app.logger) # Find the gallery with the corresponding name found_gallery = GalleryHelper.get_gallery_with_name( galleries, gallery_name, app.logger) if request.method == "POST": try: # Delete from file system GalleryHelper.delete_gallery(found_gallery.name, app.logger) # Delete from global object galleries.remove(found_gallery) # Save as json file... GalleryHelper.save_to_json(galleries, app.logger) return redirect(url_for("my_galleries")) except Exception as error: return redirect( url_for("error", message=str(error), rescue_link=url_for('delete_gallery', gallery_name=gallery_name))) return render_template("confirm_delete_gallery.html", side_nav_elements=result, current_path=current_path, gallery=found_gallery)