Ejemplo n.º 1
0
def feedback(request):
    pulled = pull_notif(request.user)

    if request.method == 'POST' and 'markread' not in request.POST:
        form = FeedbackForm(request.POST)

        if form.is_valid():
            if form.cleaned_data['feedback'] != "":
                subject = 'Feedback Left'
                message = form.cleaned_data['feedback'] + "\n from <b>" + str(
                    request.user.username) + "</b>"
                send_mail(
                    subject,
                    message,
                    '*****@*****.**',
                    ['*****@*****.**'],
                    fail_silently=True,
                )
            context = {'has_unread': pulled[0], 'notif': pulled[1]}
            return render(request, 'feedback/feedback_complete.html', context)
    else:
        if request.method == 'POST' and 'markread' in request.POST:
            mark_read(request.user)
            pulled = pull_notif(request.user)

        form = FeedbackForm()
        args = {'form': form, 'has_unread': pulled[0], 'notif': pulled[1]}
        return render(request, 'feedback/feedback_form.html', args)
Ejemplo n.º 2
0
def settings(request):
    pulled = pull_notif(request.user)
    if request.method == 'POST' and 'markread' in request.POST:
        mark_read(request.user)
        pulled = pull_notif(request.user)

    context = {'has_unread': pulled[0], 'notif': pulled[1]}
    return render(request, 'settings/settings.html', context)
Ejemplo n.º 3
0
def survey_complete(request):
    pulled = pull_notif(request.user)

    if request.method == 'POST' and 'markread' in request.POST:
        mark_read(request.user)
        pulled = pull_notif(request.user)

    context = {'has_unread': pulled[0], 'notif': pulled[1]}
    return render(request, 'survey/survey_complete.html', context)
Ejemplo n.º 4
0
def default_view(request, extra):
    pulled = pull_notif(request.user)

    if request.method == 'POST' and 'markread' in request.POST:
        mark_read(request.user)
        pulled = pull_notif(request.user)

    return render(request, '../templates/broken_page.html', {
        'has_unread': pulled[0],
        'notif': pulled[1]
    })
Ejemplo n.º 5
0
def matchresults_view(request):
    '''
    storage = messages.get_messages(request)
    msgs = []
    username = ''
    email    = ''
    industry = ''

    for message in storage:
        print(message, file=stderr)
        msgs.append(message)

    if len(msgs) > 0:
        username = msgs[0]
        email    = msgs[1]
        industry = msgs[2]
        messages.add_message(request, messages.INFO, username)
        messages.add_message(request, messages.INFO, email)
        messages.add_message(request, messages.INFO, industry)
    '''

    matchedUser = request.session.get('matchedUser', None)
    matchedUsers = []
    if matchedUser is not None:
        request.session['matchedUser'] = matchedUser
        matchedUsers.append(matchedUser)

    pulled = pull_notif(request.user)

    context = {  #
        #'msgs': msgs,
        #'username': username,
        #'email': email,
        #'industry': industry,
        'has_unread': pulled[0],
        'notif': pulled[1],
        'matchedUsers': matchedUsers,
        'configured': False
    }
    if request.method == 'POST' and 'markread' in request.POST:
        mark_read(request.user)
        pulled = pull_notif(request.user)
        context['has_unread'] = pulled[0]
        context['notif'] = pulled[1]
    else:
        val_acceptance = _on_accept(request)
        if (val_acceptance):
            # requested_names = str(request.user.profile.requested_names) + request.POST.get('username') + ","
            # request.user.profile.requested_names = requested_names
            # request.user.profile.save()
            return redirect('request_info')

    return render(request, 'matching/matchresults.html', context)
Ejemplo n.º 6
0
def request_info(request):
    pulled = pull_notif(request.user)

    if request.user.profile.is_matched or request.user.profile.is_waiting or request.user.profile.has_request:

        requested_names = str(request.user.profile.requested_names).split(",")
        requested_users = []

        for name in requested_names:
            if name is not '':
                requested_users.append(User.objects.get(username=name))

        if request.method == 'POST' and 'markread' in request.POST:
            mark_read(request.user)
            pulled = pull_notif(request.user)

        requestee = request.session.get('matchedUser', None)

        request_match = ""
        request_matches = User.objects.filter(
            username=request.user.profile.match_name)
        if request_matches:
            request_match = request_matches[0]

        # if (str(target.profile.industry_choice_2) == 'None'):
        #     industry = target.profile.industry_choice_1
        # else:
        #     industry = str(target.profile.industry_choice_1) + ', ' + str(target.profile.industry_choice_2)
        context = {
            'users': requested_users,
            'requestee': requestee,
            'request_match': request_match,
            # 'username': target.username,
            # 'industry': industry,
            # 'year': target.profile.year_in_school,
            # 'role': target.profile.role,
            # 'email': target.email,
            'has_unread': pulled[0],
            'notif': pulled[1],
            'request': request
        }

        return render(request, 'matching/request_info.html', context)
    else:
        if request.method == 'POST' and 'markread' in request.POST:
            mark_read(request.user)
            pulled = pull_notif(request.user)

        context = {'has_unread': pulled[0], 'notif': pulled[1]}

        return render(request, 'matching/no_request.html', context)
Ejemplo n.º 7
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['form'] = self.get_form()

        pulled = pull_notif(self.request.user)
        context['has_unread'] = pulled[0]
        context['notif'] = pulled[1]
        return context
Ejemplo n.º 8
0
def matchlistresults_view(request):
    matchedUsers = request.session.get('matchedUsers', None)
    pulled = pull_notif(request.user)
    if request.method == 'POST' and 'markread' in request.POST:
        mark_read(request.user)
        pulled = pull_notif(request.user)

    context = {
        'has_read': pulled[0],
        'notif': pulled[1],
        'matchedUsers': matchedUsers,
        'configured': True
    }

    val_acceptance = _on_accept(request)
    if (val_acceptance):
        return redirect('request_info')
    return render(request, 'matching/matchresults.html', context)
Ejemplo n.º 9
0
def confirm_cancel_request(request):
    match = None
    if request.user.profile.is_sender and request.user.profile.is_waiting:
        match = request.user.profile.match_name
    else:
        match = request.POST.get('match')

    # if match accepted/declined request already
    if match == None:
        match = request.user.profile.match_name

        # if match declined
        if not match:
            return render(request, 'matching/done_cancel.html')

        # if match accepted
        target = User.objects.get(username=match)
        email = target.email
        #print("hello match:", match, email)
        context = {
            'match': match,
            'email': email,
        }
        return render(request, 'matching/cannot_cancel.html', context)

    target = User.objects.get(username=match)
    pulled = pull_notif(request.user)
    print("my match")

    if request.method == 'POST' and 'markread' in request.POST:
        mark_read(request.user)
        pulled = pull_notif(request.user)

    context = {
        'username': target.username,
        'has_unread': pulled[0],
        'notif': pulled[1],
        'match': match,
    }
    return render(request, 'matching/confirm_cancel.html', context)
Ejemplo n.º 10
0
def edit_settings(request):
    pulled = pull_notif(request.user)

    if request.method == "POST" and 'markread' not in request.POST:
        form = SettingsForm(request.POST, instance=request.user.profile)

        if form.is_valid():
            form.save()
            return redirect('settings:settings')
    else:
        form = SettingsForm(instance=request.user.profile)

    form[
        'receive_email'].label = "Do you want to receive email notifications from Mockingbird?"
    form['is_idle'].label = "Do you want to be inactive?"
    form[
        'is_idle'].help_text = "(You will not be able to match nor will you show up in other user's recommended matches.)"

    if request.method == 'POST' and 'markread' in request.POST:
        mark_read(request.user)
        pulled = pull_notif(request.user)

    context = {'form': form, 'has_unread': pulled[0], 'notif': pulled[1]}
    return render(request, 'settings/settings_form.html', context)
Ejemplo n.º 11
0
def matchconfig_view(request):
    initial_data = {
        'industry_match': request.user.profile.industry_match,
        'rank_by': request.user.profile.rank_by,
    }

    form = MatchConfigurationForm(instance=request.user.profile,
                                  initial=initial_data)
    form.fields[
        'industry_match'].label = "Which industry or industries are you looking to be matched on?"
    form.fields[
        'rank_by'].label = "Which fields do you want to rank your matches by? (Ctrl or Cmd + Click) to select multiple."

    pulled = pull_notif(request.user)

    if request.method == 'POST' and 'markread' in request.POST:
        mark_read(request.user)
        pulled = pull_notif(request.user)

    return render(request, 'matching/match.html', {
        'form': form,
        'has_unread': pulled[0],
        'notif': pulled[1]
    })
Ejemplo n.º 12
0
def survey(request):
    pulled = pull_notif(request.user)

    # if not matched
    if not request.user.profile.is_matched:
        context = {'has_unread': pulled[0], 'notif': pulled[1]}
        if request.method == 'POST' and 'markread' in request.POST:
            mark_read(request.user)
            pulled = pull_notif(request.user)
            context['has_unread'] = pulled[0]
            context['notif'] = pulled[1]

        return render(request, 'survey/no_survey.html', context)

    # if submitted
    if request.method == 'POST' and 'markread' not in request.POST:
        form = SurveyForm(request.POST)
        # if valid form
        if form.is_valid():
            target = User.objects.filter(
                username=request.user.profile.match_name)[0]

            # update information about user
            request.user.profile.match_name = ""
            request.user.profile.is_matched = False
            request.user.profile.send_survey = False

            # now that multiple request don't need this?
            request.user.profile.is_sender = False
            request.user.profile.is_waiting = False
            request.user.profile.save()

            # update information about user's match
            # if tried to meet but the other person did not show up
            if form.cleaned_data['did_meet'] == 'yes' and form.cleaned_data[
                    'on_time'] == '1':
                target.statistics.no_show += 1
                target.statistics.overall_rating -= Decimal(0.5)
                target.statistics.save()
            elif form.cleaned_data['did_meet'] == 'yes':
                # print("did meet", file=stderr)

                # update the target's statistics
                current_total_rate = Decimal(
                    target.statistics.rate) * target.statistics.tot_interview

                target.statistics.rate = (current_total_rate + Decimal(
                    form.cleaned_data['friendly'])) / (
                        target.statistics.tot_interview + 1)
                target.statistics.tot_interview += 1

                # adding late
                if form.cleaned_data['on_time'] == "2" or form.cleaned_data[
                        'on_time'] == "3":
                    target.statistics.late += 1

                # updates to ratings
                if form.cleaned_data['friendly'] == "2":
                    target.statistics.overall_rating -= Decimal(0.2)

                elif form.cleaned_data['friendly'] == "1":
                    target.statistics.overall_rating -= Decimal(0.1)
                target.statistics.save()

                if form.cleaned_data['on_time'] == "2":
                    target.statistics.overall_rating -= Decimal(0.1)
                elif form.cleaned_data['on_time'] == "3":
                    target.statistics.overall_rating -= Decimal(0.2)
                target.statistics.save()

                # positive updates (capped at 5)
                if target.statistics.overall_rating < 5:
                    if form.cleaned_data[
                            'on_time'] == "4" and form.cleaned_data[
                                'friendly'] == "4":
                        target.statistics.overall_rating += Decimal(0.1)
                    elif form.cleaned_data[
                            'on_time'] == "4" and form.cleaned_data[
                                'friendly'] == "5":
                        target.statistics.overall_rating += Decimal(0.2)
                target.statistics.save()

                # send email if there is feedback
                if form.cleaned_data['comment'] != "":
                    subject = 'Comment Left'
                    message = form.cleaned_data[
                        'comment'] + "\n from <b>" + str(
                            request.user.username) + "</b> for " + str(
                                target.username)
                    send_mail(
                        subject,
                        message,
                        '*****@*****.**',
                        ['*****@*****.**'],
                        fail_silently=True,
                    )

            Thread.objects.filter(
                Q(first=request.user) | Q(second=request.user)).delete()
            matchlist_create(request.user)
            return redirect('survey:survey_complete')

    # if first time loading
    else:
        form = SurveyForm()

    form.fields['did_meet'].label = "Did you meet with your match?"
    form.fields['on_time'].label = "Was your match on time?"
    form.fields['friendly'].label = "How friendly or rude was your match?"
    form.fields['comment'].label = "If you have any additional comments or concern you would like to mention about " \
                                   "your partner, please add below."

    form.fields['did_meet'].initial = 'n/a'

    if request.method == 'POST' and 'markread' in request.POST:
        mark_read(request.user)
        pulled = pull_notif(request.user)

    args = {
        'form': form,
        'username': str(request.user.profile.match_name),
        'has_unread': pulled[0],
        'notif': pulled[1]
    }
    return render(request, 'survey/survey.html', args)
Ejemplo n.º 13
0
def login(request):
    pulled = pull_notif(request.user)
    if request.method == 'POST' and 'markread' in request.POST:
        mark_read(request.user)
        pulled = pull_notif(request.user)

    discover_users = []
    recommended = None

    if request.user.id is not None:
        matchlist = matchlist_get(request)
        length = len(matchlist)
        length = 3 if length > 3 else length

        if length > 0:
            for x in range(length):
                if not matchlist[x].profile.is_idle:
                    if recommended is not None:
                        discover_users.append(matchlist[x])
                    else:
                        recommended = matchlist[x]

    match = ""
    requested_users = []

    if not request.user.is_anonymous:
        if request.user.profile.match_name != "" and request.user.profile.match_name != "None":
            name = request.user.profile.match_name
            match = User.objects.filter(username=name)[0]

        if request.user.profile.is_matched or request.user.profile.is_waiting or request.user.profile.has_request:

            requested_names = str(
                request.user.profile.requested_names).split(",")
            # requested_users = []

            for name in requested_names:
                if name is not '':
                    requested_users.append(User.objects.get(username=name))

    context = {
        'has_unread': pulled[0],
        'notif': pulled[1],
        'discover_users': discover_users,
        'recommended': recommended,
        'match': match,
        'users': requested_users,
    }

    if request.method == 'POST' and 'send_request' in request.POST:
        _on_accept_home(request, discover_users[0])
        return redirect('home')

    elif request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                auth_login(request, user)
                return redirect('home')
            else:
                # return invalid login error message
                return render(
                    request, '../templates/home.html', {
                        'form': form,
                        'error_message': "Incorrect username and/or password"
                    })
    else:
        form = LoginForm()
    context['form'] = form
    return render(request, '../templates/home.html', context=context)
Ejemplo n.º 14
0
def done_cancel(request):
    if request.method == 'POST' and 'markread' in request.POST:
        storage = messages.get_messages(request)
        msgs = []
        for m in storage:
            msgs.append(m)
        mark_read(request.user)
        pulled = pull_notif(request.user)

        context = {
            'username': msgs[0],
            'has_unread': pulled[0],
            'notif': pulled[1],
        }
        return render(request, 'matching/done_cancel.html', context)

    # update target's info
    match = request.POST.get('match')
    target = User.objects.get(username=match)

    # case where they're trying to go to this url forcefully
    if not match or match == "None":
        return redirect('../default')

    # make a notification for the target
    # if user is sender, they are canceling
    if request.user.profile.is_sender:
        # update own info
        request.user.profile.is_waiting = False
        request.user.profile.is_sender = False
        request.user.profile.match_name = "None"
        request.user.save()

        # print("here")
        # if they are only one in the request
        request_names = target.profile.requested_names.split(",")
        if len(request_names) == 0:
            target.profile.has_request = False
        else:
            # remove their name from request_names
            new_names = []
            for x in request_names:
                if x and x != request.user.username:
                    new_names.append(x)
            if len(new_names) == 0:
                target.profile.has_request = False
                target.profile.requested_names = ""
            else:  # else reset the names
                target.profile.requested_names = ",".join(new_names)

        if target.profile.receive_email:
            # send email that the match has been rejected
            subject = '[MockingBird] Canceled Match Request :('
            message = render_to_string(
                'matching/cancel_email.html', {
                    'user': target,
                    'cancel_username': request.user.username,
                })
            target.email_user(subject, message)

        matchlist_create(request.user)
        NotificationItem.objects.create(type="MC",
                                        user=target,
                                        match_name=str(request.user.username))

    # if user is not the sender, they are rejecting someone
    else:
        target.profile.is_sender = False
        target.profile.is_waiting = False
        target.profile.match_name = ""

        # update current user
        requested_names = str(request.user.profile.requested_names).split(",")
        new_names = []
        for x in requested_names:
            if x and x != target.username:
                print(x)
                new_names.append(x)
        # print("rejecting")
        # print(new_names)

        # if none remaining, change to false
        if len(new_names) == 0:
            request.user.profile.has_request = False
            request.user.profile.requested_names = ""
        else:  #else reset the names
            request.user.profile.requested_names = ",".join(new_names)

        # send email
        if target.profile.receive_email:
            # send email that the match has been rejected
            subject = '[MockingBird] Rejected Match Request :('
            message = render_to_string(
                'matching/reject_email.html', {
                    'user': target,
                    'cancel_username': request.user.username,
                })
            target.email_user(subject, message)

        NotificationItem.objects.create(type="MD",
                                        user=target,
                                        match_name=str(request.user.username))
    target.profile.save()
    request.user.profile.save()

    pulled = pull_notif(request.user)

    context = {
        'username': target.username,
        'has_unread': pulled[0],
        'notif': pulled[1],
    }

    messages.add_message(request, messages.INFO, str(target.username))

    return render(request, 'matching/done_cancel.html', context)
Ejemplo n.º 15
0
def accept_request(request):
    if not request.user.profile.has_request:
        pulled = pull_notif(request.user)

        if request.method == 'POST' and 'markread' in request.POST:
            mark_read(request.user)
            pulled = pull_notif(request.user)

        context = {'has_unread': pulled[0], 'notif': pulled[1]}
        return render(request, 'matching/no_request.html', context)
    else:
        t_username = request.POST.get('match')
        requested_users = str(request.user.profile.requested_names).split(",")
        print("t_username: "******"":
                continue
            print("requested user: "******"this user is a match", file=stderr)
            else:
                target.profile.is_matched = False
                target.profile.match_name = ""
                print("this user is not a match", file=stderr)
            target.profile.is_waiting = False
            target.profile.is_sender = False
            target.profile.save()

        # change sender and accepter to matched
        request.user.profile.is_matched = True
        request.user.profile.has_request = False
        request.user.profile.requested_names = ""
        request.user.profile.match_name = t_username
        request.user.profile.save()

        # make notification item for target
        NotificationItem.objects.create(type="MA",
                                        user=target,
                                        match_name=str(request.user.username))
        current_site = get_current_site(request)

        # logic to send email to the target
        if target.profile.receive_email:
            subject = '[MockingBird] Your Match has been confirmed!'
            message = render_to_string('matching/match_confirmed.html', {
                'user': target,
                'domain': current_site.domain,
            })
            target.email_user(subject, message)

        #send_survey(request, target, str(target.profile.match_name), str(t_username))
        send_time = timezone.now() + timedelta(seconds=30)
        #send_survey.apply_async(eta=send_time, args=(request.user, target, current_site))
        send_survey.apply_async(eta=send_time,
                                args=(request.user, target, current_site))

        matchedUser = MatchedUser(
            username=str(target.username),
            email=str(target.email),
            industry1=str(target.profile.industry_choice_1),
            industry2=str(target.profile.industry_choice_2),
            year=str(target.profile.year_in_school))

        # notification for the send survey notification

        request.session['matchedUser'] = matchedUser.__dict__
        return redirect('request_info')