示例#1
0
def login_as_guest(request):
    if request.user.is_authenticated():
        # if the user 'guestXYZ' is logged in, don't reset his conference objects,
        #   simply redirect him to the main page
        # if another (normal) user is already logged in, redirect him to the main page
        return redirect('/app/conference/list/')
    else:
        # Create new guest user
        suffix = User.objects.make_random_password(length=5, allowed_chars='1234567890')
        username = "******" + suffix
        while User.objects.filter(username=username).exists():
            suffix = User.objects.make_random_password(length=5, allowed_chars='1234567890')
            username = "******" + suffix
        password = ''
        user = User.objects.create_user(username, '', password)
        user.save()
        guest_user = authenticate(username=username, password=password)
        django_login(request, guest_user)
        c = Conference()
        c.user = user
        c.title = "Demo Conference " + suffix
        c.num_days = 2
        c.schedule_string = '[[[[]], [[]], [[], []]], []]'
        c.settings_string = '[[[60], [60], [60, 60]], []]'
        c.names_string = "[[['Slot1'], ['Slot2'], ['Slot 3a', 'Slot 3b']]]"
        c.start_times = "['7:00', '7:00']"
        c.save()
        return redirect('/app/conference/list/')
def copy_conference(request):
    # Create conference base
    new_conference = Conference()
    new_conference.user = request.user
    copied_conference = Conference.objects.get(pk=request.POST.get('conference', None), user=request.user)
    new_conference.title = "Copy of " + copied_conference.title
    # Copy conference structure
    settings_str = copied_conference.settings_string
    new_conference.settings_string = settings_str
    # Copy names
    names_str = copied_conference.names_string
    new_conference.names_string = names_str
    # Create new empty list of papers
    settings_list = ast.literal_eval(settings_str)
    new_list = []
    for d in settings_list:
        day = []
        for r in d:
            row = []
            for c in r:
                col = []
                row.append(col)
            day.append(row)
        new_list.append(day)
    new_conference.schedule_string = str(new_list)
    new_conference.num_days = copied_conference.num_days
    new_conference.slot_length = copied_conference.slot_length
    new_conference.save()
    return redirect('/app/conference/list')
示例#3
0
def copy_conference(request):
    # Create conference base
    new_conference = Conference()
    new_conference.user = request.user
    copied_conference = Conference.objects.get(pk=request.POST.get(
        'conference', None),
                                               user=request.user)
    new_conference.title = "Copy of " + copied_conference.title
    # Copy conference structure
    settings_str = copied_conference.settings_string
    new_conference.settings_string = settings_str
    # Copy names
    names_str = copied_conference.names_string
    new_conference.names_string = names_str
    # Create new empty list of papers
    settings_list = ast.literal_eval(settings_str)
    new_list = []
    for d in settings_list:
        day = []
        for r in d:
            row = []
            for c in r:
                col = []
                row.append(col)
            day.append(row)
        new_list.append(day)
    new_conference.schedule_string = str(new_list)
    new_conference.num_days = copied_conference.num_days
    new_conference.slot_length = copied_conference.slot_length
    new_conference.save()
    return redirect('/app/conference/list')
def index(request):
    if request.method == 'POST':
        request.session['conf'] = request.POST.get('conference',0)
    try:
        request.session['conf']
    except KeyError:
        return redirect('/app/conference/list')
    request.session['parallel_error']=""
    # Get the number of all authors and papers
    num_authors = Author.objects.filter(user=request.user).count()
    num_papers = Paper.objects.filter(user=request.user, conference=request.session['conf']).count()
    # Get the data necessary to display the schedule
    try:
        settings = Conference.objects.get(user=request.user, pk=request.session['conf'])
    except ObjectDoesNotExist:
        s = Conference()
        s.user = request.user
        s.num_days = 1
        s.slot_length = 60
        s.settings_string = "[[]]"
        s.schedule_string = "[]"
        s.save()
        settings = s
    num_days = None
    if settings is not None:
        num_days = settings.num_days
    day = int(request.GET.get('day',0))
    if day >= num_days and num_days >=1:
        raise Http404('The selected day is too high')
    settings_str = settings.settings_string
    settings_list = ast.literal_eval(settings.settings_string)[int(request.GET.get('day',0))]
    # Create the form for uploading files
    papers_form = FileForm()
    assignments_form = AssignmentsFileForm()
    # Create a list of all the papers that the user has imported/created
    papers = Paper.objects.filter(user=request.user, conference=request.session['conf']).order_by('title')
    paper_titles = []
    paper_ids = []
    paper_lengths = []
    paper_locked = []
    paper_clusters = []
    for paper in papers:
        paper_titles.append(paper.title)
        paper_ids.append(paper.pk)
        paper_lengths.append(paper.length)
        paper_locked.append(paper.is_locked)
        paper_clusters.append(paper.cluster)
    paper_dict = dict(zip(paper_ids, paper_titles))
    paper_locked_dict = dict(zip(paper_ids, paper_locked))
    schedule = ast.literal_eval(settings.schedule_string)
    return render(request, 'app/index.html', {'num_authors':num_authors, 'num_papers':num_papers, 'num_days':num_days,
                                              'settings_list':settings_list,'paper_titles':paper_titles,
                                              'paper_ids':paper_ids, 'paper_dict':paper_dict, 'schedule':schedule,
                                              'day':day, 'paper_lengths':paper_lengths, 'paper_locked':paper_locked_dict,
                                              'paper_clusters': paper_clusters, 'papers_form':papers_form,
                                              'assignments_form':assignments_form})
示例#5
0
def index(request):
    float_msg = None
    if request.session.get('float_msg', None):
        float_msg = request.session.get('float_msg', None)
        request.session['float_msg'] = None
    if request.method == 'POST':
        request.session['conf'] = request.POST.get('conference', 0)
    try:
        request.session['conf']
    except KeyError:
        return redirect('/app/conference/list')
    request.session['parallel_error'] = ""
    # Get the number of all authors and papers
    num_authors = Author.objects.filter(user=request.user).count()
    num_papers = Paper.objects.filter(
        user=request.user, conference=request.session['conf']).count()
    # Get the data necessary to display the schedule
    try:
        settings = Conference.objects.get(user=request.user,
                                          pk=request.session['conf'])
    except ObjectDoesNotExist:
        s = Conference()
        s.user = request.user
        s.num_days = 1
        s.slot_length = 60
        s.settings_string = "[[]]"
        s.schedule_string = "[]"
        s.save()
        settings = s
    num_days = None
    if settings is not None:
        num_days = settings.num_days
    day = int(request.GET.get('day', 0))
    if day >= num_days and num_days >= 1:
        raise Http404('The selected day is too high')
    settings_str = settings.settings_string
    settings_list = ast.literal_eval(settings.settings_string)[int(
        request.GET.get('day', 0))]
    set = schedule_manager_class()
    if settings.schedule_string == "[]":
        set.create_empty_list(settings.settings_string)
    else:
        set.import_paper_schedule(settings.schedule_string)
    for ri, row in enumerate(settings_list):
        print("row: " + str(row))
        for si, slot in enumerate(row):
            print("slot: " + str(slot))
            set.set_settings(settings_str)
            free_time = set.get_slot_free_time(int(request.GET.get('day', 0)),
                                               ri, si)
            slot = [slot, free_time]
            row[si] = slot
    # Create the form for uploading files
    papers_form = FileForm()
    assignments_form = AssignmentsFileForm()
    # Create a list of all the papers that the user has imported/created
    papers = Paper.objects.filter(
        user=request.user,
        conference=request.session['conf']).order_by('title')
    paper_titles = []
    paper_ids = []
    paper_lengths = []
    paper_locked = []
    paper_clusters = []
    for paper in papers:
        paper_titles.append(paper.title)
        paper_ids.append(paper.pk)
        paper_lengths.append(paper.length)
        paper_locked.append(paper.is_locked)
        paper_clusters.append(paper.cluster)
    paper_dict = dict(zip(paper_ids, paper_titles))
    paper_locked_dict = dict(zip(paper_ids, paper_locked))
    schedule = ast.literal_eval(settings.schedule_string)
    review_string = Conference.objects.get(
        user=request.user, pk=request.session['conf']).reviewer_biddings_string
    return render(
        request, 'app/index.html', {
            'num_authors': num_authors,
            'num_papers': num_papers,
            'num_days': num_days,
            'settings_list': settings_list,
            'paper_titles': paper_titles,
            'paper_ids': paper_ids,
            'paper_dict': paper_dict,
            'schedule': schedule,
            'day': day,
            'paper_lengths': paper_lengths,
            'paper_locked': paper_locked_dict,
            'paper_clusters': paper_clusters,
            'papers_form': papers_form,
            'assignments_form': assignments_form,
            'float_msg': float_msg,
            'review_string': review_string,
            'conference_title': settings.title
        })