예제 #1
0
파일: views.py 프로젝트: mmusbah/myewb2
def create_work_record(request, username, object=None):
    form = WorkRecordForm(request.POST)
    other_user = User.objects.get(username=username)
    if form.is_valid():
        work_record = form.save(commit=False)
        work_record.user = other_user
        
        employer = form.cleaned_data['employer']
        # find network ID (based on name they entered)
        # TODO: remove from network when someone ends their employment
        networks = Network.objects.filter(name=employer)
        # networks = networks.filter(network_type='C')
        
        if networks.count() == 0:
            # FIXME: this is duplicated in networks.views.networks_index
            # (refactor to centralize)
            # also kinda dupicated below, create_work_record
            network = Network(network_type='C', slug=employer,
                              name=employer,
                              creator=other_user)
            network.save()
        else:
            network = networks[0]

        # FIXME this should be implemented as a signal - profiles should not know about GroupMember
        existing_members=network.members.filter(user=other_user)
        if existing_members.count() == 0:
            network_member = GroupMember(group=network, user=other_user, is_admin=False)
            network.members.add(network_member)
            network_member.save()

        work_record.network = network
        
        work_record.save()
        return HttpResponseRedirect(reverse('profile_detail', kwargs={'username': other_user.username }))

    else:
        return render_to_response(
                'profiles/new_work_record.html',
                {
                'form': form,
                'other_user': other_user,
                },
                context_instance=RequestContext(request)
                )
예제 #2
0
파일: views.py 프로젝트: mmusbah/myewb2
def create_student_record(request, username, object=None):
    form = StudentRecordForm(request.POST)
    other_user = User.objects.get(username=username)
    if form.is_valid():
        student_record = form.save(commit=False)
        student_record.user = other_user
        
        # find network ID (based on name they entered)
        # TODO: remove from network when someone ends their employment
        institution = form.cleaned_data['institution']
        networks = Network.objects.filter(name=institution)
        # networks = networks.filter(network_type='U')
        
        if networks.count() == 0:
            network = Network(network_type='U', slug=institution,
                              name=institution,
                              creator=other_user)
            network.save()
        else:
            network = networks[0]

        # FIXME this should be implemented as a signal - profiles should not know about GroupMember
        existing_members=network.members.filter(user=other_user)
        if existing_members.count() == 0:
            network_member = GroupMember(group=network, user=other_user, is_admin=False)
            network.members.add(network_member)
            network_member.save()

        student_record.network = network
        
        student_record.save()
        return HttpResponseRedirect(reverse('profile_detail', kwargs={'username': other_user.username }))
        
    else:
        return render_to_response(
                'profiles/new_student_record.html',
                {
                'form': form,
                'other_user': other_user,
                },
                context_instance=RequestContext(request)
                )