Пример #1
0
def updateCastName(request, company_name, member_name, cast_id):
    name = 'updates:updateCastName'

    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)
        member = admin.member

        if Cast.objects.filter(id=cast_id).exists():
            cast = Cast.objects.get(id=cast_id)

            # save casting data
            if request.method == 'POST':
                form = CastForm(request.POST, instance=cast)
                if form.is_valid():
                    form.save()
                    return redirect('profiles:casts', company_name, member_name,)
            else:
                form = CastForm(instance=cast)
            return render(request, 'updates/update.html', {'company':company, 'member':member, 'curr':cast, 'form':form, 'redirect_name':name})

        return redirect('profiles:casts', company_name, member_name,)

    else:
        raise PermissionDenied
Пример #2
0
def deleteMember(request, company_name, member_name, member_id):
    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        if Member.objects.filter(id=member_id).exists():
            old_member = Member.objects.get(id=member_id)

            # make sure you can only delete people who are in your company
            if old_member.groups.filter(
                    name=company_name).exists() and admin.member != old_member:
                # delete person from company set
                company = Company.objects.get(name=company_name)
                company.user_set.remove(old_member)

                # if user is a student and is no longer associated with any companies, remove them from system to clear space
                if not old_member.has_usable_password(
                ) and old_member.groups.all().count() == 0:
                    old_member.delete()

        return redirect(
            'profiles:members',
            company_name,
            member_name,
        )

    else:
        raise PermissionDenied
Пример #3
0
def deleteSchedule(request, company_name, member_name):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        unscheduleRehearsals(company_name, Rehearsal.objects.filter(company__name=company_name), Cast.objects.filter(company__name=company_name))
        return redirect('profiles:scheduling', company_name, member_name,)
    else:
        raise PermissionDenied
Пример #4
0
def updateRehearsal(request, company_name, member_name, rehearsal_id):
    name = 'updates:updateRehearsal'
    
    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)
        member = admin.member
        
        if company.rehearsal_set.filter(id=rehearsal_id).exists():
            rehearsal = company.rehearsal_set.get(id=rehearsal_id)
                    
            # process the form and rehearsal data
            if request.method == 'POST':
                form = RehearsalForm(request.POST, instance=rehearsal)
                if form.is_valid():
                    form.save()

                    return redirect('profiles:spaces', company_name, member_name,)
            else:
                form = RehearsalForm(instance=rehearsal)
            return render(request, 'updates/update.html', {'company':company, 'member':member, 'curr':rehearsal, 'form':form, 'redirect_name':name})
        return redirect('profiles:spaces', company_name, member_name,)
    else:
        raise PermissionDenied
Пример #5
0
def addChoreographer(request, company_name, member_name, cast_id):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)
        if Cast.objects.filter(id=cast_id).exists():
            cast = Cast.objects.get(id=cast_id)

            if request.method == 'POST':
                form = CastingForm(request.POST, company_name=company_name)
                if form.is_valid():
                    members = form.cleaned_data['members']
                    for member in members:
                        new_choreographer = Choreographer(company=company,
                                                          cast=cast,
                                                          member=member)
                        new_choreographer.save()

        return redirect(
            'profiles:casts',
            company_name,
            member_name,
        )

    else:
        raise PermissionDenied
Пример #6
0
def deleteCast(request, company_name, member_name, cast_id):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        if Cast.objects.filter(id=cast_id).exists():
            cast = Cast.objects.get(id=cast_id)

            #unschedule the rehearsal, and delete the conflicts in cast mem
            rehearsal = cast.rehearsal
            rehearsal.is_scheduled = False
            rehearsal.save()

            members = Member.objects.filter(cast=cast)
            for mem in members:
                conflicts = mem.conflict_set.filter(description__endswith="(%s)" % (cast.name))
                for r in conflicts:
                    r.delete()
            
            choreographers = Choreographer.objects.filter(cast=cast)
            for choreographer in choreographers:
                conflicts = choreographer.member.conflict_set.filter(description__endswith="(%s)" % (cast.name))
                for r in conflicts:
                    r.delete()

            cast.delete()

            # check to see if company has any more casts
            casts = Cast.objects.filter(company__name=company_name)
            if len(casts) == 0:
                company = Company.objects.get(name=company_name)
                company.has_schedule = False
                company.save()

        return redirect('profiles:casts', company_name, member_name,)
    else:
        raise PermissionDenied
Пример #7
0
def updateDueDate(request, company_name, member_name, option):
    # make sure member is an admin and has the right to access this information
    admin = adminAuth(request, company_name, member_name)
    print option
    if admin:
        # save posted data if available
        if request.method == 'POST':
            company = Company.objects.get(name=company_name)
            if option == 'conflicts':
                try: 
                    valid_datetime = datetime.strptime(request.POST['datetimepicker4'], '%m/%d/%Y %I:%M %p')
                    company.conflicts_due = valid_datetime.replace(tzinfo=timezone.LocalTimezone())
                    company.save()
                    return redirect('profiles:profile', company_name=company_name, member_name=member_name)
                except ValueError:
                    return HttpResponse('You did not enter a valid date and time. So the information was not saved.')
            if option == 'casting':
                try: 
                    valid_datetime = datetime.strptime(request.POST['datetimepicker4'], '%m/%d/%Y %I:%M %p')
                    company.casting_due = valid_datetime.replace(tzinfo=timezone.LocalTimezone())
                    company.save()
                    return redirect('profiles:profile', company_name=company_name, member_name=member_name)
                except ValueError:
                    return HttpResponse('You did not enter a valid date and time. So the information was not saved.')
            return redirect('profiles:profile', company_name, member_name,)

        return render(request, 'profiles/datetimepicker.html', {'company_name':company_name, 'member_name':member_name, 'option':option})

    # admins and members logged in under the wrong name cannot access this page
    raise PermissionDenied
Пример #8
0
def addUsers(request, company_name, member_name):
    # create dataset for users (w/o valid netid)
    # dataset = []
    # results = User.objects.filter(groups__isnull=True).exclude(username='******')
    # for user in results:
    #     dataset.append("%s %s (%s)" % (user.first_name, user.last_name, user.email))
    # print dataset
    admin = adminAuth(request, company_name, member_name)

    if admin:
        company = Company.objects.get(name=company_name)

        # get any users w/o valid netids that are being added
        if request.method == 'POST':
            form = UserForm(request.POST)

            if form.is_valid():
                members = form.cleaned_data['users']

                for member in members:
                    member.groups.add(company)
                    member.save()

            return redirect('profiles:members', company_name=company_name, member_name=member_name)

        form = UserForm()
        return render(request, 'profiles/addmembers.html', {'form':form, 'company_name': company_name, 'member_name':member_name})
    else:
        raise PermissionDenied
Пример #9
0
def addCast(request, company_name, member_name):
    admin = adminAuth(request, company_name, member_name)

    if admin:
        company = Company.objects.get(name=company_name)

        if request.method == 'POST':
            cast_list = request.POST['cast_list']
            cast_list = [l for l in cast_list.split("\n") if l]

            # initialize error message for any processing errors
            error_message = "The following casts could not be created:"

            for name in cast_list:

                # make sure there is not already a cast with that name
                if Cast.objects.filter(name=name, company=company).exists():
                    error = "\n" + name + " (Already a cast in this company with this title)"
                    error_message += error
                    continue
                cast = Cast(company=company, name=name)
                cast.save()
            
            # print any errors
            if "\n" in error_message:
                print error_message
        return redirect('profiles:casts', company_name, member_name,)

    else:
        raise PermissionDenied
Пример #10
0
def addCast(request, company_name, member_name):
    admin = adminAuth(request, company_name, member_name)

    if admin:
        company = Company.objects.get(name=company_name)

        if request.method == 'POST':
            cast_list = request.POST['cast_list']
            cast_list = [l for l in cast_list.split("\n") if l]

            # initialize error message for any processing errors
            error_message = "The following casts could not be created:"

            for name in cast_list:

                # make sure there is not already a cast with that name
                if Cast.objects.filter(name=name, company=company).exists():
                    error = "\n" + name + " (Already a cast in this company with this title)"
                    error_message += error
                    continue
                cast = Cast(company=company, name=name)
                cast.save()

            # print any errors
            if "\n" in error_message:
                print error_message
        return redirect(
            'profiles:casts',
            company_name,
            member_name,
        )

    else:
        raise PermissionDenied
Пример #11
0
def deleteAdmin(request, company_name, member_name):
    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        admin.delete()

        return redirect('profiles:profile', company_name, member_name,)
    else:
        raise PermissionDenied
Пример #12
0
def deleteChoreographer(request, company_name, member_name, choreographer_id):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        if Choreographer.objects.filter(id=choreographer_id).exists():
            choreographer = Choreographer.objects.get(id=choreographer_id)
            choreographer.delete()

        return redirect('profiles:casts', company_name, member_name,)
    else:
        raise PermissionDenied
Пример #13
0
def addRehearsals(request, company_name, member_name):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)

        if request.method == 'POST':
            rehearsals = request.POST['rehearsals']
            rehearsals = [l for l in rehearsals.split("\n") if l]
            print rehearsals

            # initialize error message for any processing errors
            error_message = "The following rehearsals could not be processed:"

            for line in rehearsals:
                info = line.split()
                print info

                # make sure line is specified length
                if len(info) != 4:
                    error = "\n" + line + " (Each line should have exactly 4 words)"
                    error_message += error
                    continue

                # check start time
                try:
                    start = datetime.strptime(info[2], "%I:%M%p")
                    print start.time()

                    end = datetime.strptime(info[3], "%I:%M%p")
                    print end.time()
                except ValueError:
                    error = "\n" + line + " (Does not contain valid time parameters)"
                    error_message += error
                    continue

                # get day of week information
                dow = time.strptime(info[1], "%A").tm_wday

                rehearsal = Rehearsal(
                    company=company,
                    place=info[0],
                    day_of_week=TimeBlock.DAY_OF_WEEK_CHOICES[dow][0],
                    start_time=start.time(),
                    end_time=end.time())
                rehearsal.save()
                # print rehearsal
            if "\n" in error_message:
                print error_message
        return redirect(
            'profiles:spaces',
            company_name,
            member_name,
        )
    else:
        raise PermissionDenied
Пример #14
0
def deleteCastMem(request, company_name, member_name, cast_id, mem_id):
    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        if Cast.objects.filter(id=cast_id).exists() and Member.objects.filter(id=mem_id).exists():
            cast = Cast.objects.get(id=cast_id)
            mem = Member.objects.get(id=mem_id)
            cast.member_set.remove(mem)

        return redirect('profiles:casts', company_name, member_name,)
    else:
        raise PermissionDenied
Пример #15
0
def deleteAdmin(request, company_name, member_name):
    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        admin.delete()

        return redirect(
            'profiles:profile',
            company_name,
            member_name,
        )
    else:
        raise PermissionDenied
Пример #16
0
def settings(request, company_name, member_name):
    # return render(request, '404.html')
    member = memberAuth(request, company_name, member_name)
    if member:
        company = Company.objects.get(name=company_name)
        admin = adminAuth(request, company_name, member_name)
        choreographer = Choreographer.objects.filter(member=member, company=company).exists()

        personal_form = PersonalForm(instance=member)
        company_form = CompanyForm(instance=company)
        return render(request, 'profiles/settings.html', {'company': company, 'member':member, 'admin':admin, 'choreographer':choreographer, 'personal_form':personal_form, 'company_form':company_form})
    else:
        return redirect('profiles:profile', company_name, member_name,)
Пример #17
0
def deleteRehearsal(request, company_name, member_name, rehearsal_id):
    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)

        if company.rehearsal_set.filter(id=rehearsal_id).exists():
            rehearsal = company.rehearsal_set.get(id=rehearsal_id)
            rehearsal.delete()

        return redirect('profiles:spaces', company_name, member_name,)
    else:
        raise PermissionDenied
Пример #18
0
def deleteSchedule(request, company_name, member_name):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        unscheduleRehearsals(
            company_name, Rehearsal.objects.filter(company__name=company_name),
            Cast.objects.filter(company__name=company_name))
        return redirect(
            'profiles:scheduling',
            company_name,
            member_name,
        )
    else:
        raise PermissionDenied
Пример #19
0
def profile(request, company_name, member_name):
    # make sure member has access to this profile
    member = memberAuth(request, company_name, member_name)

    if member:
        if not member.first_name:
            return redirect('profiles:settings', company_name, member_name,)
        company = Company.objects.get(name=company_name)
        admin = adminAuth(request, company_name, member_name)
    
        return render(request, 'profiles/hub.html', {'member':member, 'company':company, 'admin':admin})

    else:
        raise PermissionDenied
Пример #20
0
def deleteChoreographer(request, company_name, member_name, choreographer_id):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        if Choreographer.objects.filter(id=choreographer_id).exists():
            choreographer = Choreographer.objects.get(id=choreographer_id)
            choreographer.delete()

        return redirect(
            'profiles:casts',
            company_name,
            member_name,
        )
    else:
        raise PermissionDenied
Пример #21
0
def members(request, company_name, member_name):
    # make sure member has access to this profile
    member = memberAuth(request, company_name, member_name)

    if member:
        company = Company.objects.get(name=company_name)
        member_list = Member.objects.filter(groups__name=company_name)
        admin_list = company.admin_set.all()

        admin = adminAuth(request, company_name, member_name)

        return render(request, 'profiles/members.html', {'company':company, 'member':member, 'member_list':member_list, 'admin_list':admin_list, 'admin':admin})

    else:
        raise PermissionDenied
Пример #22
0
def scheduling(request, company_name, member_name):
    # check if valid admin
    member = memberAuth(request, company_name, member_name)
    if member:
        company = Company.objects.get(name=company_name)
        admin = adminAuth(request, company_name, member_name)
        # rehearsals = company.getSortedRehearsals()
        rehearsals = Rehearsal.objects.filter(company=company)

        casts = Cast.objects.filter(company=company)

        form = RehearsalForm(company_name=company_name)

        return render(request, 'profiles/schedule.html', {'company':company, 'member':member, 'admin':admin, 'cast_list':casts, 'rehearsal_list':rehearsals, 'form':form})
    else:
        raise PermissionDenied
Пример #23
0
def addRehearsals(request, company_name, member_name):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)

        if request.method == 'POST':
            rehearsals = request.POST['rehearsals']
            rehearsals = [l for l in rehearsals.split("\n") if l]
            print rehearsals

            # initialize error message for any processing errors
            error_message = "The following rehearsals could not be processed:"

            for line in rehearsals:
                info = line.split()
                print info

                # make sure line is specified length
                if len(info) != 4:
                    error = "\n" + line + " (Each line should have exactly 4 words)"
                    error_message += error
                    continue

                # check start time
                try:
                    start = datetime.strptime(info[2], "%I:%M%p")
                    print start.time()

                    end = datetime.strptime(info[3], "%I:%M%p")
                    print end.time()
                except ValueError:
                    error = "\n" + line + " (Does not contain valid time parameters)"
                    error_message += error
                    continue

                # get day of week information
                dow = time.strptime(info[1], "%A").tm_wday

                rehearsal = Rehearsal(company=company, place=info[0], day_of_week=TimeBlock.DAY_OF_WEEK_CHOICES[dow][0], start_time=start.time(), end_time=end.time())
                rehearsal.save()
                # print rehearsal
            if "\n" in error_message:
                print error_message
        return redirect('profiles:spaces', company_name, member_name,)
    else:
        raise PermissionDenied
Пример #24
0
def deleteCastMem(request, company_name, member_name, cast_id, mem_id):
    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        if Cast.objects.filter(id=cast_id).exists() and Member.objects.filter(
                id=mem_id).exists():
            cast = Cast.objects.get(id=cast_id)
            mem = Member.objects.get(id=mem_id)
            cast.member_set.remove(mem)

        return redirect(
            'profiles:casts',
            company_name,
            member_name,
        )
    else:
        raise PermissionDenied
Пример #25
0
def deleteRehearsal(request, company_name, member_name, rehearsal_id):
    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)

        if company.rehearsal_set.filter(id=rehearsal_id).exists():
            rehearsal = company.rehearsal_set.get(id=rehearsal_id)
            rehearsal.delete()

        return redirect(
            'profiles:spaces',
            company_name,
            member_name,
        )
    else:
        raise PermissionDenied
Пример #26
0
def addAdmin(request, company_name, member_name, member_id):
    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)
        member = Member.objects.get(username=member_name)
        
        # get post data if available
        mem = Member.objects.get(id=member_id)

        if not Admin.objects.filter(member=mem, company=company).exists():
            new_admin = Admin(member=mem, company=company)
            new_admin.save()

        return redirect('profiles:members', company_name, member_name,)

    else:
        raise PermissionDenied
Пример #27
0
def addCastMem(request, company_name, member_name, cast_id):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)
        if Cast.objects.filter(id=cast_id).exists():
            cast = Cast.objects.get(id=cast_id)

            if request.method == 'POST':
                form = CastingForm(request.POST, company_name=company_name)
                if form.is_valid():
                    members = form.cleaned_data['members']
                    for member in members:
                        cast.member_set.add(member)

        return redirect('profiles:casts', company_name, member_name,)

    else:
        raise PermissionDenied
Пример #28
0
def casts(request, company_name, member_name):
    member = memberAuth(request, company_name, member_name)

    if member:
        company = Company.objects.get(name=company_name)
        admin = adminAuth(request, company_name, member_name)

        cast_list = Cast.objects.filter(company=company)
        choreographer_list = Choreographer.objects.filter(company=company)
        my_cast_list = Choreographer.objects.filter(company=company, member=member)
        # print my_cast_list
        # my_piece_list = member.cast.all()

        form = CastingForm(company_name=company_name)
        # form = UserForm()
        return render(request, 'profiles/casts.html', {'company':company, 'member':member, 'admin':admin, 'cast_list':cast_list, 'choreographer_list':choreographer_list, 'my_cast_list':my_cast_list, 'form':form})
    else:
        raise PermissionDenied
Пример #29
0
def updateCastName(request, company_name, member_name, cast_id):
    name = 'updates:updateCastName'

    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)
        member = admin.member

        if Cast.objects.filter(id=cast_id).exists():
            cast = Cast.objects.get(id=cast_id)

            # save casting data
            if request.method == 'POST':
                form = CastForm(request.POST, instance=cast)
                if form.is_valid():
                    form.save()
                    return redirect(
                        'profiles:casts',
                        company_name,
                        member_name,
                    )
            else:
                form = CastForm(instance=cast)
            return render(
                request, 'updates/update.html', {
                    'company': company,
                    'member': member,
                    'curr': cast,
                    'form': form,
                    'redirect_name': name
                })

        return redirect(
            'profiles:casts',
            company_name,
            member_name,
        )

    else:
        raise PermissionDenied
Пример #30
0
def deleteCast(request, company_name, member_name, cast_id):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        if Cast.objects.filter(id=cast_id).exists():
            cast = Cast.objects.get(id=cast_id)

            #unschedule the rehearsal, and delete the conflicts in cast mem
            rehearsal = cast.rehearsal
            rehearsal.is_scheduled = False
            rehearsal.save()

            members = Member.objects.filter(cast=cast)
            for mem in members:
                conflicts = mem.conflict_set.filter(
                    description__endswith="(%s)" % (cast.name))
                for r in conflicts:
                    r.delete()

            choreographers = Choreographer.objects.filter(cast=cast)
            for choreographer in choreographers:
                conflicts = choreographer.member.conflict_set.filter(
                    description__endswith="(%s)" % (cast.name))
                for r in conflicts:
                    r.delete()

            cast.delete()

            # check to see if company has any more casts
            casts = Cast.objects.filter(company__name=company_name)
            if len(casts) == 0:
                company = Company.objects.get(name=company_name)
                company.has_schedule = False
                company.save()

        return redirect(
            'profiles:casts',
            company_name,
            member_name,
        )
    else:
        raise PermissionDenied
Пример #31
0
def deleteMember(request, company_name, member_name, member_id):
    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        if Member.objects.filter(id=member_id).exists():
            old_member = Member.objects.get(id=member_id)

            # make sure you can only delete people who are in your company
            if old_member.groups.filter(name=company_name).exists() and admin.member != old_member:
                # delete person from company set
                company = Company.objects.get(name=company_name)
                company.user_set.remove(old_member)

                # if user is a student and is no longer associated with any companies, remove them from system to clear space
                if not old_member.has_usable_password() and old_member.groups.all().count() == 0:
                    old_member.delete()

        return redirect('profiles:members', company_name, member_name,)

    else:
        raise PermissionDenied
Пример #32
0
def updateRehearsal(request, company_name, member_name, rehearsal_id):
    name = 'updates:updateRehearsal'

    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)
        member = admin.member

        if company.rehearsal_set.filter(id=rehearsal_id).exists():
            rehearsal = company.rehearsal_set.get(id=rehearsal_id)

            # process the form and rehearsal data
            if request.method == 'POST':
                form = RehearsalForm(request.POST, instance=rehearsal)
                if form.is_valid():
                    form.save()

                    return redirect(
                        'profiles:spaces',
                        company_name,
                        member_name,
                    )
            else:
                form = RehearsalForm(instance=rehearsal)
            return render(
                request, 'updates/update.html', {
                    'company': company,
                    'member': member,
                    'curr': rehearsal,
                    'form': form,
                    'redirect_name': name
                })
        return redirect(
            'profiles:spaces',
            company_name,
            member_name,
        )
    else:
        raise PermissionDenied
Пример #33
0
def addAdmin(request, company_name, member_name, member_id):
    # check if valid admin
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)
        member = Member.objects.get(username=member_name)

        # get post data if available
        mem = Member.objects.get(id=member_id)

        if not Admin.objects.filter(member=mem, company=company).exists():
            new_admin = Admin(member=mem, company=company)
            new_admin.save()

        return redirect(
            'profiles:members',
            company_name,
            member_name,
        )

    else:
        raise PermissionDenied
Пример #34
0
def spaces(request, company_name, member_name):
    member = memberAuth(request, company_name, member_name)

    if member:
        company = Company.objects.get(name=company_name)
        admin = adminAuth(request, company_name, member_name)

        rehearsal_list = {}
        for rehearsal in company.rehearsal_set.all():
            try:
                rehearsal_list[rehearsal.day_of_week].append(rehearsal)
            # print rehearsal.day_of_week
            except KeyError:
                rehearsal_list[rehearsal.day_of_week] = []
                rehearsal_list[rehearsal.day_of_week].append(rehearsal)

        rehearsal_list = sorted(rehearsal_list.items(), key=lambda x: DOWs.index(x[0]))
        # print rehearsal_list
        # print rehearsal_list[0]

        return render(request, 'profiles/spaces.html', {'company':company, 'member':member, 'rehearsal_list':rehearsal_list, 'admin':admin})

    else:
        raise PermissionDenied
Пример #35
0
def confirmSchedule(request, company_name, member_name):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        if request.method == 'POST':
            # get cast and rehearsal lists
            rehearsals = request.POST.getlist('rehearsals')
            casts = request.POST.getlist('casts')

            rehearsal_list = []
            cast_list = []

            for rehearsal_id in rehearsals:
                rehearsal = Rehearsal.objects.get(id=rehearsal_id)
                rehearsal_list.append(rehearsal)

            for cast_id in casts:
                cast = Cast.objects.get(id=cast_id)
                cast_list.append(cast)

            errors = []
            warnings = []

            # check lengths
            if len(rehearsals) == 0:
                error = "You must select at least one rehearsal to be scheduled."
                errors.append(error)
            if len(casts) == 0:
                error = "You must select at least one cast to be scheduled."
                errors.append(error)
            if len(rehearsals) < len(casts):
                error = "In order to create a schedule, there must be at least as many rehearsals as casts. Right now you have more casts than rehearsals."
                errors.append(error)

            # # make sure availabeRehearsals >0 for all casts
            cast_error = ""
            cast_warning = ""
            for cast in cast_list:
                if len(cast.getAllRehearsals()) == 0:
                    c = " - " + cast.name
                    cast_error += c
                if cast.is_scheduled:
                    c = " - " + cast.name
                    cast_warning += c

            if '-' in cast_error:
                cast_error += ' -'
                errors.append("The following casts are not available for any rehearsals and cannot be scheduled:")
                errors.append(cast_error)
                errors.append('Consider asking members of the cast to adjust their conflicts.')
            if '-' in cast_warning:
                cast_warning += ' -'
                warnings.append("The following casts are currently scheduled for a rehearsal, and may not be scheduled unless you overwrite the current schedule.")
                warnings.append(cast_warning)
                warnings.append("If you would like to schedule an additional rehearsal for this cast, please do so from the scheduling page.")

            # make sure availabeCasts >0 for all rehearsals
            rehearsal_error = ""
            rehearsal_warning = ""
            for rehearsal in rehearsal_list:
                if len(rehearsal.getAllCasts()) == 0:
                    r = " - " + rehearsal.place + ", " + str(rehearsal.start_time) + " (" + rehearsal.day_of_week + ")"
                    rehearsal_error += r
                if rehearsal.is_scheduled:
                    r = " - " + rehearsal.place + ", " + str(rehearsal.start_time) + " (" + rehearsal.day_of_week + ")"
                    rehearsal_warning += r

            if '-' in rehearsal_error:
                rehearsal_error += ' -'
                errors.append("The following rehearsals do not work for any casts and cannot be scheduled:")
                errors.append(rehearsal_error)
                errors.append('Consider contacting PAC or switching rehearsal spaces with another company.')
            if '-' in rehearsal_warning:
                rehearsal_warning += ' -'
                warnings.append("The following rehearsals are currently assigned to a cast, and may not be scheduled unless you overwrite / delete the current schedule.")
                warnings.append(rehearsal_warning)

            # print errors
            if errors == []:
                errors = None

                # get the associated rehearsals and casts
                finalDict = {}
                finalDict["Rehearsals"] = rehearsal_list
                finalDict['Casts'] = cast_list

                # create scheduling form
                form = SchedulingForm(rehearsals=rehearsals, casts=casts)



            else:
                finalDict = None
                form = None

            if warnings == []:
                warnings = None

            # return render(request, 'profiles/makeschedule.html', {'company':company, 'member':admin.member, 'make_schedule':make_schedule})
            # print errors, finalDict


    
    # return redirect('profiles:scheduling', company_name, member_name,)
    return render(request, 'profiles/confirmschedule.html', {'company_name':company_name, 'member_name':member_name, 'errors':errors, 'warnings':warnings, 'dict':finalDict, 'form':form})
Пример #36
0
def parsePAC(request, company_name, member_name):
    if request.method == 'POST':
        admin = adminAuth(request, company_name, member_name)
        if admin:
            company = Company.objects.get(name=company_name)
            pub_url = request.POST['url']
            # print pub_url

            split_string = pub_url.split("d/")
            # print split_string

            calID = split_string[1].split('/')[0]
            # print calID

            # get info for each day of the week
            for day in range(1,8):
            # day = 6
                # JSON Representation to get headers
                html = get_json('cells', calID, day)
                format = get_col_headers(html)

                # JSON Representation to get data
                html = get_json('list', calID, day)

                dow = html['feed']['title']['$t'].encode('utf-8').strip()
                print dow[0:3]
                print '========================='
                last_company = {}
                for name in format:
                    last_company[name] = ['', -1]

                rehearsals = []
                rehearsals_index = 0

                for entry in html['feed']['entry']:
                    row = entry['content']['$t'].encode('utf-8').strip()
                    time = entry['title']['$t'].encode('utf-8').strip()

                    for name in format:
                        result = getRowValue(row, format, name)
                        # print "%s, %s:%s" % (time, name, result)
                        # print result
                        # print result, last_company[name]
                        if result != last_company[name][0]:
                            index = last_company[name][1]
                            if index != -1:
                                t = time.split('-')[0]
                                end = datetime.strptime(t, "%I:%M%p")
                                rehearsals[index].end_time = end.time()
                                last_company[name][1] = -1
                                # print 'add end time to rehearsal in %s' % name

                            if company_name in result:
                                #create new rehearsal
                                t = time.split('-')[0]
                                start = datetime.strptime(t, "%I:%M%p")
                                rehearsal = Rehearsal(company=company, day_of_week=dow[0:3], place=name, start_time=start.time())
                                # print rehearsal, rehearsals_index
                                #append to rehearsals
                                rehearsals.append(rehearsal)
                                last_company[name][1] = rehearsals_index
                                rehearsals_index += 1
                                
                                # print "create rehearsal"
                                # print start.time()

                            # print "Time:%s %s:%s" % (time, name, result)
                            last_company[name][0] = result

                # print rehearsals
                for rehearsal in rehearsals:
                    if rehearsal.end_time == None:
                        rehearsal.end_time = datetime.strptime('1:00am', "%I:%M%p").time()
                    print rehearsal
                    rehearsal.save()

    return redirect('profiles:spaces', company_name, member_name,)
Пример #37
0
def makeSchedule(request, company_name, member_name):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        # get dict
        if request.method =='POST':
            form = SchedulingForm(request.POST)
            if form.is_valid():
                try:
                    if request.POST['override']:
                        override = True
                except Exception:
                    override = False

                print "Override:", override
                # get rehearsals and casts to be scheduled
                rehearsals = form.cleaned_data['rehearsals']
                casts = form.cleaned_data['casts']
                # print casts, "\n", rehearsals

                # if user elected to override rehearsals, unschedule any rehearsals that are already scheduled
                company = Company.objects.get(name=company_name)
                if override:
                    dict = unscheduleRehearsals(company_name, rehearsals, casts)
                    rehearsals = dict["Rehearsals"]
                    casts = dict["Casts"]
                
                # otherwise, remove any already scheduled casts from the list of casts to be scheduled
                else:
                    casts = casts.exclude(is_scheduled=True)

                for rehearsal in rehearsals:
                    print rehearsal.is_scheduled, rehearsal
                for cast in casts:
                    print cast.is_scheduled, cast

                print "======================"

                # save the casts that are scheduled
                scheduled_casts = []
                scheduled_rehearsals = []
                # begin scheduling casts
                for cast in casts:
                    print "\n\n"
                    # get all unscheduled rehearsals with least number of available casts (greater than 0)
                    min = len(Cast.objects.filter(company=company))
                    for rehearsal in rehearsals:
                        print rehearsal, rehearsal.is_scheduled
                        if rehearsal.is_scheduled == False:
                            n = len(rehearsal.getAvailableCasts())
                            print n, rehearsal
                            if n > 0 and n <= min:
                                min = n
                    print "Least # of available casts:\n", min

                    rehearsal_list = []
                    for rehearsal in rehearsals:
                        if rehearsal.is_scheduled == False and len(rehearsal.getAvailableCasts()) == min:
                            rehearsal_list.append(rehearsal)

                    print "Unscheduled rehearsals with least # of available casts:\n", rehearsal_list
                    # if rehearsal_list == []:
                    #     company.has_schedule = False
                    #     unscheduleRehearsals(company_name, scheduled_rehearsals, scheduled_casts)
                    #     company.save()
                    #     return HttpResponse("Could not complete scheduling. <p>Please return to the <a href='/%s/%s/schedule'>scheduling page</a> to unschedule rehearsals / overwrite old schedule in order to complete this scheduling request.</p>" % (company_name, member_name))


                    # get all unscheduled casts available during rehearsals above
                    # pick the ones with least number of available rehearsals
                    min = len(Rehearsal.objects.filter(company=company))
                    print min
                    for rehearsal in rehearsal_list:
                        available_casts = rehearsal.getAvailableCasts()
                        for cast in available_casts:
                            if cast in casts:
                                print cast.is_scheduled, cast
                                if cast.is_scheduled == False:
                                    n = len(cast.getAvailableRehearsals())
                                    if n > 0 and n <= min:
                                        print n, cast
                                        min = n

                    print "Least # of available rehearsals\n", min

                    # create scheduling options for casts with min number found above
                    options = {}
                    for rehearsal in rehearsal_list:
                        available_casts = rehearsal.getAvailableCasts()
                        for cast in available_casts:
                            if cast in casts:
                                if cast.is_scheduled == False and len(cast.getAvailableRehearsals()) == min:
                                    try:
                                        options[cast].append(rehearsal)
                                    except:
                                        options[cast] = []
                                        options[cast].append(rehearsal)

                    print "Scheduling options based on rehearsals and casts above:\n", options

                    if options != {}:
                        # randomly pick a cast from the options
                        cast = random.choice(options.keys())

                        print "Randomly chosen cast:\n", cast

                        rehearsal = random.choice(options[cast])
                        print "Randomly chosen rehearsal:\n", rehearsal

                        # print cast
                        # print options[cast]


                        # schedule the cast to its respective rehearsal
                        cast.scheduleRehearsal(rehearsal)
                        rehearsal.is_scheduled = True
                        cast.save()
                        rehearsal.save()

                        scheduled_casts.append(cast)
                        scheduled_rehearsals.append(rehearsal)

                        print "Is cast scheduled?"
                        print cast.is_scheduled

                    else:
                        # if cannot complete schedule for some reason
                        unscheduleRehearsals(company_name, scheduled_rehearsals, scheduled_casts)
                        if override:
                            company.has_schedule = False
                        company.save()
                        return HttpResponse("Something went wrong! Could not complete schedule. <p>Please make sure the rehearsal(s)/cast(s) you are trying to schedule are not already scheduled. If rehearsal(s)/cast(s) are free, please ask members to adjust their conflicts.</p><a href='/%s/%s'>Return to Hub</a> or <a href='/%s/%s/schedule'>Return to Scheduling</a>" % (company_name, member_name, company_name, member_name))
                        # return HttpResponse("Something went wrong! Could not complete schedule. <p>Make sure you are not trying to schedule casts for rehearsal times that all cast members cannot make (the schedule will not allow this). If you would like to schedule a cast for a specific rehearsal time, regardless of conflicts, please ask members to adjust their conflicts, then return to the <a href='/%s/%s/schedule'>scheduling page</a> to re-schedule the %s rehearsal(s)/cast(s)</p>" % (company_name, member_name, company_name))

                company.has_schedule = True
                company.save()

        return redirect('profiles:scheduling', company_name, member_name,)

    else:
        raise PermissionDenied
Пример #38
0
def addStudents(request, company_name, member_name):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)

        if request.method == 'POST':
            # check if there are any 'students' being inputted
            student_list = request.POST['student_list']
            student_list = [l for l in student_list.split("\n") if l]

            # initialize error message for any processing errors
            error_message = "The following lines could not be processed:"

            for line in student_list:
                info = line.split()

                # make sure line is specified length
                if len(info) != 3:
                    error = "\n" + line + " (Each line should have exactly 3 words)"
                    error_message += error
                    continue

                # check to see if you have email or username
                if '@' in info[0]:
                    email = info[0].split('@')
                    if email[1].lower() != 'princeton.edu':
                        # print line
                        error = "\n" + line + " (First word in line must be a NetID or a valid Princeton email address)"
                        error_message += error
                        continue
                    username = email[0]
                else:
                    username = info[0]

                print username, info[1], info[2]

                # check if the member already exists
                if Member.objects.filter(username=username).exists():
                    member = Member.objects.get(username=username)
                    # check if there is a  member with the same username in this group
                    if member.groups.filter(name=company_name).exists():
                        # print "checkpoint2"
                        # if student
                        if not member.has_usable_password():
                            error = "\n" + line + " (There is already a member of this company with this username)"
                            error_message += error
                            continue
                        # if not student
                        else:
                            # change the 'nonstudents' username
                            member.username = "******" % (username, Member.objects.count())
                            member.save()
                            # print member.username
                    
                    # if member is not a part of this group
                    else:
                        # add them to this company
                        member.groups.add(company)
                        member.save()
                        continue

                # add the member to the company
                mem = Member(username=username, first_name=info[1], last_name=info[2], email="*****@*****.**" % username)
                mem.set_unusable_password()
                mem.save()
                mem.groups.add(company)

            if "\n" in error_message:
                print error_message
        return redirect('profiles:members', company_name, member_name,)

    else:
        raise PermissionDenied
Пример #39
0
def addStudents(request, company_name, member_name):
    admin = adminAuth(request, company_name, member_name)
    if admin:
        company = Company.objects.get(name=company_name)

        if request.method == 'POST':
            # check if there are any 'students' being inputted
            student_list = request.POST['student_list']
            student_list = [l for l in student_list.split("\n") if l]

            # initialize error message for any processing errors
            error_message = "The following lines could not be processed:"

            for line in student_list:
                info = line.split()

                # make sure line is specified length
                if len(info) != 3:
                    error = "\n" + line + " (Each line should have exactly 3 words)"
                    error_message += error
                    continue

                # check to see if you have email or username
                if '@' in info[0]:
                    email = info[0].split('@')
                    if email[1].lower() != 'princeton.edu':
                        # print line
                        error = "\n" + line + " (First word in line must be a NetID or a valid Princeton email address)"
                        error_message += error
                        continue
                    username = email[0]
                else:
                    username = info[0]

                print username, info[1], info[2]

                # check if the member already exists
                if Member.objects.filter(username=username).exists():
                    member = Member.objects.get(username=username)
                    # check if there is a  member with the same username in this group
                    if member.groups.filter(name=company_name).exists():
                        # print "checkpoint2"
                        # if student
                        if not member.has_usable_password():
                            error = "\n" + line + " (There is already a member of this company with this username)"
                            error_message += error
                            continue
                        # if not student
                        else:
                            # change the 'nonstudents' username
                            member.username = "******" % (username,
                                                        Member.objects.count())
                            member.save()
                            # print member.username

                    # if member is not a part of this group
                    else:
                        # add them to this company
                        member.groups.add(company)
                        member.save()
                        continue

                # add the member to the company
                mem = Member(username=username,
                             first_name=info[1],
                             last_name=info[2],
                             email="*****@*****.**" % username)
                mem.set_unusable_password()
                mem.save()
                mem.groups.add(company)

            if "\n" in error_message:
                print error_message
        return redirect(
            'profiles:members',
            company_name,
            member_name,
        )

    else:
        raise PermissionDenied