Ejemplo n.º 1
0
def notes_validator(title, 
    body, 
    color,
    tags):
    errors = list()
    if title:
        if not is_empty(title, minimum=1):
            pass
        else:
            errors.append("Title is invalid. Must be a string of 1 characters minimum.")        
    if body and not is_empty(body, minimum=1):
        pass
    else:
        errors.append("Body is invalid: must be 1 characters minimum.")
    if color:
        if not checkers.is_string(color):
            pass
    else:
        errors.append("Color is invalid. Must be string.")
    if tags:
        if not is_empty(tags, minimum=2):
            pass
        else:
            errors.append("Tags is invalid. Must be at least one tag of two characters minimum.")    
    if len(errors) == 0:
        return True, errors
    if len(errors) > 0:
        return False, errors
Ejemplo n.º 2
0
def is_valid_username(username):
    pattern = r'^[A-Za-z0-9_]*$'
    valid = re.search(pattern, username)
    if (username and valid) and not is_empty(username, minimum=4) and len(username) < 30:
        return True
    else:
        return False
Ejemplo n.º 3
0
def gp_notebook():
	if request.method == "GET":
		notes = current_user.get_notes()
		if notes:
			return {
				"code": 200,
				"message":"Notes retrieved", 
				"success": True,
				"notes": notes_schema.dump(notes),
				}, 200
		return {
			"code": 200,
			"message":"No Notes found", 
			"success": True,
			"notes": [],
			}, 200
	if request.method == "POST":
		json_data = request.get_json()
		title = json_data.get("title")
		body = json_data.get("body")
		color = json_data.get("color")
		tags = json_data.get("tags")
		validate = notes_validator(title, 
		body, 
		color, 
		tags)
		if not validate[0]:
			return {
				"code": 400,
				"message":"Please review the errors", 
				"success": False,
				"errors": validate[1],
				}, 400
		note = Notes(
			user_id=current_user.id, 
			title=title, 
			body=body, 
			color=color,
			tags_string=tags)
		if is_empty(tags, minimum=2):
			tags = None
		else:
			tags = [note.tags.append(add_tags(tag.strip())) for tag in tags.split(",")]
		db.session.add(note)
		db.session.commit()
		if note:
			return {"code": 200,
				"message":"Note added successfully!", 
				"success": True,
				"note": note_schema.dump(note),
				}, 200
		return {    
			"code": 400,
			"message":"Could not add to database. "
			"Might be an enternal error. Please try again later.", 
			"success": False,
			"note": None
			}, 400
Ejemplo n.º 4
0
def gpd_notebooks(id):
	note = current_user.get_note(id)
	if not note:
	  return {
      "code": 404,
      "message":"note with that id was not found", 
      "success": False,
      "note": None, 
  }, 404
	if request.method == "GET":
		if note:
			return {
				"code": 200,
				"message":"Notes retrieved", 
				"success": True,
				"note": note_schema.dump(note),
			}, 200
	if request.method == "PUT":
		json_data = request.get_json()
		title = json_data.get("title")
		body = json_data.get("body")
		color = json_data.get("color")
		tags = json_data.get("tags")
		validate = notes_validator(title, 
			body, 
			color, 
			tags)
		if not validate[0]:
			return {
				"code": 400,
				"message":"Please review the errors", 
				"success": False,
				"errors": validate[1],
				}, 400
		update_note = current_user.update_note(note_id=id, title=title, 
			body=body, color=color, tags_string=tags)
		if is_empty(tags, minimum=2):
			tags = None
		else:
			tags = [note.tags.append(add_tags(tag.strip())) for tag in tags.split(",")]
		db.session.commit()
		if update_note:
			return {
				"code": 200,
				"message":"Note updated successfully!", 
				"success": True,
				"note": note_schema.dump(update_note),
				}, 200
		return {
			"code": 400,
			"message":"Could not add to database. Might be an enternal error."
			" Or that you may not have permission to do so. Please try again later.", 
			"success": False,
			"note": None,
			}, 400
	if request.method == "DELETE":
		note = current_user.move_note_to_trash(note)
		return {
			"code": 200,
			"message":"Note moved to trash", 
			"success": True,
			"note": note_schema.dump(note),
		}, 200
Ejemplo n.º 5
0
def is_valid_password(password):
    if password and not is_empty(password, minimum=8):
        return True
    return False