Exemplo n.º 1
0
def edit_electee_process_visibility(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit the electee process visibility settings.'
        return redirect('electees:view_electee_groups')
    current_vis = ElecteeProcessVisibility.objects.get_or_create(term=AcademicTerm.get_current_term())
    VisibilityForm = modelform_factory(ElecteeProcessVisibility,exclude=['term'])
    prefix='visibility'
    form = VisibilityForm(request.POST or None ,prefix=prefix,instance=current_vis[0])
    if request.method =='POST':
        if form.is_valid():
            form.save()
            request.session['success_message']='Electee settings updated successfully'
            return redirect('electees:manage_survey')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'

    template = loader.get_template('generic_form.html')
    context_dict = {
        'form':form,
        'prefix':prefix,
        'has_files':False,
        'submit_name':'Update Visibility Settings',
        'form_title':'Update Electee Visibility Settings for %s'%(unicode(AcademicTerm.get_current_term())),
        'help_text':'Change whether certain electee items are visible to all actives.',
        'base':'electees/base_electees.html',
        'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
Exemplo n.º 2
0
def outreach_event(request, url_stem):
    request.session['current_page'] = request.path
    outreach_event = get_object_or_404(OutreachEventType, url_stem=url_stem)
    relevant_officers = Officer.objects.filter(
        user__uniqname=request.user.username,
        term=AcademicTerm.get_current_term(),
        position__in=outreach_event.officers_can_edit.all())
    events = CalendarEvent.objects.filter(
        term=AcademicTerm.get_current_term(),
        event_type=outreach_event.event_category,
        eventshift__end_time__gte=timezone.now()).annotate(earliest_shift=Min(
            'eventshift__start_time')).order_by('earliest_shift')
    template = loader.get_template('outreach/outreach_template.html')
    context_dict = {
        'events':
        events,
        'subnav':
        url_stem,
        'title':
        outreach_event.title,
        'text':
        outreach_event.text,
        'has_cal_events':
        outreach_event.has_calendar_events,
        'event_category':
        outreach_event.event_category.name,
        'can_edit_outreach_event': (request.user.is_superuser
                                    or relevant_officers.exists()),
        'event_timeline':
        outreach_event.outreachevent_set.all().order_by('-pin_to_top', '-id'),
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
Exemplo n.º 3
0
def outreach_event(request, url_stem):
    request.session['current_page'] = request.path
    outreach_event = get_object_or_404(OutreachEventType, url_stem=url_stem)
    relevant_officers = Officer.objects.filter(
                    user__uniqname=request.user.username,
                    term=AcademicTerm.get_current_term(),
                    position__in=outreach_event.officers_can_edit.all()
    )
    events = CalendarEvent.objects.filter(
                    term=AcademicTerm.get_current_term(),
                    event_type=outreach_event.event_category,
                    eventshift__end_time__gte=timezone.now()
    ).annotate(
        earliest_shift=Min('eventshift__start_time')
    ).order_by('earliest_shift')
    template = loader.get_template('outreach/outreach_template.html')
    context_dict = {
        'events': events,
        'subnav': url_stem,
        'title': outreach_event.title,
        'text': outreach_event.text,
        'has_cal_events': outreach_event.has_calendar_events,
        'event_category': outreach_event.event_category.name,
        'can_edit_outreach_event': (request.user.is_superuser or
                                    relevant_officers.exists()),
        'event_timeline': outreach_event.outreachevent_set.all().order_by(
                                                    '-pin_to_top',
                                                    '-id'
        ),
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Exemplo n.º 4
0
 def test_officer_ajax(self):
     old_term = AcademicTerm.objects.get(semester_type__name='Fall',
                                         year=2012)
     current_term = AcademicTerm.get_current_term()
     officers = Officer.objects.all()
     officers[2].term.clear()
     officers[2].term.add(old_term)
     for officer in officers:
         view_url = reverse('about:officer', args=[officer.id])
         resp = self.client.get(view_url,
                                HTTP_X_REQUESTED_WITH='XMLHttpRequest')
         self.assertEqual(resp.status_code, 200)
         position = unicode(officer.position)
         if officer.position.name == 'Advisor':
             self.assertFalse(position in resp.content,
                              msg='%s name is in response.' % position)
         else:
             self.assertTrue(position in resp.content,
                             msg='%s name not in response' % position)
         officer_name = officer.user.get_firstlast_name()
         self.assertTrue(officer_name in resp.content,
                         msg='%s user name not in response' % position)
         if (current_term in officer.term.all()) and not\
            (position == 'Advisor'):
             self.assertTrue(officer.position.email in resp.content,
                             msg='%s position email absent' % position)
             self.assertFalse(officer.user.get_email() in resp.content,
                              msg='%s user email present' % position)
         else:
             self.assertFalse(officer.position.email in resp.content,
                              msg='%s position email present' % position)
             self.assertTrue(officer.user.get_email() in resp.content,
                             msg='%s personal email absent' % position)
     officers[2].term.clear()
     officers[2].term.add(AcademicTerm.get_current_term())
Exemplo n.º 5
0
def get_members(init_term=None, include_electees=True,include_stopped_electing=False,include_actives=True,include_grads=True,include_ugrads=True,include_alums=False,only_around=False,only_active_status=False,only_da=False,only_pa=False):
    members = MemberProfile.objects.all()

    #handle status partitions
    if not include_electees:
        members=members.exclude(status__name='Electee')
    elif not include_stopped_electing:
        members=members.exclude(still_electing=False,status__name='Electee')
    if not include_actives:
        members=members.exclude(status__name='Active')
    #handle standing partitions
    if not include_grads:
        members=members.exclude(standing__name="Graduate")
    if not include_ugrads:
        members=members.exclude(standing__name='Undergraduate')
    if not include_alums:
        members=members.exclude(standing__name='Alumni')
    last_two_terms = [AcademicTerm.get_current_term(), get_previous_full_term(AcademicTerm.get_current_term())]
    if only_around:
        recent_progress=ProgressItem.objects.filter(term__in=last_two_terms)
        members=members.filter(progressitem__in=recent_progress)
    if only_active_status:
        recent_active = Distinction.objects.filter(term__in=last_two_terms,distinction_type__name='Active')
        members=members.filter(distinction__in=recent_active)
    if only_da:
        recent_active = Distinction.objects.filter(term__in=last_two_terms,distinction_type__name='Distinguished Active')
        members=members.filter(distinction__in=recent_active)
    if only_pa:
        recent_active = Distinction.objects.filter(term__in=last_two_terms,distinction_type__name='Prestigious Active')
        members=members.filter(distinction__in=recent_active)
    if init_term:
        members=members.filter(init_term=init_term,init_chapter__state='MI',init_chapter__letter='G')

    return members.distinct()
Exemplo n.º 6
0
def leadership_for_term(request, term_id):
    """
    Shows the officers for the specified term. The packing logic that assembles
    officers into teams for dispaly is contained in the pack_officers_for_term
    function.
    """
    term = get_object_or_404(AcademicTerm, id=term_id)
    officers = pack_officers_for_term(AcademicTerm.objects.get(id=term_id))
    officer_set = Officer.objects.filter(term=term).values('id')
    template = loader.get_template('about/leadership.html')

    context_dict = {
        "officers": officers,
        'committee_members': CommitteeMember.objects.filter(term=term),
        'officer_ids': officer_set,
        'request': request,
        'terms': AcademicTerm.get_rchron_before()[:5],
        'requested_term': term,
        'is_current': (term_id == AcademicTerm.get_current_term().id),
        'subnav': 'leadership',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Exemplo n.º 7
0
def manually_edit_electee_group_membership(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee teams'
        return redirect('electees:view_electee_groups')
    e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
    prefix = 'manual_groups'
    term =AcademicTerm.get_current_term()
    formset=ManualElecteeGroupMembersFormSet(request.POST or None,prefix=prefix,queryset=ElecteeGroup.objects.filter(term=term))
    if request.method=='POST':
        if formset.is_valid():
            formset.save()
            request.session['success_message']='Electee team membership updated successfully'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':prefix,
        'subsubnav':'members',
        'has_files':False,
        'submit_name':'Update Electee Team Membership',
        'form_title':'Add Electee Team Members',
        'help_text':'Add members to electee teams. This is for initial addition only, for edits use the drag-and-drop interface.',
        'can_add_row':False,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
Exemplo n.º 8
0
def manually_edit_electee_group_membership(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee teams'
        return redirect('electees:view_electee_groups')
    e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
    prefix = 'manual_groups'
    term =AcademicTerm.get_current_term()
    formset=ManualElecteeGroupMembersFormSet(request.POST or None,prefix=prefix,queryset=ElecteeGroup.objects.filter(term=term))
    if request.method=='POST':
        if formset.is_valid():
            formset.save()
            request.session['success_message']='Electee team membership updated successfully'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':prefix,
        'subsubnav':'members',
        'has_files':False,
        'submit_name':'Update Electee Team Membership',
        'form_title':'Add Electee Team Members',
        'help_text':'Add members to electee teams. This is for initial addition only, for edits use the drag-and-drop interface.',
        'can_add_row':False,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Exemplo n.º 9
0
def edit_electee_process_visibility(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit the electee process visibility settings.'
        return redirect('electees:view_electee_groups')
    current_vis = ElecteeProcessVisibility.objects.get_or_create(term=AcademicTerm.get_current_term())
    VisibilityForm = modelform_factory(ElecteeProcessVisibility,exclude=['term'])
    prefix='visibility'
    form = VisibilityForm(request.POST or None ,prefix=prefix,instance=current_vis[0])
    if request.method =='POST':
        if form.is_valid():
            form.save()
            request.session['success_message']='Electee settings updated successfully'
            return redirect('electees:manage_survey')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'

    template = loader.get_template('generic_form.html')
    context_dict = {
        'form':form,
        'prefix':prefix,
        'has_files':False,
        'submit_name':'Update Visibility Settings',
        'form_title':'Update Electee Visibility Settings for %s'%(unicode(AcademicTerm.get_current_term())),
        'help_text':'Change whether certain electee items are visible to all actives.',
        'base':'electees/base_electees.html',
        'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))  
Exemplo n.º 10
0
def update_person(request):
    """ If person exists, pre-fill information
    If person has profile but not BS profile, pre-fill some of it, and on
    submit link together
    If person has nothing, will need to create and link everything on submit 
    """
    if not Permissions.can_process_bookswap(request.user):
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM
        return get_previous_page(request, alternate='bookswap:admin_index')
    had_profile = request.session.pop('had_profile', False)
    uniqname = request.session.pop('uniqname', '')
    if had_profile:
        bsp = BookSwapPerson.objects.get(user_profile__uniqname=uniqname)
        form = BookSwapPersonForm(request.POST or None, instance=bsp)
    else:
        initial = {
            'UMID': request.session.pop('UMID', ''),
            'uniqname': uniqname,
            'barcode': request.session.pop('barcode', ''),
        }
        form = BookSwapPersonFormNoProfile(request.POST or None, initial=initial)
        
    if request.method == 'POST':
        if form.is_valid():
            bsp = form.save()
            uniqname = bsp.user_profile.uniqname
            request.session['success_message'] = ('User created/updated.')
            if BookSwapStatus.can_receive(AcademicTerm.get_current_term()):
                return redirect('bookswap:receive_book_start', uniqname=uniqname)
            elif BookSwapStatus.can_sell(AcademicTerm.get_current_term()):
                return redirect('bookswap:sell_book_start', uniqname=uniqname)
            else:
                request.session['info_message'] = ('Book Swap not open for '
                                                   'receiving or selling')
                return redirect('bookswap:admin_index')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
            request.session['had_profile'] = had_profile
            request.session['uniqname'] = uniqname
    else:
        request.session['had_profile'] = had_profile
        request.session['uniqname'] = uniqname
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form': form,
        'subnav': 'admin',
        'has_files': False,
        'submit_name': 'Create/update user',
        'form_title': 'Create/update the user information',
        'help_text': ('Please confirm that the following is correct and '
                      'update as necessary. Note that for sellers an address '
                      'is required.'),
        'base': 'bookswap/base_bookswap.html',
        }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Exemplo n.º 11
0
def get_members(init_term=None,
                include_electees=True,
                include_stopped_electing=False,
                include_actives=True,
                include_grads=True,
                include_ugrads=True,
                include_alums=False,
                only_around=False,
                only_active_status=False,
                only_da=False,
                only_pa=False):
    members = MemberProfile.objects.all()

    # handle status partitions
    if not include_electees:
        members = members.exclude(status__name='Electee')
    elif not include_stopped_electing:
        members = members.exclude(still_electing=False, status__name='Electee')
    if not include_actives:
        members = members.exclude(status__name='Active')
    # handle standing partitions
    if not include_grads:
        members = members.exclude(standing__name="Graduate")
    if not include_ugrads:
        members = members.exclude(standing__name='Undergraduate')
    if not include_alums:
        members = members.exclude(standing__name='Alumni')
    last_two_terms = [
        AcademicTerm.get_current_term(),
        AcademicTerm.get_current_term().get_previous_full_term()
    ]
    if only_around:
        recent_progress = ProgressItem.objects.filter(term__in=last_two_terms)
        members = members.filter(progressitem__in=recent_progress)
    if only_active_status:
        recent_active = Distinction.objects.filter(
            term__in=last_two_terms, distinction_type__name='Active')
        members = members.filter(distinction__in=recent_active)
    if only_da:
        recent_active = Distinction.objects.filter(
            term__in=last_two_terms,
            distinction_type__name='Distinguished Active')
        members = members.filter(distinction__in=recent_active)
    if only_pa:
        recent_active = Distinction.objects.filter(
            term__in=last_two_terms,
            distinction_type__name='Prestigious Active')
        members = members.filter(distinction__in=recent_active)
    if init_term:
        members = members.filter(init_term=init_term,
                                 init_chapter__state='MI',
                                 init_chapter__letter='G')

    return members.distinct()
Exemplo n.º 12
0
class MeetingMinutesForm(forms.ModelForm):
    """ Form for submitting meeting minutes"""
    semester = forms.ModelChoiceField(widget=Select2Widget(),
                                      queryset=AcademicTerm.get_rchron(),
                                      initial=AcademicTerm.get_current_term())

    class Meta:
        model = MeetingMinutes
        fields = [
            'pdf_file', 'meeting_type', 'semester', 'meeting_name',
            'display_order'
        ]
Exemplo n.º 13
0
def mindset(request):
    request.session['current_page']=request.path
    template = loader.get_template('outreach/MindSET.html')
    k_12_officers = Officer.objects.filter(position__name='K-12 Outreach Officer').order_by('-term__year','term__semester_type__name')
    officers_unique=[]
    id_set = set()
    positions=OfficerPosition.objects.filter(name='K-12 Outreach Officer')
    current_officers=k_12_officers.filter(term=AcademicTerm.get_current_term())

    if positions.exists:
        position=positions[0]
    else:
        position=None
    for officer in k_12_officers:
        if officer.user.uniqname in id_set:
            continue
        else:
            id_set|=set([officer.user.uniqname])
            if not current_officers.filter(user__uniqname=officer.user.uniqname).exists():
                officers_unique.append(officer)

    mindset_main_photo = OutreachPhoto.objects.filter(photo_type__name='MindSET_Main')
    mindset_slideshow_photos = OutreachPhoto.objects.filter(photo_type__name='MindSET_Slideshow',active=True)
    if mindset_main_photo.exists():
        main_photo=mindset_main_photo[0]
    else:
        main_photo=None
    mindset_parking_photo = OutreachPhoto.objects.filter(photo_type__name='MindSET_Map')
    if mindset_parking_photo.exists():
        parking_photo=mindset_parking_photo[0]
    else:
        parking_photo=None
    events = CalendarEvent.objects.filter(term=AcademicTerm.get_current_term(),event_type__name='MindSET').annotate(earliest_shift=Min('eventshift__start_time')).order_by('earliest_shift')
    context_dict = {
            'events':events,
            'main_photo':main_photo,
            'parking_photo':parking_photo,
            'modules':MindSETModule.objects.all(),
            'k_12_officers':officers_unique,
            'position':position,
            'current_officers':current_officers,
            'volunteer_files':VolunteerFile.objects.all(),
            'slideshow_photos':mindset_slideshow_photos,
            'subnav':'mindset',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Exemplo n.º 14
0
def get_next_full_term(term):
    new_type = None
    new_year = 0
    if term.semester_type.name == "Fall":
        new_year = term.year + 1
        new_type = SemesterType.objects.get(name="Winter")
    else:
        new_year = term.year
        new_type = SemesterType.objects.get(name="Fall")
    if AcademicTerm.objects.filter(year=new_year, semester_type=new_type).exists():
        return AcademicTerm.objects.get(year=new_year, semester_type=new_type)
    else:
        a = AcademicTerm(year=new_year, semester_type=new_type)
        a.save()
        return a
Exemplo n.º 15
0
def get_previous_full_term(term):
    new_type = None
    new_year = 0;
    if term.semester_type.name=='Winter':
        new_year=term.year-1
        new_type = SemesterType.objects.get(name='Fall')
    else:
        new_year = term.year
        new_type = SemesterType.objects.get(name='Winter')
    if AcademicTerm.objects.filter(year=new_year,semester_type=new_type).exists():
        return AcademicTerm.objects.get(year=new_year,semester_type=new_type)
    else:
        a = AcademicTerm(year=new_year,semester_type=new_type)
        a.save()
        return a
Exemplo n.º 16
0
def get_next_full_term(term):
    new_type = None
    new_year = 0;
    if term.semester_type.name=='Fall':
        new_year=term.year+1
        new_type = SemesterType.objects.get(name='Winter')
    else:
        new_year = term.year
        new_type = SemesterType.objects.get(name='Fall')
    if AcademicTerm.objects.filter(year=new_year,semester_type=new_type).exists():
        return AcademicTerm.objects.get(year=new_year,semester_type=new_type)
    else:
        a = AcademicTerm(year=new_year,semester_type=new_type)
        a.save()
        return a
Exemplo n.º 17
0
    def profiles_you_can_view(cls, user):
        if user.is_superuser:
            return MemberProfile.get_members()
        current_positions = cls.get_current_officer_positions(user)
        query_all = (Q(position__name='President') |
                     Q(position__name='Vice President') |
                     Q(position__name='Graduate Student Vice President'))
        query_actives = Q(position__name='Membership Officer')
        query_electees = Q(position__name='Graduate Student Coordinator')
        query_electee_groups = (Q(leaders=user.userprofile.memberprofile) |
                                Q(officers=user.userprofile.memberprofile))
        query_out = MemberProfile.objects.none()
        if current_positions:
            if current_positions.filter(query_all).exists():
                return MemberProfile.get_members()
            if current_positions.filter(query_actives).exists():
                query_out = query_out | MemberProfile.get_actives()
            if current_positions.filter(query_electees).exists():
                query_out = query_out | MemberProfile.get_electees()

        electee_groups_led = ElecteeGroup.objects.filter(
                                query_electee_groups
                            ).filter(term=AcademicTerm.get_current_term())
        for electee_group in electee_groups_led:
            query_out = query_out | electee_group.members.all()

        return query_out
Exemplo n.º 18
0
def edit_electee_group_points(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee team points.'
        return redirect('electees:view_electee_groups')
    term =AcademicTerm.get_current_term()
    GroupPointsFormSet = modelformset_factory(ElecteeGroupEvent,exclude=('related_event_id',),can_delete=True)
    GroupPointsFormSet.form.base_fields['electee_group'].queryset=ElecteeGroup.objects.filter(term=term)
    if request.method =='POST':
        formset = GroupPointsFormSet(request.POST,prefix='group_points',queryset=ElecteeGroupEvent.objects.filter(related_event_id=None,electee_group__term=term))
        if formset.is_valid():
            formset.save()
            request.session['success_message']='Electee team points updated successfully'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        formset = GroupPointsFormSet(prefix='group_points',queryset=ElecteeGroupEvent.objects.filter(related_event_id=None,electee_group__term=term))
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':'group_points',
        'subsubnav':'points',
        'has_files':False,
        'submit_name':'Update Electee Team Points',
        'form_title':'Update/Add Remove Electee Team Points',
        'help_text':'Track the electee team points. You should not note any points from threshold participation at service or social events here. Those are tabulated automatically.',
        'can_add_row':True,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
Exemplo n.º 19
0
def edit_electee_resources(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee resources.'
        return redirect('electees:view_electee_groups')
    ResourceFormSet = modelformset_factory(ElecteeResource,exclude=('term',),can_delete=True)
    term =AcademicTerm.get_current_term()
    if request.method =='POST':
        formset = ResourceFormSet(request.POST,request.FILES,prefix='resources',queryset=ElecteeResource.objects.filter(term=term))
        if formset.is_valid():
            instances=formset.save(commit=False)
            for obj in formset.deleted_objects:
                obj.delete()
            for instance in instances:
                instance.term=term
                instance.save()
            request.session['success_message']='Electee resources updated successfully'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        formset = ResourceFormSet(prefix='resources',queryset=ElecteeResource.objects.filter(term=term))
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':'resources',
        'has_files':True,
        'submit_name':'Update Electee Resources',
        'form_title':'Update/Add/Remove Electee Resources for %s'%(unicode(term)),
        'help_text':'These are the full packets and their constituent parts. If you need a part that isn\'t listed here, contact the web chair.',
        'can_add_row':True,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
Exemplo n.º 20
0
    def __init__(self, *args, **kwargs):
        initial = []
        group_leaders = get_current_group_leaders()
        event_leaders = get_current_event_leaders()
        officers = Officer.get_current_members()
        leader_list = group_leaders | event_leaders | officers
        for leader in leader_list:
            if ProgressItem.objects.filter(
                    member=leader,
                    term=AcademicTerm.get_current_term(),
                    event_type=EventCategory.objects.get(
                        name='Leadership')).exists():
                continue
            if leader in officers:
                name_str = 'Was an officer'
            elif leader in group_leaders:
                name_str = 'Was a group leader'
            else:
                name_str = 'Led a project'
            initial.append({'member': leader, 'name': name_str})
        kwargs['initial'] = initial
        super(BaseLeadershipCreditFormSet, self).__init__(*args, **kwargs)

        self.queryset = ProgressItem.objects.none()
        self.extra = len(initial) + 1
Exemplo n.º 21
0
def edit_electee_group_membership(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee teams'
        return redirect('electees:view_electee_groups')
    if request.method =='POST':
        electee_groups_json=request.POST['electee_groups']
        electee_groups = json.loads(electee_groups_json)
        for group_id in electee_groups:
            members = electee_groups[group_id]
            group = ElecteeGroup.objects.get(id=group_id)
            group.members.clear()
            for member in members:
                group.members.add(MemberProfile.objects.get(uniqname=member))
        request.session['success_message']='Your changes have been saved'

    e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
    template = loader.get_template('electees/edit_electee_group_membership.html')
    context_dict = {
        'electee_groups':e_groups,
        'unassigned_electees':get_unassigned_electees(),
        'subsubnav':'members',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
Exemplo n.º 22
0
def default_term():
    """ Returns the current term.

    Fixes a serialization issue that results from circular references in
    migrations.
    """
    return AcademicTerm.get_current_term().id
Exemplo n.º 23
0
def get_members_for_COE():
    members = MemberProfile.get_actives().exclude(standing__name='Alumni')
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="MemberData.csv"'

    writer = UnicodeWriter(response)
    writer.writerow([
        'First Name', 'Last Name', 'uniqname', 'Active?', 'Officer?',
        'Standing', 'Major'
    ])
    for member in members:
        current_term = AcademicTerm.get_current_term()
        was_active = 'Active' if Distinction.objects.filter(
            member=member, term=current_term.get_previous_full_term()).exists(
            ) else 'Inactive'
        officer_terms = Officer.objects.filter(
            user=member,
            term__in=[
                current_term.get_previous_full_term(),
                current_term,
            ])
        if officer_terms.exists():
            officer_pos = ', '.join([
                unicode(officer.position) + ' ' +
                ', '.join([unicode(term) for term in officer.term.all()])
                for officer in officer_terms
            ])
        else:
            officer_pos = 'Member'
        writer.writerow([
            member.first_name, member.last_name, member.uniqname, was_active,
            officer_pos, member.standing.name,
            ', '.join([major.name for major in member.major.all()])
        ])
    return response
Exemplo n.º 24
0
def default_term():
    """ Returns the current term.

    Fixes a serialization issue that results from circular references in
    migrations.
    """
    return AcademicTerm.get_current_term().id
Exemplo n.º 25
0
 def __init__(self, *args, **kwargs):
     term = kwargs.pop('term', AcademicTerm.get_current_term())
     initial=[]
     for distinction in DistinctionType.objects.filter(status_type__name='Active'):
         actives_already_received_distinction = MemberProfile.objects.filter(
                             distinction__distinction_type=distinction,
                             distinction__term=term
         )
         actives = distinction.get_actives_with_status(term)
         for active in actives:
             if active in actives_already_received_distinction:
                 continue
             if distinction.name == 'Active':
                 gift = 'N/A'
             else:
                 gift = 'Not specified'
             initial.append(
                 {
                     'member': active,
                     'distinction_type': distinction,
                     'gift': gift,
                     'approve': False
                 }
             )
     kwargs['initial'] = initial
     super(BaseAddActiveStatusFormSet,
           self).__init__(*args, **kwargs)
     self.extra = len(initial)+1
     self.form.base_fields['distinction_type'].queryset =\
             DistinctionType.objects.filter(status_type__name='Active')
Exemplo n.º 26
0
def get_project_report_term():
    today = date.today()
    current_term = AcademicTerm.get_current_term()
    this_fall = Q(year=today.year, semester_type__name='Fall')
    last_fall = Q(year=today.year-1, semester_type__name='Fall')
    next_winter = Q(year=today.year+1, semester_type__name='Winter')
    this_winter = Q(year=today.year, semester_type__name='Winter')
    this_summer = Q(year=today.year, semester_type__name='Summer')
    last_summer = Q(year=today.year-1, semester_type__name='Summer')
    if today.month >= 9:
        # the project reports were already turned in, only care about the fall
        return AcademicTerm.objects.filter(
                                    this_fall |
                                    next_winter |
                                    this_summer)
    elif today.month >=5:
        # the project reports might be turned in. Show all
        return AcademicTerm.objects.filter(
                                    this_fall |
                                    next_winter |
                                    this_summer |
                                    this_winter |
                                    last_summer |
                                    last_fall)
    else:  # report not turned in yet
        return AcademicTerm.objects.filter(
                                    this_winter |
                                    last_summer |
                                    last_fall)
Exemplo n.º 27
0
def edit_electee_group_membership(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee teams'
        return redirect('electees:view_electee_groups')
    if request.method =='POST':
        electee_groups_json=request.POST['electee_groups']
        electee_groups = json.loads(electee_groups_json)
        for group_id in electee_groups:
            members = electee_groups[group_id]
            group = ElecteeGroup.objects.get(id=group_id)
            group.members.clear()
            for member in members:
                group.members.add(MemberProfile.objects.get(uniqname=member))
        request.session['success_message']='Your changes have been saved'

    e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
    template = loader.get_template('electees/edit_electee_group_membership.html')
    context_dict = {
        'electee_groups':e_groups,
        'unassigned_electees':get_unassigned_electees(),
        'subsubnav':'members',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Exemplo n.º 28
0
def edit_electee_group_points(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee team points.'
        return redirect('electees:view_electee_groups')
    term =AcademicTerm.get_current_term()
    GroupPointsFormSet = modelformset_factory(ElecteeGroupEvent,exclude=('related_event_id',),can_delete=True)
    GroupPointsFormSet.form.base_fields['electee_group'].queryset=ElecteeGroup.objects.filter(term=term)
    if request.method =='POST':
        formset = GroupPointsFormSet(request.POST,prefix='group_points',queryset=ElecteeGroupEvent.objects.filter(related_event_id=None,electee_group__term=term))
        if formset.is_valid():
            formset.save()
            request.session['success_message']='Electee team points updated successfully'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors.'
    else:
        formset = GroupPointsFormSet(prefix='group_points',queryset=ElecteeGroupEvent.objects.filter(related_event_id=None,electee_group__term=term))
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':'group_points',
        'subsubnav':'points',
        'has_files':False,
        'submit_name':'Update Electee Team Points',
        'form_title':'Update/Add Remove Electee Team Points',
        'help_text':'Track the electee team points. You should not note any points from threshold participation at service or social events here. Those are tabulated automatically.',
        'can_add_row':True,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Exemplo n.º 29
0
 def __init__(self, *args, **kwargs):
     term = kwargs.pop('term', AcademicTerm.get_current_term())
     initial = []
     for distinction in DistinctionType.objects.filter(
             status_type__name='Active'):
         actives_already_received_distinction = MemberProfile.objects.filter(
             distinction__distinction_type=distinction,
             distinction__term=term)
         actives = distinction.get_actives_with_status(term)
         for active in actives:
             if active in actives_already_received_distinction:
                 continue
             if distinction.name == 'Active':
                 gift = 'N/A'
             else:
                 gift = 'Not specified'
             initial.append({
                 'member': active,
                 'distinction_type': distinction,
                 'gift': gift,
                 'approve': False
             })
     kwargs['initial'] = initial
     super(BaseAddActiveStatusFormSet, self).__init__(*args, **kwargs)
     self.extra = len(initial) + 1
     self.form.base_fields['distinction_type'].queryset =\
             DistinctionType.objects.filter(status_type__name='Active')
Exemplo n.º 30
0
 def get_previous_officer_positions(cls,user):
     profile = cls.get_profile(user)
     if not profile:
         return Officer.objects.none()
     term = get_previous_full_term(AcademicTerm.get_current_term())
     positions = Officer.objects.filter(user=profile,term = term,position__position_type='O')
     return positions
Exemplo n.º 31
0
def view_electee_groups(request):
    request.session['current_page']=request.path
    e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term()).order_by('points')
    packets = ElecteeResource.objects.filter(term=AcademicTerm.get_current_term(),resource_type__is_packet=True).order_by('resource_type')
    resources = ElecteeResource.objects.filter(term=AcademicTerm.get_current_term(),resource_type__is_packet=False).order_by('resource_type')
    template = loader.get_template('electees/view_electee_groups.html')
    context_dict = {
        'groups':e_groups,
        'resources':resources,
        'packets':packets,
        'electee_resumes':'TBP_electee_resumes.zip',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Exemplo n.º 32
0
    def profiles_you_can_view(cls, user):
        if user.is_superuser:
            return MemberProfile.get_members()
        current_positions = cls.get_current_officer_positions(user)
        query_all = (Q(position__name='President') |
                     Q(position__name='Vice President') |
                     Q(position__name='Graduate Student Vice President'))
        query_actives = Q(position__name='Membership Officer')
        query_electees = Q(position__name='Graduate Student Coordinator')
        query_electee_groups = (Q(leaders=user.userprofile.memberprofile) |
                                Q(officers=user.userprofile.memberprofile))
        query_out = MemberProfile.objects.none()
        if current_positions:
            if current_positions.filter(query_all).exists():
                return MemberProfile.get_members()
            if current_positions.filter(query_actives).exists():
                query_out = query_out | MemberProfile.get_actives()
            if current_positions.filter(query_electees).exists():
                query_out = query_out | MemberProfile.get_electees()

        electee_groups_led = ElecteeGroup.objects.filter(
                                query_electee_groups
                            ).filter(term=AcademicTerm.get_current_term())
        for electee_group in electee_groups_led:
            query_out = query_out | electee_group.members.all()

        return query_out
Exemplo n.º 33
0
def get_unassigned_electees():
    current_electee_groups = ElecteeGroup.objects.filter(
                                    term=AcademicTerm.get_current_term()
    )
    current_electees = MemberProfile.get_electees()
    for group in current_electee_groups.all():
        current_electees = current_electees.exclude(pk__in=group.members.all())
    return current_electees.order_by('standing', 'last_name')
Exemplo n.º 34
0
def get_unassigned_electees():
    current_electee_groups = ElecteeGroup.objects.filter(
                                    term=AcademicTerm.get_current_term()
    )
    current_electees = MemberProfile.get_electees()
    for group in current_electee_groups.all():
        current_electees = current_electees.exclude(pk__in=group.members.all())
    return current_electees.order_by('standing', 'last_name')
Exemplo n.º 35
0
def manage_outreach_events(request, url_stem):
    outreach_event = get_object_or_404(OutreachEventType, url_stem=url_stem)
    relevant_officers = Officer.objects.filter(
                        user__uniqname=request.user.username,
                        term=AcademicTerm.get_current_term(),
                        position__in=outreach_event.officers_can_edit.all()
    )
    if not (request.user.is_superuser or relevant_officers.exists()):
        request.session['error_message'] = ('You are not authorized to edit '
                                            'outreach events')
        return get_previous_page(request, alternate='outreach:index')
    OutreachFormSet = modelformset_factory(
                            OutreachEvent,
                            exclude=['outreach_event']
    )
    prefix = 'outreach'
    formset = OutreachFormSet(
                    request.POST or None,
                    request.FILES or None,
                    prefix=prefix,
                    queryset=OutreachEvent.objects.filter(
                                outreach_event=outreach_event
                    )
    )

    if request.method == 'POST':
        if formset.is_valid():
            instances = formset.save(commit=False)
            for instance in instances:
                instance.outreach_event = outreach_event
                instance.save()
            request.session['success_message'] = ('Outraech Events '
                                                  'successfully updated.')
            return redirect('outreach:mindset')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    context_dict = {
        'formset': formset,
        'prefix': prefix,
        'subnav': 'index',
        'has_files': True,
        'submit_name': 'Update Outreach Events',
        'back_button': {
                    'link': reverse('outreach:outreach_event',
                                    args=[url_stem]),
                    'text': 'To %s Page' % (outreach_event.title)
        },
        'form_title': 'Edit %s Events' % (outreach_event.title),
        'help_text': ('Update or add new outreach events to display in '
                      'the %s section.') % (outreach_event.title),
        'can_add_row': True,
        'base': 'outreach/base_outreach.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    template = loader.get_template('generic_formset.html')
    return HttpResponse(template.render(context))
Exemplo n.º 36
0
def mindset(request):
    request.session['current_page'] = request.path
    template = loader.get_template('outreach/MindSET.html')
    k_12_officers = Officer.objects.filter(
        position__name='K-12 Outreach Officer').order_by(
            '-term__year', 'term__semester_type__name')
    officers_unique = []
    id_set = set()
    term = AcademicTerm.get_current_term()
    positions = OfficerPosition.objects.filter(name='K-12 Outreach Officer')
    current_officers = k_12_officers.filter(term=term)

    if positions.exists:
        position = positions[0]
    else:
        position = None
    for officer in k_12_officers:
        if officer.user.uniqname in id_set:
            continue
        else:
            id_set |= set([officer.user.uniqname])
            officers = current_officers.filter(
                user__uniqname=officer.user.uniqname)
            if not officers.exists():
                officers_unique.append(officer)

    mindset_main_photo = OutreachPhoto.objects.filter(
        photo_type__name='MindSET_Main')
    mindset_slideshow_photos = OutreachPhoto.objects.filter(
        photo_type__name='MindSET_Slideshow', active=True)
    if mindset_main_photo.exists():
        main_photo = mindset_main_photo[0]
    else:
        main_photo = None
    mindset_parking_photo = OutreachPhoto.objects.filter(
        photo_type__name='MindSET_Map')
    if mindset_parking_photo.exists():
        parking_photo = mindset_parking_photo[0]
    else:
        parking_photo = None
    events = CalendarEvent.objects.filter(
        term=term, event_type__name='MindSET').annotate(earliest_shift=Min(
            'eventshift__start_time')).order_by('earliest_shift')
    context_dict = {
        'events': events,
        'main_photo': main_photo,
        'parking_photo': parking_photo,
        'modules': MindSETModule.objects.all(),
        'k_12_officers': officers_unique,
        'position': position,
        'current_officers': current_officers,
        'volunteer_files': VolunteerFile.objects.all(),
        'slideshow_photos': mindset_slideshow_photos,
        'subnav': 'mindset',
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    return HttpResponse(template.render(context_dict, request))
Exemplo n.º 37
0
def manage_outreach_events(request, url_stem):
    outreach_event = get_object_or_404(OutreachEventType, url_stem=url_stem)
    relevant_officers = Officer.objects.filter(
        user__uniqname=request.user.username,
        term=AcademicTerm.get_current_term(),
        position__in=outreach_event.officers_can_edit.all())
    if not (request.user.is_superuser or relevant_officers.exists()):
        request.session['error_message'] = ('You are not authorized to edit '
                                            'outreach events')
        return get_previous_page(request, alternate='outreach:index')
    OutreachFormSet = modelformset_factory(OutreachEvent,
                                           exclude=['outreach_event'])
    prefix = 'outreach'
    formset = OutreachFormSet(
        request.POST or None,
        request.FILES or None,
        prefix=prefix,
        queryset=OutreachEvent.objects.filter(outreach_event=outreach_event))

    if request.method == 'POST':
        if formset.is_valid():
            instances = formset.save(commit=False)
            for instance in instances:
                instance.outreach_event = outreach_event
                instance.save()
            request.session['success_message'] = ('Outraech Events '
                                                  'successfully updated.')
            return redirect('outreach:mindset')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    context_dict = {
        'formset':
        formset,
        'prefix':
        prefix,
        'subnav':
        'index',
        'has_files':
        True,
        'submit_name':
        'Update Outreach Events',
        'back_button': {
            'link': reverse('outreach:outreach_event', args=[url_stem]),
            'text': 'To %s Page' % (outreach_event.title)
        },
        'form_title':
        'Edit %s Events' % (outreach_event.title),
        'help_text': ('Update or add new outreach events to display in '
                      'the %s section.') % (outreach_event.title),
        'can_add_row':
        True,
        'base':
        'outreach/base_outreach.html',
    }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    template = loader.get_template('generic_formset.html')
    return HttpResponse(template.render(context_dict, request))
Exemplo n.º 38
0
 def get_current_chair_positions(cls,user):
     profile = cls.get_profile(user)
     if not profile:
         return Officer.objects.none()
     term = AcademicTerm.get_current_term()
     if term.semester_type.name=='Summer':
         term = get_next_full_term(term)
     current_positions = Officer.objects.filter(user=profile,term = term,position__position_type='C')
     return current_positions
Exemplo n.º 39
0
def get_quorum_list_elections():
    term = AcademicTerm.get_current_term()
    all_actives = MemberProfile.get_actives()
    electees = MemberProfile.get_electees()
    active_actives = get_active_members(term)
    members_who_graduated = get_members_who_graduated()
    actual_actives = get_active_members_who_came_to_something(term)
    potential_actives = get_active_members_only_if_they_come(
                                            term,
                                            is_last_voting_meeting=True
    )
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="MemberStatus.csv"'

    writer = UnicodeWriter(response)
    writer.writerow([
            'First Name',
            'Last Name',
            'uniqname',
            'Active?',
            'Alumni?',
            'Present'
    ])
    for m in all_actives:
        if m in potential_actives:
            active = 'If present'
        elif m in actual_actives:
            active = 'Yes'
        elif m.standing.name == 'Alumni':
            active = 'Confirm Manually'
        else:
            active = 'No'
        if m in members_who_graduated:
            alum_text = 'Maybe'
        elif m.standing.name == 'Alumni':
            alum_text = 'Yes'
        else:
            alum_text = 'No'
        writer.writerow([
                m.first_name,
                m.last_name,
                m.uniqname,
                active,
                alum_text,
                ''
        ])
    for m in electees:
        writer.writerow([
                m.first_name,
                m.last_name,
                m.uniqname,
                'Electee',
                'No',
                ''
        ])
    return response
Exemplo n.º 40
0
def receive_book_start(request, uniqname):
    """ Just show a form for the barcode
    On submit looks up the book type, if present redirects to receive_book
    If not saves the uniqname into request.session and redirects to
    create_book_type
    """
    if not Permissions.can_process_bookswap(request.user):
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM
        return get_previous_page(request, alternate='bookswap:admin_index')
    if not BookSwapStatus.can_receive(AcademicTerm.get_current_term()):
        request.session['error_message'] = 'Book receiving not enabled'
        return get_previous_page(request, alternate='bookswap:admin_index')
    form = BookSearchForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            barcode = form.cleaned_data.get('book_barcode', '')
            book_type = BookType.objects.filter(isbn=barcode)
            if book_type.exists():
                # TODO: If multiple give choice?
                book_type = book_type[0]
                request.session['success_message'] = ('Book found, please '
                                                      'enter sale details.')
                return redirect('bookswap:receive_book',
                                uniqname=uniqname,
                                book_type_id=book_type.id)

            else:
                request.session['warning_message'] = ('Book not found, please '
                                                      'enter details.')
                request.session['uniqname'] = uniqname
                request.session['isbn'] = barcode
                return redirect('bookswap:create_book_type')

        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form':
        form,
        'subnav':
        'admin',
        'has_files':
        False,
        'submit_name':
        'Search for book by ISBN',
        'form_title':
        'Search for a book in the system',
        'help_text': ('You can search for a book by its ISBN, which is the '
                      '13 digit code scanned by the barcode.'),
        'base':
        'bookswap/base_bookswap.html',
    }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Exemplo n.º 41
0
def create_elections(request):
    if not request.user.is_superuser:
        request.session['error_message'] = 'Invalid Action.'
        return redirect('elections:index')
    term = AcademicTerm.get_current_term()
    e = Election.create_election_for_next_term(term)
    request.session['success_message'] = 'Elections Created'
    return HttpResponseRedirect(
                reverse('elections:list', args=(e.id,))
    )
Exemplo n.º 42
0
    def __init__(self, *args, **kwargs):
        super(BaseManageDuesFormSet, self).__init__(*args, **kwargs)

        # create filtering here whatever that suits you needs
        self.queryset = ProgressItem.objects.filter(
            member__status__name='Electee',
            event_type__name='Dues',
            term=AcademicTerm.get_current_term(),
        ).order_by('member__last_name', 'member__first_name',
                   'member__uniqname')
Exemplo n.º 43
0
 def get_current_leaders(cls):
     """ Returns all the members who are group leaders or are officers
     associated with a group.
     """
     current_groups = cls.objects.filter(
         term=AcademicTerm.get_current_term())
     return MemberProfile.objects.filter(
         Q(electee_group_leaders__in=current_groups)
         | Q(electee_group_officers__in=current_groups)).distinct(
         ).order_by('last_name', 'first_name', 'uniqname')
Exemplo n.º 44
0
class BaseNEPForm(forms.ModelForm):
    """ Base form for filling out a non-event project summary.
    """
    leaders = forms.ModelMultipleChoiceField(
        widget=Select2MultipleWidget(), queryset=MemberProfile.get_members())
    term = forms.ModelChoiceField(widget=Select2Widget(),
                                  queryset=AcademicTerm.get_rchron(),
                                  initial=AcademicTerm.get_current_term())
    assoc_officer = forms.ModelChoiceField(
        widget=Select2Widget(),
        queryset=OfficerPosition.get_current(),
        label='Associated Officer')

    class Meta:
        model = NonEventProject
        fields = [
            'name', 'description', 'leaders', 'assoc_officer', 'term',
            'start_date', 'end_date', 'location'
        ]
Exemplo n.º 45
0
    def __init__(self, *args, **kwargs):
        super(BaseManageActiveGroupMeetingsFormSet,
              self).__init__(*args, **kwargs)

        self.queryset = ProgressItem.objects.filter(
            member__status__name='Active',
            event_type__name='Team Meetings',
            term=AcademicTerm.get_current_term(),
        ).order_by('member__last_name', 'member__first_name',
                   'member__uniqname')
Exemplo n.º 46
0
    def __init__(self, *args, **kwargs):
        profiles = kwargs.pop('profiles', None)
        exam_name = kwargs.pop('exam_name', None)
        interview_name = kwargs.pop('interview_name', None)
        group_meetings_name = kwargs.pop('group_meetings_name', None)
        advisor_form_name = kwargs.pop('advisor_form_name', None)
        if not profiles:
            return
        initial = []
        term = AcademicTerm.get_current_term()
        for profile in profiles:
            init_dict = {
                'electee': profile.get_firstlast_name(),
                'standing': profile.standing.name,
                'uniqname': profile.uniqname
            }

            exam_progress = ProgressItem.objects.filter(
                event_type__name=exam_name,
                term=term,
                member=profile,
            ).aggregate(Sum('amount_completed'))
            if exam_progress['amount_completed__sum'] > 0:
                init_dict['electee_exam_completed'] = True
            else:
                init_dict['electee_exam_completed'] = False
            interview_progress = ProgressItem.objects.filter(
                event_type__name=interview_name,
                term=term,
                member=profile,
            ).aggregate(Sum('amount_completed'))
            amount = interview_progress['amount_completed__sum']
            init_dict['peer_interviews_completed'] = int(
                amount) if amount else 0

            group_meetings_progress = ProgressItem.objects.filter(
                event_type__name__in=group_meetings_name,
                term=term,
                member=profile,
            ).aggregate(Sum('amount_completed'))
            amount = group_meetings_progress['amount_completed__sum']
            init_dict['group_meetings'] = int(amount) if amount else 0
            advisor_form_progress = ProgressItem.objects.filter(
                event_type__name=advisor_form_name,
                term=term,
                member=profile,
            ).aggregate(Sum('amount_completed'))
            if advisor_form_progress['amount_completed__sum'] > 0:
                init_dict['advisor_form'] = True
            else:
                init_dict['advisor_form'] = False
            initial.append(init_dict)
        kwargs['initial'] = initial
        print initial
        super(BaseManageUgradPaperWorkFormSet, self).__init__(*args, **kwargs)
Exemplo n.º 47
0
    def save(self, commit=True):
        instance = super(ManageActiveGroupMeetingsForm,
                         self).save(commit=False)
        term = AcademicTerm.get_current_term()
        instance.term = term
        instance.date_completed = date.today()
        instance.name = 'Team Meetings'
        extra_meetings = ProgressItem.objects.filter(
            term=term,
            member=instance.member,
            event_type__name='Extra Team Meetings',
        )
        group = ElecteeGroup.objects.filter(
            Q(leaders=instance.member) | Q(officers=instance.member))
        group = group.filter(term=term)
        dist = DistinctionType.objects.filter(
            status_type__name='Electee', standing_type__name='Undergraduate')
        if group.exists():
            print group
            if group[0].members.exists():
                print group[0]
                standing = group[0].members.all()[0].standing
                dist = DistinctionType.objects.filter(
                    status_type__name='Electee', standing_type=standing)
        group_meeting_req = Requirement.objects.filter(
            distinction_type=dist,
            event_category__name='Team Meetings',
            term=term.semester_type)
        if group_meeting_req:
            amount_group_req = group_meeting_req[0].amount_required
        else:
            amount_group_req = 0
        if extra_meetings.count(
        ) > 1 or instance.amount_completed <= amount_group_req:
            extra_meetings.delete()

        if not extra_meetings.exists(
        ) and instance.amount_completed > amount_group_req:
            extra_meeting = ProgressItem(term=term,
                                         member=instance.member,
                                         date_completed=date.today())
            extra_meeting.event_type = EventCategory.objects.get(
                name='Extra Team Meetings')
            extra_meeting.amount_completed = instance.amount_completed - amount_group_req
            extra_meeting.save()
        elif instance.amount_completed > amount_group_req:
            extra_meeting = extra_meetings[0]
            extra_meeting.amount_completed = instance.amount_completed - amount_group_req
            extra_meeting.save()
        instance.event_type = EventCategory.objects.get(name='Team Meetings')
        if instance.amount_completed > amount_group_req:
            instance.amount_completed = amount_group_req
        if commit:
            instance.save()
        return instance
Exemplo n.º 48
0
    def term(self, create, extracted, **kwargs):
        if not create:
            # Simple build, do nothing.
            return

        if extracted:
            # A list of groups were passed in, use them
            for term in extracted:
                self.term.add(term)
        else:
            self.term.add(AcademicTerm.get_current_term())
Exemplo n.º 49
0
def electee_stopped_electing(profile):
    profile.still_electing=False
    profile.save()
    future_events = CalendarEvent.objects.filter(eventshift__attendees=profile,completed=False)
    for event in future_events:
        for shift in event.eventshift_set.all():
            shift.attendees.remove(profile)
            shift.save()
    for group in ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term(),members=profile):
        group.members.remove(profile)
        group.save()
Exemplo n.º 50
0
    def term(self, create, extracted, **kwargs):
        if not create:
            # Simple build, do nothing.
            return

        if extracted:
            # A list of groups were passed in, use them
            for term in extracted:
                self.term.add(term)
        else:
            self.term.add(AcademicTerm.get_current_term())
Exemplo n.º 51
0
 def get_previous_officer_positions(cls, user):
     profile = cls.get_profile(user)
     if not profile:
         return Officer.objects.none()
     term = AcademicTerm.get_current_term().get_previous_full_term()
     positions = Officer.objects.filter(
                     user=profile,
                     term=term,
                     position__position_type='O'
     )
     return positions
Exemplo n.º 52
0
 def add_statuses(cls,uniqnames,distinction_type,term=None,gift='N/A'):
     if not term:
         term = AcademicTerm.get_current_term()
     no_profiles=[]
     for uniqname in uniqnames:
         profiles = MemberProfile.objects.filter(uniqname=uniqname)
         if not profiles.exists():
             no_profiles.append(uniqname)
             continue
         dist = cls(member=profiles[0],term=term,gift=gift,distinction_type=distinction_type)
         dist.save()
     return no_profiles
Exemplo n.º 53
0
def edit_electee_groups(request):
    if not Permissions.can_manage_electee_progress(request.user):
        request.session['error_message']='You are not authorized to edit electee groups'
        return redirect('electees:view_electee_groups')
    e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
    ElecteeGroupFormSet = modelformset_factory(ElecteeGroup,form =BaseElecteeGroupForm,can_delete=True)
    if request.method =='POST':
        formset = ElecteeGroupFormSet(request.POST,prefix='groups')
        if formset.is_valid():
            instances=formset.save(commit=False)
            for obj in formset.deleted_objects:
                obj.delete()
            for instance in instances:
                if not instance.id:
                    instance.term = AcademicTerm.get_current_term()
                    instance.points = 0
                instance.save()
            formset.save_m2m()
            request.session['success_message']='Electee teams successfully updated'
            return redirect('electees:view_electee_groups')
        else:
            request.session['error_message']='Form is invalid. Please correct the noted errors'
    else:
        formset = ElecteeGroupFormSet(queryset=e_groups,prefix='groups')
    template = loader.get_template('generic_formset.html')
    context_dict = {
        'formset':formset,
        'prefix':'groups',
        'subsubnav':'groups',
        'has_files':False,
        'submit_name':'Update Electee Teams',
        'form_title':'Update/Add/Remove Electee Teams',
        'help_text':'Create the electee teams for this semester, and specify the leaders and officers. You can also remove or edit here.',
        'can_add_row':True,
        'base':'electees/base_electees.html',
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Exemplo n.º 54
0
def submit_background_form(request):
    if not can_submit_background_form(request.user):
        request.session['error_message']='You are not authorized to submit an educational background form.'
        return redirect('electees:view_electee_groups')
    BackgroundForm = modelform_factory(EducationalBackgroundForm,exclude=('member','term',))
    profile=request.user.userprofile.memberprofile
    term =AcademicTerm.get_current_term()
    existing_form = EducationalBackgroundForm.objects.filter(member=profile,term=term)
    if existing_form.exists():
        form = BackgroundForm(request.POST or None, prefix='background',instance=existing_form[0])
        formset= InstituteFormset(request.POST or None, prefix='institute',instance=existing_form[0])
    else:
        blank_form = EducationalBackgroundForm(member=request.user.userprofile.memberprofile,term=AcademicTerm.get_current_term())
        form = BackgroundForm(request.POST or None,prefix='background',instance=blank_form)
        formset= InstituteFormset(request.POST or None,prefix='institute',instance=blank_form)
    if request.method == 'POST':
        if form.is_valid():
            background_form = form.save(commit=False)
            formset[0].empty_permitted=False
            if formset.is_valid():
                background_form.save()
                form.save_m2m()
                formset.save()
                request.session['success_message']='Background form successfully submitted'
                existing_progress_background_form= ProgressItem.objects.filter(member=profile,term=term,event_type__name='Educational Background Form')
                if not existing_progress_background_form.exists():
                    p = ProgressItem(member=profile,term=term,amount_completed=1,date_completed=date.today(),name='Educational Background Form Completed')
                    p.event_type = EventCategory.objects.get(name='Educational Background Form')
                    p.save()
                return redirect('electees:view_electee_groups')
            else:
                request.session['error_message']='Either there were errors in your prior degrees or you forgot to include one.'
        else:
            request.session['error_message']='There were errors in the submitted form, please correct the errors noted below.'
        
        
    template = loader.get_template('electees/submit_education_form.html')
    dp_ids=[]
    for count in range(len(formset)):
        dp_ids.append('id_institute-%d-degree_start_date'%(count))
        dp_ids.append('id_institute-%d-degree_end_date'%(count))
    context_dict = {
        'form':form,
        'formset':formset,
        'prefix':'institute',
        'dp_ids':dp_ids,
        'dp_ids_dyn':['degree_start_date', 'degree_end_date'],
        }
    context_dict.update(get_common_context(request))
    context_dict.update(get_permissions(request.user))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
Exemplo n.º 55
0
def receive_book(request, uniqname, book_type_id):
    if not Permissions.can_process_bookswap(request.user):
        request.session['error_message'] = messages.BOOKSWAP_NO_PERM
        return get_previous_page(request, alternate='bookswap:admin_index')
    if not BookSwapStatus.can_receive(AcademicTerm.get_current_term()):
        request.session['error_message'] = 'Book receiving not enabled'
        return get_previous_page(request, alternate='bookswap:admin_index')
    book_type = get_object_or_404(BookType, id=book_type_id)
    seller = get_object_or_404(BookSwapPerson, user_profile__uniqname=uniqname)
    instance = Book(
                seller=seller,
                book_type=book_type,
                term=AcademicTerm.get_current_term()
    )
    form = ReceiveBookForm(request.POST or None, instance=instance)
    if request.method == 'POST':
        if form.is_valid():
            book = form.save()
            request.session['success_message'] = ('Book added created! '
                                                  'Please continue.')
            return redirect('bookswap:receive_book_start',
                            uniqname=uniqname)
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    template = loader.get_template('generic_form.html')
    context_dict = {
        'form': form,
        'subnav': 'admin',
        'has_files': False,
        'submit_name': 'Receive book',
        'form_title': 'Recieve a copy of: %s for %s' % (book_type.title, uniqname),
        'help_text': ('This receives a specific saleable book.'),
        'base': 'bookswap/base_bookswap.html',
        }
    context_dict.update(get_permissions(request.user))
    context_dict.update(get_common_context(request))
    context = RequestContext(request, context_dict)
    return HttpResponse(template.render(context))
    pass