def UpdateUser(): if not IsAuthenticated(): return redirect('/') try: user = User() user.firstName = request.args.get('usersettings_firstName', "", type=STRING) user.lastName = request.args.get('usersettings_lastName', "", type=STRING) user.username = request.args.get('usersettings_username', "", type=STRING) user.email = request.args.get('usersettings_email', "", type=STRING) user.password = request.args.get('usersettings_password', "", type=STRING) user.userId = GetUserIdSession() validationMessage = user.IsValid() if validationMessage != "": return jsonify(validationMessage) filterParameter = FilterParameter("USERUSERNAME", "LIKE", user.username) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) users = userhandler.Get(filterExpression) if len(users) > 0 and users[0].userId != GetUserIdSession(): return jsonify("This username is already taken") filterParameter = FilterParameter("USEREMAIL", "LIKE", user.email) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) users = userhandler.Get(filterExpression) if len(users) > 0 and users[0].userId != GetUserIdSession(): return jsonify("This e-mail address is already taken") userhandler.Update(user) SetUserIdSession(user.userId) SetFullNameSession(user.firstName + " " + user.lastName) SetUsernameSession(user.username) return jsonify("") except: return jsonify("Unexpected error occured")
def GetByUsernameOrEmail(usernameEmail): filterParameter1 = FilterParameter("USERUSERNAME", "LIKE", usernameEmail, "OR ") filterParameter2 = FilterParameter("USEREMAIL", "LIKE", usernameEmail) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter1) filterExpression.AddParameter(filterParameter2) userList = Get(filterExpression) if len(userList) > 0: return userList[0] return User()
def UpdateMusician(): if not IsAuthenticated(): return jsonify("You must be logged in to update a concert area") if not IsAdmin(): return jsonify( "You must have admin privileges to update a concert area") concert_areaId = request.args.get('concert_areaId', "", type=int) name = request.args.get('name', "", type=STRING) address = request.args.get('address', "", type=STRING) date = request.args.get('date', "", type=STRING) filterParameter1 = FilterParameter("CONCERT_AREANAME", "LIKE", name) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter1) concert_areaList = concert_areahandler.Get(filterExpression) if len(musicianList) > 0: return jsonify( "This musician already exists. Enter a different musician name.") concert_area = concert_areahandler.GetByID(concert_areaId) concert_area.name = name concert_area.address = address concert_area.capacity = capacity concert_areahandler.Update(concert_area) return jsonify("")
def AddConcert_area(): if not IsAuthenticated(): return jsonify("You must be logged in to add a concert area") if not IsAdmin(): return jsonify("You must have admin privileges to add a concert area") concert_area = Concert_area() concert_area.name = request.args.get('concert_areaadd_concert_areaName', "", type=STRING) concert_area.address = request.args.get( 'concert_areaadd_concert_areaaddress', "", type=STRING) concert_area.capacity = request.args.get( 'concert_areaadd_concert_areacapacity', "", type=STRING) filterParameter = FilterParameter("CONCERT_AREANAME", "LIKE", concert_area.name) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) concert_area = concert_areahandler.Get(filterExpression) if len(concert_area) > 0: return jsonify("This concert area already exists") if len(concert_area.capacity) != 7 and not musician.establishYear.isdigit( ): return jsonify( "Concert area's capacity cannot be equal or bigger than 1000000") concert_areahandler.Insert(concert_area) return jsonify("")
def News(): if not IsAuthenticated(): newsList = newsviewhandler.Get() newsList.sort(key=lambda x: x.updateDate, reverse=True) newsList = newsList[:3] for n in newsList: n.updateDate = n.updateDate.strftime('%d.%m.%Y') return render_template('news.html', newsList=newsList, authenticated=IsAuthenticated(), admin=IsAdmin(), fullName=GetFullNameSession()) searchBy = request.args.get('searchBy', "", type=STRING) filterParameter = FilterParameter("MUSICIANNAME", "LIKE", "%" + searchBy + "%") filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) newsList = newsviewhandler.Get(filterExpression) newsList.sort(key=lambda x: x.updateDate, reverse=True) for n in newsList: n.updateDate = n.updateDate.strftime('%d.%m.%Y') return render_template('news.html', newsList=newsList, authenticated=IsAuthenticated(), admin=IsAdmin(), fullName=GetFullNameSession())
def GetByMusicianName(musicianName): filterParameter = FilterParameter("MUSICIANNAME" , "LIKE", musicianName) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) musicianList = Get(filterExpression) if len(musicianList) > 0: return musicianList[0] return Musician()
def Register(): if IsAuthenticated(): return redirect('/') user = User() user.firstName = request.args.get('registerFirstName', "", type=STRING) user.lastName = request.args.get('registerLastName', "", type=STRING) user.username = request.args.get('registerUsername', "", type=STRING) user.email = request.args.get('registerEmail', "", type=STRING) user.password = request.args.get('registerPassword', "", type=STRING) user.userType = 2 validationMessage = user.IsValid() if validationMessage != "": return jsonify(validationMessage) filterParameter = FilterParameter("USERUSERNAME", "LIKE", user.username) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) users = userhandler.Get(filterExpression) if len(users) > 0: return jsonify("Username already exists") filterParameter = FilterParameter("USEREMAIL", "LIKE", user.email) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) users = userhandler.Get(filterExpression) if len(users) > 0: return jsonify("Email already exists") user = userhandler.Insert(user) SetUserIdSession(user.userId) SetFullNameSession(user.firstName + " " + user.lastName) SetUsernameSession(user.username) return jsonify("")
def Musicians(): searchBy = request.args.get('searchBy', "", type=STRING) filterParameter = FilterParameter("MUSICIANNAME", "LIKE", "%" + searchBy + "%") filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) musicianList = musicianhandler.Get(filterExpression) return render_template('musicians.html', musicianList=musicianList, authenticated=IsAuthenticated(), admin=IsAdmin(), fullName=GetFullNameSession())
def Concert_area(): searchBy = request.args.get('searchBy', "", type=STRING) filterParameter = FilterParameter("CONCERT_AREANAME", "LIKE", "%" + searchBy + "%") filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) concert_areaList = concert_areahandler.Get(filterExpression) return render_template('concert_area.html', concert_areaList=concert_areaList, authenticated=IsAuthenticated(), admin=IsAdmin(), fullName=GetFullNameSession())
def GetByID(musicianId): filterParameter = FilterParameter("MUSICIANID" , "=", musicianId) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) return Get(filterExpression)[0]
def GetByID(newsId): filterParameter = FilterParameter("NEWSID", "=", newsId) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) return Get(filterExpression)[0]
def GetByID(userId): filterParameter = FilterParameter("USERID", "=", userId) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) return Get(filterExpression)[0]
def GetByID(concert_areaId): filterParameter = FilterParameter("CONCERT_AREAID" , "=", concert_areaId) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) return Get(filterExpression)[0]
def GetByID(ticketId): filterParameter = FilterParameter("TICKETID", "=", ticketId) filterExpression = FilterExpression() filterExpression.AddParameter(filterParameter) return Get(filterExpression)[0]