예제 #1
0
파일: views.py 프로젝트: stanri/caesar-web
def bulk_add(request):
  if request.method == 'GET':
    form = UserBulkAddForm()
    return render(request, 'accounts/bulk_add_form.html', {
      'form': form
    })
  else: # bulk adding time
    form = UserBulkAddForm(request.POST)
    if not form.is_valid():
      return render(request, 'accounts/bulk_add_form.html', {
        'form': form,
        'message': 'Invalid form. Are you missing a field?'})

    # todo(mglidden): use a regex instead of three replace statements
    users = form.cleaned_data['users'].replace(' ', ',').replace('\t', ',').replace('\r\n', ',').replace('\n', ',').replace(', ', ',').split(',')

    semester = form.cleaned_data['semester']

    existing_users = 0; created_users = 0; existing_memberships = 0; created_memberships = 0;

    for user_str in users:
      if '@' in user_str:
        user_email = user_str
        user_str = user_email[:user_email.index('@')]
      else:
        user_email = user_str + '@mit.edu'

      # In production, we should never have more than one user for a given email. The dev DB has some bad data, so we're using filter instead of get.
      # We filter by username since that's the unique key.
      users = User.objects.filter(username=user_str)
      if users:
        user = users[0]
        existing_users += 1
      else:
        user = User(username=user_str, email=user_email)
        user.save()
        user.profile.role = 'S'
        user.profile.save()
        created_users += 1

      if not user.membership.filter(semester=semester):
        membership = Member(role=Member.STUDENT, user=user, semester=semester)
        membership.save()
        created_memberships += 1
      else:
        existing_memberships += 1

    return render(request, 'accounts/bulk_add_form.html', {
      'form': form,
      'message': 'Created %s users, %s already existed. Added %s users to %s, %s were already members.' % (created_users, existing_users, created_memberships, semester, existing_memberships),
      })
def addplayer(request, id):
    account = AccountType.objects.get(id=id)
    group = Group.objects.get(name=account.membership_type)
    instance = Member()
    if request.method == "POST":
        form = PlayerCreationForm(request.POST)
        if form.is_valid():
            user = form.save()
            group.user_set.add(user)
            instance.player = user
            instance.member_group = group
            instance.created_by = request.user
            instance.save()
            return redirect('manage_players')
    else:
        form = PlayerCreationForm()
    return render(request, 'application/add_player.html', {'account':account, 'form':form})
예제 #3
0
파일: views.py 프로젝트: stanri/caesar-web
def edit_membership(request):
    """Allow users to enroll in classes."""
    user = request.user
    enrolled_classes = request.user.membership

    if request.method == "POST":
        # handle ajax post to this url
        semester_id = request.POST['semester_id']
        semester = Semester.objects.get(pk=semester_id)

        if request.POST['enrolled']=='True':
            m = request.user.membership.filter(semester=semester)
            m.delete()
        else:
            m = Member(user=request.user, role=Member.VOLUNTEER, semester=semester)
            m.save()

    return render(request, 'accounts/edit_membership.html', {
        'semesters': Semester.objects.filter(is_current_semester=True),
        'enrolled_classes': enrolled_classes,
    })
예제 #4
0
def edit_membership(request):
    """Allow users to enroll in classes."""
    user = request.user
    enrolled_classes = request.user.membership

    if request.method == "POST":
        # handle ajax post to this url
        semester_id = request.POST['semester_id']
        semester = Semester.objects.get(pk=semester_id)

        if request.POST['enrolled'] == 'True':
            m = request.user.membership.filter(semester=semester)
            m.delete()
        else:
            m = Member(user=request.user,
                       role=Member.VOLUNTEER,
                       semester=semester)
            m.save()

    return render(
        request, 'accounts/edit_membership.html', {
            'semesters': Semester.objects.filter(is_current_semester=True),
            'enrolled_classes': enrolled_classes,
        })
예제 #5
0
def bulk_add(request):
    if request.method == 'GET':
        form = UserBulkAddForm()
        return render(request, 'accounts/bulk_add_form.html', {'form': form})
    else:  # bulk adding time
        form = UserBulkAddForm(request.POST)
        if not form.is_valid():
            return render(request, 'accounts/bulk_add_form.html', {
                'form': form,
                'message': 'Invalid form. Are you missing a field?'
            })

        # todo(mglidden): use a regex instead of three replace statements
        users = form.cleaned_data['users'].replace(' ', ',').replace(
            '\t', ',').replace('\r\n',
                               ',').replace('\n', ',').replace(', ',
                                                               ',').split(',')

        semester = form.cleaned_data['semester']

        existing_users = 0
        created_users = 0
        existing_memberships = 0
        created_memberships = 0

        for user_str in users:
            if '@' in user_str:
                user_email = user_str
                user_str = user_email[:user_email.index('@')]
            else:
                user_email = user_str + '@mit.edu'

            # In production, we should never have more than one user for a given email. The dev DB has some bad data, so we're using filter instead of get.
            # We filter by username since that's the unique key.
            users = User.objects.filter(username=user_str)
            if users:
                user = users[0]
                existing_users += 1
            else:
                user = User(username=user_str, email=user_email)
                user.save()
                user.profile.role = 'S'
                user.profile.save()
                created_users += 1

            if not user.membership.filter(semester=semester):
                membership = Member(role=Member.STUDENT,
                                    user=user,
                                    semester=semester)
                membership.save()
                created_memberships += 1
            else:
                existing_memberships += 1

        return render(
            request, 'accounts/bulk_add_form.html', {
                'form':
                form,
                'message':
                'Created %s users, %s already existed. Added %s users to %s, %s were already members.'
                % (created_users, existing_users, created_memberships,
                   semester, existing_memberships),
            })
예제 #6
0
# create a SubmitMilestone
submit_milestone = SubmitMilestone(assignment=assignment,name="submit_milestone")
submit_milestone.save()
# create a ReviewMilestone
review_milestone = ReviewMilestone(assignment=assignment,submit_milestone=submit_milestone,name="review_milestone")
review_milestone.save()

chunk_to_copy = Chunk.objects.filter(student_lines__gte=5)[0]
file_to_copy = chunk_to_copy.file
# make all the users members of the class
# create a Submission for every member in the class
for m in semester_members:
	roles = [Member.STUDENT, Member.STUDENT, Member.TEACHER, Member.VOLUNTEER]
	member = Member(semester=semester,user=m,role=roles[m.id%4])
	# member = Member(semester=semester,user=m,role=Member.STUDENT)
	member.save()
	m.membership.add(member)
	m.save()
	semester.members.add(member)
	semester.save()
	submission = Submission(milestone=submit_milestone,name="submission_"+m.username)
	submission.pk = None
	# submission.milestone_id = submit_milestone.id
	submission.save()
	submission.authors.add(m)
	submission.save()
	# create 8 files that each have 1 chunk
	for i in range(8):
		file = file_to_copy
		file.pk = None
		file.submission = submission