Пример #1
0
def sendMessages():
    if session.get('user') != None:
        if request.method == 'POST':
            userName = request.form['user_name']
            content = request.form['content']
            message = Message()
            message.sender = current_app.user.username
            message.receiver = userName
            message.content = content
            status = search(userName, 'someqw19012341')
            if userName != current_app.user.username:

                if status == 'Password is invalid':
                    currentName = current_app.user.username
                    relationStatus = current_app.friendStore.searchFriends(
                        currentName, userName)
                    if relationStatus == 'alreadyExists':
                        current_app.messageStore.sendMessage(message)
                        current_app.messageStore.getMessages(
                            current_app.user.username)
                        notification = Notification()
                        for conversation in current_app.messageStore.conversations:
                            if conversation.sender == userName:
                                for messages in conversation.messages:
                                    if message.sender == currentName and message.receiver == userName:
                                        notification.requester = currentName
                                        notification.requested = userName
                                        notification.typeId = messages.messageId
                        current_app.notificationStore.sendMessageNotification(
                            notification)
                    else:
                        flash('you are not friends with ' + userName)
                else:
                    flash('There is no user with this username: '******'very funny -_-')
        return render_template('messages.html',
                               messages=current_app.messageStore.conversations,
                               userMap=current_app.usermap.myLocations,
                               user_name=current_app.user.username,
                               first_name=current_app.user.name,
                               last_name=current_app.user.surname,
                               e_mail=current_app.user.email)
    else:
        flash('Please sign in or register for DeepMap')
        return render_template('home.html')
Пример #2
0
def makeComment():
    if request.method == 'POST':
        friendsUsername = request.form['friendsName']
        content = request.form['content']
        username = current_app.user.username
        userId = current_app.user.userId
        comment = Comment()
        comment.userName = username
        comment.userId = userId
        comment.friendUsername = friendsUsername
        comment.content = content
        current_app.commentStore.addComment(comment)
        friendsMap = UserLocationStore()
        friendsMap.getLocations(friendsUsername)
        markerLocations = []
        for locations in friendsMap.myLocations:
            newLocation = {
                'lat': locations.lat,
                'lng': locations.lng,
                'info': locations.mapInfo,
                'label': locations.locationLabel
            }
            markerLocations.append(newLocation)
        current_app.commentStore.getComments(friendsUsername)
        notification = Notification()
        for comment in current_app.commentStore.comments:
            if comment.userName == username and comment.friendUsername == friendsUsername:
                notification.requester = username
                notification.requested = friendsUsername
                notification.typeId = comment.commentId
        current_app.notificationStore.sendCommentNotification(notification)
        return render_template('user_page.html',
                               comments=current_app.commentStore.comments,
                               markerLocations=markerLocations,
                               userMap=friendsMap.myLocations,
                               user_name=friendsUsername)
    else:
        flash('Please sign in or register for DeepMap')
        return render_template('home.html')