def submit_art(): """Displays the artwork submission page and handles the submission of artworks.""" if g.logged_in_user: if request.method == 'GET': return render_template("submit.html") else: # Form Validation if not ("title" in request.form and "description" in request.form) : abort(500) elif not request.form["title"]: flash("Your title must not be left blank. ") art = request.files['upload'] art_type = None # Image if request.form["art_type"] == "image": if not util.allowed_file(art.filename, config.image_extensions): flash(config.file_type_error + "The allowed filetypes are " + util.print_list(config.image_extensions) + ". ") elif art.content_length >= config.max_image_size: flash(config.file_size_error + "Your image must be at most " + config.max_image_size_text + ". ") else: art_type = "image" # Audio # Literature # Animation if request.form["art_type"] == "animation": if not util.allowed_file(art.filename, config.animation_extensions): flash(config.file_type_error + "Your animation must be a " + util.print_list(config.animation_extensions) + " file. ") elif art.content_length >= config.max_animation_size: flash(config.file_size_error + "Your .swf file must be at most " + config.max_image_size_text + ". ") else: art_type = "animation" # Craft # Cullinary # Performance if art_type: fileType = util.fileType(art.filename) key = keys_model.next("art") file_location = os.path.join(config.art_dir, str(key) + "." + fileType) art.save(file_location) storage.push(file_location, file_location) art_model.insert({ "_id" : key , "title" : request.form["title"] , "description" : request.form["description"] , "code_desc" : usercode.parse(request.form["description"]) , "author" : g.logged_in_user["username"] , "author_ID" : g.logged_in_user["_id"] , "keywords" : filter (lambda keyword: not keyword in ignored_keywords.commonWords, map(lambda keyword: keyword.lower() , request.form["title"].split() ) ) , "mature" : False , "folder" : "complete" , "favorites" : [] , "fav_amount" : 0 , "views" : 0 , "date" : datetime.datetime.today() , "filetype" : fileType , "type" : art_type }) if type == "image": autocrop(key) return redirect(url_for('crop',art=key)) else: return redirect(url_for('view_art',art=key)) return redirect(url_for('submit_art')) return redirect(url_for('submit_art')) else: abort(401)
def settings(): """The user's settings page. Used for changing their profile, account settings, and homepage.""" if g.logged_in_user: if request.method == 'GET': if config.beta_key: beta_keys = beta_pass_model.get({"owner" : g.logged_in_user["username"] }) else: beta_keys = None return render_template("settings.html", beta_keys = beta_keys) elif request.method == 'POST': # User Messages messages = [] # User Icon icon = request.files['icon_upload'] if icon: print icon.content_length if not icon.content_length <= config.max_icon_size: flash(config.file_size_error + "Your icon must be at most " + config.max_icon_size_text + ". ") else: if not util.allowed_file(icon.filename,config.icon_extensions): flash(config.file_type_error + "The allowed extensions are " + util.print_list(config.icon_extensions) + ". ") else: try: os.remove(os.path.join(config.icons_dir, g.logged_in_user['lowername'] + "." + g.logged_in_user["icon"])) except: if config.logging: logging.warning("Couldn't remove user \"" + g.logged_in_user['username']+ "\"'s old icon while attempting to upload a new icon. ") fileName = g.logged_in_user['lowername'] fileType = util.fileType(icon.filename) if fileType.lower() == "jpg": fileType = "jpeg" # Change filetype for PIL (mimetype,i) = mimetypes.guess_type(icon.filename) file_location = os.path.join(config.icons_dir, fileName) users_model.update({"lowername": g.logged_in_user['lowername']}, {"icon": fileType} ) icon.save(file_location) image = Image.open(file_location) resized = image.resize(config.icon_size, Image.ANTIALIAS) resized.save(file_location, fileType, quality=100) storage.push(file_location, file_location, mimetype = mimetype ) messages.append("User Icon") # Password if request.form["change_pass_current"] and request.form["change_pass_new_1"] and request.form["change_pass_new_2"]: if cryptography.encrypt_password(request.form["change_pass_current"], True) != g.logged_in_user['password']: flash("The new password you gave didn't match the one in the database! ):") elif request.form["change_pass_new_1"] != request.form["change_pass_new_2"]: flash("The new passwords you gave don't match! Try retyping them carefully. ") else: hashed = cryptography.encrypt_password(request.form['change_pass_new_1'], True) users_model.update({"_id": g.logged_in_user['_id']}, {"password": hashed} ) session['password']=hashed messages.append("Password") # Gender if request.form["change_gender"] != g.logged_in_user["gender"]: users_model.update({"_id": g.logged_in_user['_id']}, {"gender": request.form["change_gender"] }) messages.append("Gender") # Location if request.form["change_latitude"] != str(g.logged_in_user["latitude"]) or request.form["change_longitude"] != str(g.logged_in_user["longitude"]): try: latFloat = float(request.form["change_latitude"]) lonFloat = float(request.form["change_longitude"]) users_model.update({"_id": g.logged_in_user['_id']}, {"latitude": latFloat, "longitude": lonFloat } ) messages.append("Location") except ValueError: flash("The locations you gave were invalid latitude and longitude coordinates! ): ") # Profile if request.form["change_profile"] != g.logged_in_user["profile"]: users_model.update({"_id": g.logged_in_user['_id']}, {"profile": request.form["change_profile"], "code_profile": usercode.parse(request.form["change_profile"]) }) messages.append("Profile") # Color Theme if request.form["change_color_theme"] != g.logged_in_user["theme"]: users_model.update({"_id": g.logged_in_user['_id']}, {"theme": request.form["change_color_theme"]} ) messages.append("Color Theme") # Layout l1 = util.url_decode(request.form["change_layout"]) l2 = util.url_decode(request.form["change_layout_order"]) for key in l2: l2[key] = int(l2[key]) # Converts orderings to integers layout = util.conc_dict_values(l1,l2) if not util.compare_dicts(layout, g.logged_in_user["layout"]): if util.compare_dict_keys(layout, g.logged_in_user["layout"]): layout_to_push = {} for key in layout: layout_to_push["layout." + key] = layout[key] users_model.update({"_id": g.logged_in_user['_id']}, layout_to_push) messages.append("Layout") return render_template("settings_success.html",messages=messages,len=len) else: abort(401)