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
def test_resume_compile(self): compile_resumes() # check that the resumes are in the right place self.assertTrue(exists(RESUMES_BY_MAJOR_LOCATION())) self.assertTrue(exists(RESUMES_BY_YEAR_LOCATION())) guide = CorporateResourceGuide.objects.get() # first test the major directory resource_guide_url = sep.join([RESUMES_BY_MAJOR_LOCATION(), guide.name+'.pdf']) self.assertTrue(isfile(resource_guide_url)) major_dirs = set() for major in Major.objects.all(): major_dir = sep.join([RESUMES_BY_MAJOR_LOCATION(), slugify(major.name)]) major_dirs.add(slugify(major.name)) self.assertTrue(exists(major_dir)) self.assertFalse(isfile(major_dir)) major_resumes = set() for member in MemberProfile.get_members().filter(major=major): if not member.resume: continue resume_file = sep.join([major_dir, member.get_resume_name()]) major_resumes.add(member.get_resume_name()) self.assertTrue(isfile(resume_file)) self.assertEqual(major_resumes, set(listdir(major_dir))) major_dirs.add(guide.name+'.pdf') self.assertEqual(major_dirs,set(listdir(RESUMES_BY_MAJOR_LOCATION()))) # now check the by year, basically checking that what is there is all # and only what is supposed to be resource_guide_url = sep.join([RESUMES_BY_YEAR_LOCATION(), guide.name+'.pdf']) self.assertTrue(isfile(resource_guide_url)) standing_dirs = set() for standing in Standing.objects.all(): sub_dir = slugify(standing.name) +( '' if standing.name == 'Alumni' else '-student') standing_dir = sep.join([RESUMES_BY_YEAR_LOCATION(), sub_dir]) standing_dirs.add(sub_dir) self.assertTrue(exists(standing_dir)) self.assertFalse(isfile(standing_dir)) year_dirs = {} for member in MemberProfile.get_members().filter(standing=standing): if not member.resume: continue year_dir = 'Graduating'+slugify(member.expect_grad_date.year) if year_dir not in year_dirs: year_dirs[year_dir]=set() year_dirs[year_dir].add( member.get_resume_name()) resume_file = sep.join([standing_dir, year_dir, member.get_resume_name()]) for year_dir in year_dirs: self.assertEqual(year_dirs[year_dir],set(listdir(sep.join([standing_dir, year_dir])))) self.assertEqual(set(year_dirs.keys()),set(listdir(standing_dir))) standing_dirs.add(guide.name+'.pdf') self.assertEqual(standing_dirs,set(listdir(RESUMES_BY_YEAR_LOCATION())))
def view_map(request): """ The view of member locations. """ if (not hasattr(request.user, 'userprofile') or not request.user.userprofile.is_member()): request.session['error_message'] = ('You must be logged in and a ' 'member to view this.') return get_previous_page( request, alternate='member_resources:index' ) members_with_location = MemberProfile.get_members().exclude(location='') template = loader.get_template('fora/map.html') member = request.user.userprofile.memberprofile location = (member.location if member.location else GeoLocation(42.26, -83.7483)) context_dict = { 'members': members_with_location, 'center': location, 'can_center_on_me': bool(member.location), } context_dict.update(get_permissions(request.user)) context_dict.update(get_common_context(request)) context = RequestContext(request, context_dict) return HttpResponse(template.render(context))
class AwardForm(forms.ModelForm): """ Form for giving out an award.""" recipient = forms.ModelChoiceField(widget=Select2Widget(), queryset=MemberProfile.get_members()) class Meta: model = Award fields = ['award_type', 'term', 'recipient', 'comment']
class BaseNEPParticipantForm(forms.ModelForm): """ Base form for adding participants to a non-event project.""" participant = forms.ModelChoiceField(widget=Select2Widget(), queryset=MemberProfile.get_members()) class Meta: model = NonEventProjectParticipant fields = ['project', 'participant', 'hours']
class CommitteeMemberForm(forms.ModelForm): """ Form for adding committee members for a given term.""" member = forms.ModelChoiceField(widget=Select2Widget(), queryset=MemberProfile.get_members(), label='Member') class Meta: model = CommitteeMember exclude = ['term']
class ManageProjectLeaderForm(ModelForm): member_profile = forms.ModelChoiceField( widget=Select2Widget(), queryset=MemberProfile.get_members() ) class Meta: model = ProjectLeaderList fields = ['member_profile']
class CompleteEventForm(ModelForm): """ Form used to specify how many hours the attendee was at the event. """ member = forms.ModelChoiceField(widget=Select2Widget(), queryset=MemberProfile.get_members()) class Meta: model = ProgressItem exclude = ('term', 'event_type', 'date_completed', 'related_event', 'name')
def compile_resumes(): media_parent = '/'.join(settings.MEDIA_ROOT.split('/')[:-2])+'/' if os.path.exists(RESUMES_BY_MAJOR_LOCATION()): shutil.rmtree(RESUMES_BY_MAJOR_LOCATION()) os.makedirs(RESUMES_BY_MAJOR_LOCATION()) resource_guides = CorporateResourceGuide.objects.filter(active=True) if resource_guides: shutil.copy(media_parent+resource_guides[0].resource_guide.url,os.path.sep.join([RESUMES_BY_MAJOR_LOCATION(),slugify(resource_guides[0].name)+'.pdf'])) for resume_major in Major.objects.all(): query=Q(major=resume_major) users_in_major = MemberProfile.get_members().filter(query) for user in users_in_major: if user.resume: major_dir = os.path.sep.join([RESUMES_BY_MAJOR_LOCATION(),slugify(resume_major.name)]) if not os.path.exists(major_dir): os.makedirs(major_dir) resume_name=user.get_resume_name() shutil.copy(media_parent+user.resume.url,os.path.sep.join([major_dir,resume_name])) if os.path.exists(RESUMES_BY_YEAR_LOCATION()): shutil.rmtree(RESUMES_BY_YEAR_LOCATION()) os.makedirs(RESUMES_BY_YEAR_LOCATION()) if resource_guides: shutil.copy(media_parent+resource_guides[0].resource_guide.url,os.path.sep.join([RESUMES_BY_YEAR_LOCATION(),slugify(resource_guides[0].name)+'.pdf'])) for standing in Standing.objects.all(): members = MemberProfile.get_members().filter(standing=standing) if standing.name == 'Alumni': status_dir = os.path.sep.join([RESUMES_BY_YEAR_LOCATION(),slugify(standing.name)]) else: status_dir = os.path.sep.join([RESUMES_BY_YEAR_LOCATION(), slugify(standing.name)+'-student']) if not os.path.exists(status_dir): os.makedirs(status_dir) for user in members: if user.resume: current_grad_year = user.expect_grad_date.year year_dir = os.path.sep.join([status_dir,'Graduating'+slugify(current_grad_year)]) if not os.path.exists(year_dir): os.makedirs(year_dir) resume_name=slugify(user.last_name+'_'+user.first_name+'_'+user.uniqname)+'.pdf' shutil.copy(media_parent+user.resume.url,os.path.sep.join([year_dir,resume_name]))
class OfficerForm(forms.ModelForm): """ Form for specifying an officer. Excludes term, since that is specified externally. """ user = forms.ModelChoiceField(widget=Select2Widget(), queryset=MemberProfile.get_members(), label='Member') position = forms.ModelChoiceField(widget=Select2Widget(), queryset=OfficerPosition.get_current()) class Meta: model = Officer exclude = ['term']
class BaseAnnouncementForm(ModelForm): """ Form for creating and submitting announcements to be included in the weekly announcements sent to membership. """ contacts = forms.ModelMultipleChoiceField( widget=Select2MultipleWidget(), queryset=MemberProfile.get_members()) class Meta: model = AnnouncementBlurb fields = [ 'start_date', 'end_date', 'title', 'text', 'contacts', 'sign_up_link' ]
class WebArticleForm(forms.ModelForm): """ Form for submitting website articles.""" TWEET_CHOICES = ( ('N', 'No Tweet'), ('T', 'Tweet normally'), ('H', 'Tweet with #UmichEngin'), ) tagged_members = forms.ModelMultipleChoiceField( widget=Select2MultipleWidget(), queryset=MemberProfile.get_members(), required=False) tweet_option = forms.ChoiceField(choices=TWEET_CHOICES, initial='N') class Meta: model = WebsiteArticle exclude = ['created_by', 'approved']
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' ]
class CompleteFixedProgressEventForm(ModelForm): """ For events where progress is fixed (i.e. you were there or you weren't) only listing attendees is necessary. """ member = forms.ModelChoiceField(widget=Select2Widget(), queryset=MemberProfile.get_members()) class Meta: model = ProgressItem exclude = ( 'term', 'event_type', 'date_completed', 'amount_completed', 'related_event', 'name', 'hours', )
class LeadershipCreditForm(forms.ModelForm): member = forms.ModelChoiceField(widget=Select2Widget(), queryset=MemberProfile.get_members()) approve = forms.BooleanField(required=False) class Meta: model = ProgressItem exclude = ('term', 'event_type', 'amount_completed', 'date_completed', 'related_event') def save(self, commit=True): approved = self.cleaned_data.pop('approve', False) if approved: instance = super(LeadershipCreditForm, self).save(commit=False) instance.term = AcademicTerm.get_current_term() instance.event_type = EventCategory.objects.get(name='Leadership') instance.amount_completed = 1 instance.date_completed = date.today() if commit: instance.save() return instance else: return None
def view_map(request): """ The view of member locations. """ if (not hasattr(request.user, 'userprofile') or not request.user.userprofile.is_member()): request.session['error_message'] = ('You must be logged in and a ' 'member to view this.') return get_previous_page( request, alternate='member_resources:index' ) members_with_location = MemberProfile.get_members().exclude(location='') template = loader.get_template('fora/map.html') member = request.user.userprofile.memberprofile location = (member.location if member.location else GeoLocation(42.26, -83.7483)) context_dict = { 'members': members_with_location, 'center': location, 'can_center_on_me': bool(member.location), } context_dict.update(get_permissions(request.user)) context_dict.update(get_common_context(request)) return HttpResponse(template.render(context_dict, request))
class NominationForm(forms.ModelForm): """ Form for submitting nominations. Overrides the default behavior to make it so that you can only nominate someone to a position that is part of the current election. """ nominee = forms.ModelChoiceField(widget=Select2Widget(), queryset=MemberProfile.get_members()) position = forms.ModelChoiceField(widget=Select2Widget(), queryset=OfficerPosition.get_current()) class Meta: model = Nomination exclude = ( 'election', 'nominator', 'accepted', ) def __init__(self, *args, **kwargs): election = kwargs.pop('election', None) super(NominationForm, self).__init__(*args, **kwargs) if election: officers = election.officers_for_election.all() self.fields['position'].queryset = officers
class AddContactForm(forms.Form): address = forms.CharField(widget=forms.Textarea, required=False) company = forms.ModelChoiceField( widget=Select2Widget(), queryset=Company.objects.order_by('name'), label='Company', ) gets_email = forms.BooleanField(required=False) has_contacted = forms.BooleanField(required=False) personal_contact_of = forms.ModelChoiceField( widget=Select2Widget(), queryset=MemberProfile.get_members(), label='Personal contact of', required=False ) member = forms.ModelChoiceField( widget=Select2Widget( ), queryset=MemberProfile.get_members(), label='Contact', required=False, initial=None ) speaking_interest = forms.BooleanField(required=False) name = forms.CharField(max_length=256, required=False) email = forms.EmailField(max_length=254, required=False) phone = USPhoneNumberField(required=False) short_bio = forms.CharField(widget=forms.Textarea, required=False) initiating_chapter = forms.ModelChoiceField( widget=Select2Widget(), queryset=TBPChapter.objects.order_by('state', 'letter'), label='Initiating TBP Chapter (if any)', required=False ) id = forms.IntegerField(widget=forms.HiddenInput(), initial=0) is_member = forms.BooleanField( widget=forms.HiddenInput(), initial=None, required=False ) def __init__(self, *args, **kwargs): c = kwargs.pop('contact', None) ed = kwargs.pop('can_edit', False) super(AddContactForm, self).__init__(*args, **kwargs) if not ed: self.fields['gets_email'].widget = forms.HiddenInput() if c: self.fields['address'].initial = c.address self.fields['company'].initial = c.company self.fields['gets_email'].initial = c.gets_email self.fields['has_contacted'].initial = c.has_contacted self.fields['personal_contact_of'].initial = c.personal_contact_of self.fields['speaking_interest'].initial = c.speaking_interest self.fields['id'].initial = c.id if hasattr(c, 'member'): self.fields['is_member'].initial = True self.fields['member'].initial = c.member else: self.fields['is_member'].initial = None self.fields['member'].initial = None self.fields['name'].initial = c.name self.fields['email'].initial = c.email self.fields['phone'].initial = c.phone self.fields['short_bio'].initial = c.short_bio self.fields['initiating_chapter'].initial = c.initiating_chapter def clean(self): cleaned_data = super(AddContactForm, self).clean() member = cleaned_data.get('member') name = cleaned_data.get('name') if self.has_changed() and not(name or member): raise forms.ValidationError( ('Either a member profile or a ' 'contact name must be provided')) def is_overdetermined(self): if self.cleaned_data.get('member'): name = self.cleaned_data.get('name') email = self.cleaned_data.get('email') phone = self.cleaned_data.get('phone') bio = self.cleaned_data.get('short_bio') chapter = self.cleaned_data.get('initiating_chapter') if name or email or phone or bio or chapter: return True return False def save(self): if not self.has_changed(): return id = self.cleaned_data.get('id') was_instance = id and id > 0 was_member = self.cleaned_data.get('is_member') member = self.cleaned_data.get('member') if member: # save a MemberContact if was_instance and was_member: c = MemberContact.objects.get(id=id) else: c = MemberContact() if was_instance and not was_member: NonMemberContact.objects.filter(id=id).delete() c.member = member else: # save a NonMemberContact if was_instance and not was_member: c = NonMemberContact.objects.get(id=id) else: c = NonMemberContact() if was_instance and was_member: MemberContact.objects.filter(id=id).delete() c.name = self.cleaned_data.get('name') c.email = self.cleaned_data.get('email') c.phone = self.cleaned_data.get('phone') c.short_bio = self.cleaned_data.get('short_bio') c.initiating_chapter = self.cleaned_data.get('initiating_chapter') c.address = self.cleaned_data.get('address') c.company = self.cleaned_data.get('company') c.gets_email = self.cleaned_data.get('gets_email') c.has_contacted = self.cleaned_data.get('has_contacted') c.personal_contact_of = self.cleaned_data.get('personal_contact_of') c.speaking_interest = self.cleaned_data.get('speaking_interest') c.save() return c def delete(self): id = self.cleaned_data.get('id') was_instance = id and id > 0 was_member = self.cleaned_data.get('is_member') if not was_instance: return if was_member: MemberContact.objects.filter(id=id).delete() else: NonMemberContact.objects.filter(id=id).delete()
class BaseEventForm(ModelForm): """ Form used in creating or editing event objects. This only creates the event itself, not the shifts, though the formset for creating those is often paired with this. """ TWEET_CHOICES = ( ('N', 'No Tweet'), ('T', 'Tweet normally'), ('H', 'Tweet with #UmichEngin'), ) leaders = forms.ModelMultipleChoiceField( widget=Select2MultipleWidget(), queryset=MemberProfile.get_members()) tweet_option = forms.ChoiceField(choices=TWEET_CHOICES, initial='N') agenda = forms.ModelChoiceField( widget=Select2Widget(), queryset=MeetingMinutes.objects.filter( semester=AcademicTerm.get_current_term(), meeting_type__in=['NI', 'MM']), required=False, ) class Meta: model = CalendarEvent fields = [ 'name', 'term', 'event_type', 'event_class', 'description', 'agenda', 'google_cal', 'leaders', 'assoc_officer', 'announce_start', 'announce_text', 'preferred_items', 'min_unsign_up_notice', 'min_sign_up_notice', 'members_only', 'needs_carpool', 'use_sign_in', 'allow_advance_sign_up', 'needs_facebook_event', 'needs_flyer', 'requires_UM_background_check', 'requires_AAPS_background_check', 'mutually_exclusive_shifts', 'allow_overlapping_sign_ups', 'needs_COE_event', ] def clean(self): """ Ensures that tweets are not sent or COE events not created for events which are marked as members-only """ cleaned_data = super(BaseEventForm, self).clean() members_only = cleaned_data.get('members_only') tweet_option = cleaned_data.get('tweet_option') coe_option = cleaned_data.get('needs_COE_event') if members_only and not tweet_option == 'N': raise ValidationError( _('Tweeting is not currentlys supported' ' for members-only events')) if members_only and coe_option: raise ValidationError( _('Members-only events cannot be on the' ' COE Calendar.')) return cleaned_data
def test_resume_compile(self): compile_resumes() # check that the resumes are in the right place self.assertTrue(exists(RESUMES_BY_MAJOR_LOCATION())) self.assertTrue(exists(RESUMES_BY_YEAR_LOCATION())) guide = CorporateResourceGuide.objects.get() # first test the major directory resource_guide_url = sep.join( [RESUMES_BY_MAJOR_LOCATION(), guide.name + '.pdf']) self.assertTrue(isfile(resource_guide_url)) major_dirs = set() for major in Major.objects.all(): major_dir = sep.join( [RESUMES_BY_MAJOR_LOCATION(), slugify(major.name)]) major_dirs.add(slugify(major.name)) self.assertTrue(exists(major_dir)) self.assertFalse(isfile(major_dir)) major_resumes = set() for member in MemberProfile.get_members().filter(major=major): if not member.resume: continue resume_file = sep.join([major_dir, member.get_resume_name()]) major_resumes.add(member.get_resume_name()) self.assertTrue(isfile(resume_file)) self.assertEqual(major_resumes, set(listdir(major_dir))) major_dirs.add(guide.name + '.pdf') self.assertEqual(major_dirs, set(listdir(RESUMES_BY_MAJOR_LOCATION()))) # now check the by year, basically checking that what is there is all # and only what is supposed to be resource_guide_url = sep.join( [RESUMES_BY_YEAR_LOCATION(), guide.name + '.pdf']) self.assertTrue(isfile(resource_guide_url)) standing_dirs = set() for standing in Standing.objects.all(): sub_dir = slugify(standing.name) + ('' if standing.name == 'Alumni' else '-student') standing_dir = sep.join([RESUMES_BY_YEAR_LOCATION(), sub_dir]) standing_dirs.add(sub_dir) self.assertTrue(exists(standing_dir)) self.assertFalse(isfile(standing_dir)) year_dirs = {} for member in MemberProfile.get_members().filter( standing=standing): if not member.resume: continue year_dir = 'Graduating' + slugify(member.expect_grad_date.year) if year_dir not in year_dirs: year_dirs[year_dir] = set() year_dirs[year_dir].add(member.get_resume_name()) resume_file = sep.join( [standing_dir, year_dir, member.get_resume_name()]) for year_dir in year_dirs: self.assertEqual( year_dirs[year_dir], set(listdir(sep.join([standing_dir, year_dir])))) self.assertEqual(set(year_dirs.keys()), set(listdir(standing_dir))) standing_dirs.add(guide.name + '.pdf') self.assertEqual(standing_dirs, set(listdir(RESUMES_BY_YEAR_LOCATION())))
def compile_resumes(include_alums=False): media_parent = '/'.join(settings.MEDIA_ROOT.split('/')[:-2]) + '/' if os.path.exists(RESUMES_BY_MAJOR_LOCATION()): shutil.rmtree(RESUMES_BY_MAJOR_LOCATION()) os.makedirs(RESUMES_BY_MAJOR_LOCATION()) resource_guides = CorporateResourceGuide.objects.filter(active=True) if resource_guides: shutil.copy( media_parent + resource_guides[0].resource_guide.url, os.path.sep.join([ RESUMES_BY_MAJOR_LOCATION(), slugify(resource_guides[0].name) + '.pdf' ])) for resume_major in Major.objects.all(): query = Q(major=resume_major) users_in_major = MemberProfile.get_members( include_alums=include_alums).filter(query) for user in users_in_major: if user.resume: major_dir = os.path.sep.join( [RESUMES_BY_MAJOR_LOCATION(), slugify(resume_major.name)]) if not os.path.exists(major_dir): os.makedirs(major_dir) resume_name = user.get_resume_name() shutil.copy(media_parent + user.resume.url, os.path.sep.join([major_dir, resume_name])) if os.path.exists(RESUMES_BY_YEAR_LOCATION()): shutil.rmtree(RESUMES_BY_YEAR_LOCATION()) os.makedirs(RESUMES_BY_YEAR_LOCATION()) if resource_guides: shutil.copy( media_parent + resource_guides[0].resource_guide.url, os.path.sep.join([ RESUMES_BY_YEAR_LOCATION(), slugify(resource_guides[0].name) + '.pdf' ])) for standing in Standing.objects.all(): members = MemberProfile.get_members().filter(standing=standing) if standing.name == 'Alumni': if not include_alums: continue status_dir = os.path.sep.join( [RESUMES_BY_YEAR_LOCATION(), slugify(standing.name)]) else: status_dir = os.path.sep.join([ RESUMES_BY_YEAR_LOCATION(), slugify(standing.name) + '-student' ]) if not os.path.exists(status_dir): os.makedirs(status_dir) for user in members: if user.resume: current_grad_year = user.expect_grad_date.year year_dir = os.path.sep.join( [status_dir, 'Graduating' + slugify(current_grad_year)]) if not os.path.exists(year_dir): os.makedirs(year_dir) resume_name = slugify(user.last_name + '_' + user.first_name + '_' + user.uniqname) + '.pdf' shutil.copy(media_parent + user.resume.url, os.path.sep.join([year_dir, resume_name]))