예제 #1
0
def dashboard(request, user_pk=None):
    # PHASE_1 - Exchange hasn't started yet
    # PHASE_2 - Exchange has started

    user = request.user
    if user.is_staff and user_pk:
        user = User.objects.get(pk=user_pk)

    exchange = Exchange.upcoming()
    signup = None

    if exchange:
        signup = exchange.signups.filter(user=user)

    active_exchange = Exchange.current()
    if active_exchange:
        print("Got active Exchange")

        active_signup = active_exchange.signups.filter(user=user)[0]

        active_assignments = Assignment.objects.filter(
            user_signup=active_signup)
        print("active ass", active_assignments)

    past_assignments = Assignment.objects.filter(user=user)
    return render(
        request, 'dashboard.html', {
            "user": user,
            "next_exchange_signup": signup,
            "next_exchange": exchange,
            "past_assignments": past_assignments,
            "active_exchange": active_exchange,
            "active_signup": active_signup,
            "active_assignments": active_assignments,
        })
예제 #2
0
파일: tests.py 프로젝트: zznidar/urnik
 def _cancel_exchange_get_params(self, exchange: Exchange):
     """Cancel an exchange object and return its parameters for end-to-end testing."""
     result = dict(
         timetable=self.timetable,
         source_person=exchange.initiator_student,
         requested_student=exchange.requested_finalizer_student,
         subject_transfer_to_map={Activity.from_timetable_activity(
             exchange.allocation_from.activityRealization.activity).subject.id: exchange.allocation_to},
         force_allocation_from=exchange.allocation_from if exchange.initiator_student is None else None
     )
     exchange.date_cancelled = datetime.utcnow()
     exchange.save()
     return result
예제 #3
0
def confirm_signup(request, username, user_pk):
    user = get_object_or_404(User, pk=user_pk)
    if user.username.lower() != username.lower():
        raise Http404("User Doesn't Exist")
    user.email_confirmed = True
    user.save()
    auth_user(request, user)

    exchange = Exchange.latest()
    signup, created = Signup.objects.get_or_create(exchange=exchange,
                                                   user=user)
    if created:
        signup.tag = user.moniker
        signup.style = user.write_style
        signup.do_double = user.do_double
        do_double = request.GET.get("do_double")
        if do_double:
            signup.do_double = do_double == "true"
        signup.save()

    if request.method == 'POST':
        signup.tag = request.POST.get("tag")
        signup.style = request.POST.get("style")
        signup.do_double = request.POST.get("do_double", "false") == "true"
        signup.save()

    return render(
        request, 'confirm_signup.html', {
            "signup": signup,
            "exchange": exchange,
            'month': datetime.datetime.now().strftime("%B"),
        })
예제 #4
0
def new(request):
    if request.method == 'GET':
        if Card.objects.filter(card_user__in=Card_user.objects.filter(
                user_id=request.user.id)).count() == 0:
            return render(request, 'exchange/add.html',
                          {'message': 'Vous n\'avez pas de carte a échanger'})
        else:
            return render(
                request, 'exchange/add.html', {
                    'own_cards':
                    Card.objects.filter(card_user__in=Card_user.objects.filter(
                        user_id=request.user.id)).order_by('name'),
                    'all_cards':
                    Card.objects.all()
                })
    if request.method == 'POST':
        title = request.POST['title']
        id_card_sender = request.POST['cards']
        id_card_receiver = request.POST['card_demand']

        query = Exchange(exchange_statut="pending",
                         user_id=request.user.id,
                         title=title,
                         card_sender=Card(id=id_card_sender),
                         card_receiver=Card(id=id_card_receiver)).save()

        return render(request, 'exchange/index.html',
                      {'message': 'Votre demande a été enregistré'})
예제 #5
0
def signup(request):
    if request.method == 'POST':
        email = request.POST["email"].lower().strip()
        exchange = Exchange.latest()
        try:
            user = exchange.users.objects.get(email=email)
            return render(request, 'already_signed_up.html', {})
        except:
            pass
        user, created = User.objects.get_or_create(email=email)
        if created:
            user.username = rand_string()
            user.password = "******"
        user.moniker = request.POST["moniker"].strip()
        user.write_style = request.POST.get("write_style", None)
        user.recieve_style = request.POST.get("write_style", None)
        user.do_double = request.POST.get("do_double", "") == "true"
        user.comments = request.POST.get("comments", None)
        user.ip = request.META.get('REMOTE_ADDR', None)
        if user.ip:
            try:
                locale = g.city(user.ip)
                user.country = locale["country_name"]
                user.city = locale["city"]
            except:
                pass
        user.save()
        if created:
            auth_user(request, user)
            send_confirmation_email(user)

        exchange.users.add(user)
        exchange.save()

        return render(request, 'thank_you.html', {
            "email": email,
            "exchange": Exchange.latest()
        })
    return render(
        request, 'signup.html', {
            "exchange": Exchange.latest(),
            "completed_exchanges": Exchange.objects.filter(completed=True)
        })
예제 #6
0
def review(request, exchange=None):
    if exchange:
        exchange = get_object_or_404(Exchange,
                                     name__iexact=exchange.replace("_", " "))
    else:
        exchange = Exchange.objects.filter(completed=True).order_by("-pk")[0]
    if not exchange.completed and not request.user.is_superuser:
        raise Http404("Exchange Not yet Available")
    assignments = sortedAssignments(exchange)
    if request.method == 'POST':
        pass
    thank_you = request.GET.get("thank_you", False)
    return render(
        request, 'review.html', {
            "assignments": assignments,
            "exchange": exchange,
            "latest_exchange": Exchange.latest(),
            "thank_you": thank_you
        })
예제 #7
0
def rematch_guide(request, exchange=None):
    if exchange:
        exchange = get_object_or_404(Exchange,
                                     name__iexact=exchange.replace("_", " "))
    else:
        exchange = Exchange.this_month()
    assignments = list(Assignment.objects.filter(exchange=exchange))
    if request.method == 'POST':
        pass

    for assignment in assignments:
        if assignment.sketches.all().count() > 0:
            assignment.completed = True
            assignment.save()

    assignments = list(
        Assignment.objects.filter(exchange=exchange, rematch=False))
    #get the exchange circles.
    assignment_groups = []
    loop_count = 0
    while len(assignments) > 0 and loop_count < 1000:
        print("*******")
        assignment = assignments[0]
        sorted_assignments = []
        while assignment in assignments:
            print(assignment)
            assignments.remove(assignment)
            next_assignments = Assignment.objects.filter(
                recipient=assignment.user,
                exchange=exchange,
                style=assignment.style)
            for na in next_assignments:
                sorted_assignments.append(na)
                if not na.rematch:
                    assignment = na
        sorted_assignments.reverse()
        assignment_groups.append(sorted_assignments)
        loop_count += 1

    return render(request, 'rematch_guide.html', {
        "assignment_groups": assignment_groups,
        "exchange": exchange,
    })