コード例 #1
0
ファイル: views.py プロジェクト: matfystutor/web
    def get_context_data(self, **kwargs):
        context_data = super(TutorListView, self).get_context_data(**kwargs)
        group = self.kwargs.get("group")
        if group is None:
            tutors = Tutor.members(self.request.year)
            best = TutorGroup.objects.get(handle="best", year=self.request.year)
            leader = best.leader
        else:
            tg = get_object_or_404(TutorGroup, handle=group, year=self.request.year)
            tutors = Tutor.group_members(tg)
            leader = tg.leader

        leader_pk = leader.pk if leader else 0

        def make_tutor_dict(t):
            return {
                "pk": t.pk,
                "studentnumber": t.profile.studentnumber,
                "picture": t.profile.picture.url if t.profile.picture else "",
                "full_name": t.profile.get_full_name(),
                "street": t.profile.street,
                "city": t.profile.city,
                "phone": t.profile.phone,
                "email": t.profile.email,
                "study": t.profile.study,
            }

        tutors = [make_tutor_dict(t) for t in tutors]
        if group == "tutorsmiley" and self.request.year in [2015]:
            tutors.append(
                {
                    "pk": ":)",
                    "studentnumber": "88888888",
                    "picture": "/upload/tutorpics/smiley.png",
                    "full_name": "Smiley",
                    "street": "Skovbrynet 5",
                    "city": "Smilets By",
                    "phone": "88888888",
                    "email": "SMILEY@SMILEY.☺",
                    "study": "Smil",
                }
            )
        tutors.sort(key=lambda t: (t["pk"] != leader_pk, t["full_name"]))

        groups = TutorGroup.visible_groups.all()

        context_data["group"] = group
        context_data["tutor_list"] = tutors
        context_data["groups"] = groups
        context_data["tutor_count"] = len(tutors)
        context_data["leader_pk"] = leader_pk
        if leader_pk:
            try:
                context_data["leader"] = next(t for t in tutors if t["pk"] == leader_pk)
            except StopIteration:
                # leader is not in tutors
                context_data["leader"] = make_tutor_dict(Tutor.objects.get(pk=leader_pk))
        return context_data
コード例 #2
0
def create_tutors(tp_dict):
    existing = {
        tutor.profile.studentnumber: tutor
        for tutor in Tutor.members(YEAR)
    }
    create = []
    for studentnumber, tp in tp_dict.items():
        if studentnumber in existing:
            continue
        t = Tutor(year=YEAR, profile=tp)
        create.append(t)
        existing[studentnumber] = t

    def save_tutors():
        for tutor in create:
            tutor.save()

    return existing, save_tutors
コード例 #3
0
ファイル: views.py プロジェクト: housa/web
    def get_recipients(self, form, year):
        # All members
        tutors = Tutor.members(year)

        # Exclude non-blank confirmations
        # A blank confirmation is one where only internal_notes is nonempty
        tutors = tutors.exclude(
            Q(confirmation__pk__gt=0)
            & ~Q(confirmation__priorities=''))

        tutors = tutors.select_related('profile')
        return sorted([tu.profile.email for tu in tutors])
コード例 #4
0
ファイル: views.py プロジェクト: frederik1904/web
    def get_recipients(self, form, year):
        # All members
        tutors = Tutor.members(year)

        # Exclude non-blank confirmations
        # A blank confirmation is one where only internal_notes is nonempty
        tutors = tutors.exclude(
            Q(confirmation__pk__gt=0)
            & ~Q(confirmation__tutortype=''))

        tutors = tutors.select_related('profile')
        return sorted([tu.profile.email for tu in tutors])
コード例 #5
0
def event_detail_view(request, eventid):
    event = get_object_or_404(Event.objects.filter(pk=eventid))

    if request.tutor:
        try:
            instance = EventParticipant.objects.get(
                event=event, tutor=request.tutor)
        except EventParticipant.DoesNotExist:
            instance = EventParticipant()

        if request.method == 'POST':
            form = RSVPForm(
                data=request.POST, instance=instance,
                expect_event=event, expect_tutor=request.tutor)
            if form.is_valid():
                form.save()
        else:
            form = RSVPForm(instance=instance,
                            expect_event=event, expect_tutor=request.tutor)
    else:
        form = None

    rsvps = {p.tutor.pk: p for p in event.participants.all()}
    if event.rsvp != None:
        for tu in Tutor.members(request.year):
            rsvps.setdefault(tu.pk, EventParticipant(tutor=tu))
    accept = []
    decline = []
    no_answer = []
    for rsvp in rsvps.values():
        if rsvp.status == 'yes':
            accept.append(rsvp.tutor)
        elif rsvp.status == 'no':
            decline.append(rsvp.tutor)
        else:
            no_answer.append(rsvp.tutor)
    accept.sort(key=lambda tu: tu.profile.name)
    decline.sort(key=lambda tu: tu.profile.name)
    no_answer.sort(key=lambda tu: tu.profile.name)

    return render(
        request,
        'event.html',
        {
            'event': event,
            'rsvpform': form,
            'accept': accept,
            'decline': decline,
            'no_answer': no_answer,
        },
        RequestContext(request),
    )
コード例 #6
0
ファイル: views.py プロジェクト: tjavsi/web
 def get_context_data(self, **kwargs):
     context_data = (super(EventParticipantListView, self)
                     .get_context_data(**kwargs))
     event = context_data['event']
     participants = {p.tutor_id: p for p in event.participants.all()}
     names = {}
     tutors = {}
     for tutor in Tutor.members(self.request.year):
         names[tutor.pk] = tutor.profile.name
         tutors[tutor.pk] = participants.setdefault(
             tutor.pk, EventParticipant(event=event, tutor=tutor))
     tutors = sorted(tutors.values(), key=lambda o: names[o.tutor.pk])
     context_data['tutors'] = tutors
     return context_data
コード例 #7
0
ファイル: views.py プロジェクト: frederik1904/web
 def get_tutors(self):
     tutors = list(Tutor.members(self.request.year))
     sp = ShirtPreference.objects.filter(profile__tutor__in=tutors)
     sp_dict = {s.profile.pk: s for s in sp}
     for tu in tutors:
         try:
             s = sp_dict[tu.profile.pk]
         except KeyError:
             s = ShirtPreference()
         tu.choice1 = s.choice1
         tu.choice2 = s.choice2
         tu.choice_created = s.created
         tu.choice_updated = s.updated
     tutors.sort(key=lambda tu: (0, tu.profile.name) if tu.choice_updated is None or tu.choice1 in ('', 'Ingen') else (1, tu.choice_updated))
     return tutors
コード例 #8
0
ファイル: create_tutors.py プロジェクト: matfystutor/web
def create_tutors(tp_dict):
    existing = {tutor.profile.studentnumber: tutor
                for tutor in Tutor.members(YEAR)}
    create = []
    for studentnumber, tp in tp_dict.items():
        if studentnumber in existing:
            continue
        t = Tutor(year=YEAR, profile=tp)
        create.append(t)
        existing[studentnumber] = t

    def save_tutors():
        for tutor in create:
            tutor.save()
    
    return existing, save_tutors
コード例 #9
0
def main():
    tutors = list(Tutor.members(2017))
    passwords = pwgen(len(tutors))
    output = {}
    users = []
    for tutor, password in zip(tutors, passwords):
        studentnumber = tutor.profile.studentnumber
        if studentnumber == '201400573':
            print("Skip Alexandra")
            output[studentnumber] = 'bla'
            continue
        user = tutor.profile.get_or_create_user()
        output[studentnumber] = password
        user.set_password(password)
        users.append(user)
    with open('passwords_2017.json', 'w') as fp:
        json.dump(output, fp, indent=2)
コード例 #10
0
ファイル: views.py プロジェクト: matfystutor/web
    def __init__(self, year, groups, *args, **kwargs):
        super(GroupLeaderForm, self).__init__(*args, **kwargs)
        self.tutor_year = year

        for i, group in enumerate(groups):
            tutors = list(Tutor.members(year).filter(groups=group))
            choices = [(tu.pk, tu.profile.name) for tu in tutors]
            if group.leader and group.leader not in tutors:
                name = "%s (ej medlem)" % group.leader.profile.name
                choices.append((group.leader.pk, name))
            choices[0:0] = [("", "")]

            current_leader = group.leader.pk if group.leader else ""

            self.fields["group_%s" % group.pk] = forms.ChoiceField(
                label=group.name, required=False, choices=choices, initial=current_leader
            )
コード例 #11
0
ファイル: set_passwords_2017.py プロジェクト: matfystutor/web
def main():
    tutors = list(Tutor.members(2017))
    passwords = pwgen(len(tutors))
    output = {}
    users = []
    for tutor, password in zip(tutors, passwords):
        studentnumber = tutor.profile.studentnumber
        if studentnumber == '201400573':
            print("Skip Alexandra")
            output[studentnumber] = 'bla'
            continue
        user = tutor.profile.get_or_create_user()
        output[studentnumber] = password
        user.set_password(password)
        users.append(user)
    with open('passwords_2017.json', 'w') as fp:
        json.dump(output, fp, indent=2)
コード例 #12
0
ファイル: views.py プロジェクト: frederik1904/web
 def save_tutor_from_applications(applications, dry_run=False):
     for application in applications:
         try:
             tutor = Tutor.objects.get(
                 profile=application.profile,
                 year=application.year,
             )
         except Tutor.DoesNotExist:
             tutor = Tutor(
                 profile=application.profile,
                 year=application.year,
             )
             if not dry_run:
                 tutor.save()
         if not dry_run:
             tutor.groups = application.assigned_groups.all()
             tutor.save()
コード例 #13
0
ファイル: views.py プロジェクト: frederik1904/web
    def __init__(self, year, groups, *args, **kwargs):
        super(GroupLeaderForm, self).__init__(*args, **kwargs)
        self.tutor_year = year

        for i, group_dict in enumerate(groups):
            group = TutorGroup.objects.get(pk=group_dict["pk"])

            tutors = list(Tutor.members(year).filter(groups=group))
            choices = [(tu.pk, tu.profile.name) for tu in tutors]
            if group.leader and group.leader not in tutors:
                name = '%s (ej medlem)' % group.leader.profile.name
                choices.append((group.leader.pk, name))
            choices[0:0] = [('', '')]

            current_leader = group.leader.pk if group.leader else ''

            self.fields['group_%s' % group.pk] = forms.ChoiceField(
                label=group.name,
                required=False,
                choices=choices,
                initial=current_leader)
コード例 #14
0
ファイル: views.py プロジェクト: tjavsi/web
 def get_context_data(self, **kwargs):
     context = super(ConfirmationListView, self).get_context_data(**kwargs)
     members = Tutor.members(self.request.year)
     # TODO does this ensure O(1) database lookups?
     members = members.select_related('confirmation', 'profile')
     members = members.prefetch_related('profile__rus_set',
                                        'profile__rus_set__rusclass')
     confirmations = []
     for t in members:
         try:
             c = t.confirmation
             c.study_short = parse_study(c.study)
             c.rusclass = [r.rusclass for r in t.profile.rus_set.all()]
             confirmations.append(c)
         except Confirmation.DoesNotExist:
             study = t.profile.study
             c = Confirmation(tutor=t, study=study)
             c.study_short = study
             confirmations.append(c)
     context['confirmation_list'] = sorted(
         confirmations, key=lambda c: c.tutor.profile.get_full_name())
     return context
コード例 #15
0
ファイル: views.py プロジェクト: matfystutor/web
 def save_tutor_from_applications(applications, dry_run=False):
     for application in applications:
         try:
             tutor = Tutor.objects.get(
                 profile=application.profile,
                 year=application.year,
             )
         except Tutor.DoesNotExist:
             tutor = Tutor(
                 profile=application.profile,
                 year=application.year,
             )
             if not dry_run:
                 tutor.save()
         if not dry_run:
             tutor.groups = application.assigned_groups.all()
             tutor.save()
コード例 #16
0
ファイル: views.py プロジェクト: housa/web
 def get_context_data(self, **kwargs):
     context = super(ConfirmationListView, self).get_context_data(**kwargs)
     members = Tutor.members(self.request.year)
     # TODO does this ensure O(1) database lookups?
     members = members.select_related('confirmation', 'profile')
     members = members.prefetch_related(
         'profile__rus_set', 'profile__rus_set__rusclass')
     confirmations = []
     for t in members:
         try:
             c = t.confirmation
             c.study_short = parse_study(c.study)
             c.rusclass = [r.rusclass for r in t.profile.rus_set.all()]
             confirmations.append(c)
         except Confirmation.DoesNotExist:
             study = t.profile.study
             c = Confirmation(tutor=t, study=study)
             c.study_short = study
             confirmations.append(c)
     context['confirmation_list'] = sorted(
         confirmations,
         key=lambda c: c.tutor.profile.get_full_name())
     return context
コード例 #17
0
ファイル: views.py プロジェクト: matfystutor/web
    def __init__(self, year, groups, *args, **kwargs):
        super(GroupLeaderForm, self).__init__(*args, **kwargs)
        self.tutor_year = year

        for i, group_dict in enumerate(groups):
            group = TutorGroup.objects.get(pk=group_dict["pk"])

            tutors = list(Tutor.members(year).filter(groups=group))
            choices = [
                (tu.pk, tu.profile.name)
                for tu in tutors
            ]
            if group.leader and group.leader not in tutors:
                name = '%s (ej medlem)' % group.leader.profile.name
                choices.append((group.leader.pk, name))
            choices[0:0] = [('', '')]

            current_leader = group.leader.pk if group.leader else ''

            self.fields['group_%s' % group.pk] = forms.ChoiceField(
                label=group.name,
                required=False,
                choices=choices,
                initial=current_leader)
コード例 #18
0
ファイル: views.py プロジェクト: housa/web
 def get_queryset_base(self):
     return Tutor.members(self.request.year)
コード例 #19
0
ファイル: views.py プロジェクト: frederik1904/web
    def get_context_data(self, **kwargs):
        context_data = super(TutorListView, self).get_context_data(**kwargs)
        group = self.kwargs.get('group')
        if group is None:
            tutors = Tutor.members(self.request.year)
            best = TutorGroup.objects.get(handle='best',
                                          year=self.request.year)
            leader = best.leader
        else:
            tg = get_object_or_404(TutorGroup,
                                   handle=group,
                                   year=self.request.year)
            tutors = Tutor.group_members(tg)
            leader = tg.leader

        leader_pk = leader.pk if leader else 0

        def make_tutor_dict(t):
            return {
                'pk': t.pk,
                'studentnumber': t.profile.studentnumber,
                'picture': t.profile.picture,
                'full_name': t.profile.get_full_name(),
                'street': t.profile.street,
                'city': t.profile.city,
                'phone': t.profile.phone,
                'email': t.profile.email,
                'study': t.profile.study,
                'nickname': t.profile.nickname,
            }

        tutors = [make_tutor_dict(t) for t in tutors]
        if group == 'tutorsmiley' and self.request.year in [2015]:
            tutors.append({
                'pk': ':)',
                'studentnumber': '88888888',
                'picture': None,
                'full_name': 'Smiley',
                'street': 'Skovbrynet 5',
                'city': 'Smilets By',
                'phone': '88888888',
                'email': 'SMILEY@SMILEY.☺',
                'study': 'Smil',
            })
        tutors.sort(key=lambda t: (t['pk'] != leader_pk, t['full_name']))

        groups = TutorGroup.visible_groups.all()

        context_data['group'] = group
        context_data['tutor_list'] = tutors
        context_data['groups'] = groups
        context_data['tutor_count'] = len(tutors)
        context_data['leader_pk'] = leader_pk
        if leader_pk:
            try:
                context_data['leader'] = next(t for t in tutors
                                              if t['pk'] == leader_pk)
            except StopIteration:
                # leader is not in tutors
                context_data['leader'] = make_tutor_dict(
                    Tutor.objects.get(pk=leader_pk))
        return context_data
コード例 #20
0
    group_by_handle = {
        g.handle: g for g in TutorGroup.objects.filter(
            year=2016, handle__in=group_aliases.values())
    }

    new_tutor = []
    new_password = []
    new_groups = []
    group_leaders = []
    for entry in approved_entries:
        sn = entry['Årskortnummer']
        tp = tutorprofiles_by_sn[sn]
        entry['tutorprofile'] = tp
        if sn not in existing_sn:
            tu = Tutor(year=2016, profile=tp)
            new_tutor.append(tu)
            # print(new_tutor[-1])
            # tu.save()
            raise Exception("Did not exist")
        else:
            tu = existing_sn[sn]

        group_names = [entry['GRUPPE 1'], entry['GRUPPE 2']]
        group_names = [s for s in group_names if s != '-']
        group_handles = [group_aliases[g] for g in group_names]
        group_objects = [group_by_handle[g] for g in group_handles]

        for g in group_objects:
            new_groups.append((tu, g))
コード例 #21
0
ファイル: tutormail2017.py プロジェクト: matfystutor/web
def main():
    with open('passwords_2017.json') as fp:
        passwords = json.load(fp)
    emails = []
    for tutor in Tutor.members(2017):
        tp = tutor.profile
        groups = tutor.groups.filter(visible=True)

        arbejdstutor = any(g.handle == 'arbejdstutor' for g in groups)
        buret = any(g.handle == 'buret' for g in groups)
        normal_groups = [g for g in groups
                         if g.handle not in ('arbejdstutor', 'buret')]
        group_names = [g.name for g in normal_groups]
        ansv_names = [g.name for g in normal_groups if g.leader == tutor]
        context = dict(
            navn=tp.name.strip(),
            year=YEAR,
            studentnumber=tp.studentnumber,
            groups=' og '.join(group_names),
            webfar='Alexandra Hou',
            password=passwords[tp.studentnumber],
            group=' og '.join(ansv_names),
        )

        # afvist.txt: navn, year
        # ansv.txt: navn, year, studentnumber, password, groups, group, webfar
        # buret.txt: navn, groups, studentnumber, password, webfar
        # buretansv.txt: navn, groups, studentnumber, password, group, webfar
        # tutors.txt: navn, year, studentnumber, password, groups, webfar

        if buret:
            if ansv_names:
                tpl = 'buretansv.txt'
                subject = 'Du er blevet gruppeansvarlig!'
            else:
                tpl = 'buret.txt'
                subject = 'Du er blevet tutor!'
        elif arbejdstutor:
            if ansv_names:
                tpl = 'arbejdansv.txt'
                subject = 'Du er blevet gruppeansvarlig!'
            else:
                tpl = 'arbejd.txt'
                subject = 'Du er blevet tutor!'
        else:
            if ansv_names:
                tpl = 'ansv.txt'
                subject = 'Du er blevet gruppeansvarlig!'
            else:
                tpl = 'tutors.txt'
                subject = 'Du er blevet tutor!'

        tpl = get_template('emails/%s' % tpl)

        email_body = tpl.render(context)

        email = EmailMessage(
            subject=subject,
            body=email_body,
            from_email='"Alexandra Hou" <*****@*****.**>',
            to=[tp.email],
        )

        emails.append(email)

    # emails = [
    #     email
    #     for email in emails
    #     if '*****@*****.**' in email.to
    # ]

    with codecs.open('email2017.txt', 'w', encoding='utf-8') as fp:
        for email in emails:
            fp.write(79*'=' + '\n')
            fp.write("Fra: %s\n" % email.from_email)
            fp.write("Til: %s\n" % email.to[0])
            fp.write("Emne: %s\n" % email.subject)
            fp.write('\n%s\n' % (email.body))
コード例 #22
0
ファイル: tutormail2017.py プロジェクト: tjavsi/web
def main():
    with open('passwords_2017.json') as fp:
        passwords = json.load(fp)
    emails = []
    for tutor in Tutor.members(2017):
        tp = tutor.profile
        groups = tutor.groups.filter(visible=True)

        arbejdstutor = any(g.handle == 'arbejdstutor' for g in groups)
        buret = any(g.handle == 'buret' for g in groups)
        normal_groups = [
            g for g in groups if g.handle not in ('arbejdstutor', 'buret')
        ]
        group_names = [g.name for g in normal_groups]
        ansv_names = [g.name for g in normal_groups if g.leader == tutor]
        context = dict(
            navn=tp.name.strip(),
            year=YEAR,
            studentnumber=tp.studentnumber,
            groups=' og '.join(group_names),
            webfar='Alexandra Hou',
            password=passwords[tp.studentnumber],
            group=' og '.join(ansv_names),
        )

        # afvist.txt: navn, year
        # ansv.txt: navn, year, studentnumber, password, groups, group, webfar
        # buret.txt: navn, groups, studentnumber, password, webfar
        # buretansv.txt: navn, groups, studentnumber, password, group, webfar
        # tutors.txt: navn, year, studentnumber, password, groups, webfar

        if buret:
            if ansv_names:
                tpl = 'buretansv.txt'
                subject = 'Du er blevet gruppeansvarlig!'
            else:
                tpl = 'buret.txt'
                subject = 'Du er blevet tutor!'
        elif arbejdstutor:
            if ansv_names:
                tpl = 'arbejdansv.txt'
                subject = 'Du er blevet gruppeansvarlig!'
            else:
                tpl = 'arbejd.txt'
                subject = 'Du er blevet tutor!'
        else:
            if ansv_names:
                tpl = 'ansv.txt'
                subject = 'Du er blevet gruppeansvarlig!'
            else:
                tpl = 'tutors.txt'
                subject = 'Du er blevet tutor!'

        tpl = get_template('emails/%s' % tpl)

        email_body = tpl.render(context)

        email = EmailMessage(
            subject=subject,
            body=email_body,
            from_email='"Alexandra Hou" <*****@*****.**>',
            to=[tp.email],
        )

        emails.append(email)

    # emails = [
    #     email
    #     for email in emails
    #     if '*****@*****.**' in email.to
    # ]

    with codecs.open('email2017.txt', 'w', encoding='utf-8') as fp:
        for email in emails:
            fp.write(79 * '=' + '\n')
            fp.write("Fra: %s\n" % email.from_email)
            fp.write("Til: %s\n" % email.to[0])
            fp.write("Emne: %s\n" % email.subject)
            fp.write('\n%s\n' % (email.body))
コード例 #23
0
ファイル: views.py プロジェクト: matfystutor/web
    def get_context_data(self, **kwargs):
        context_data = super(TutorListView, self).get_context_data(**kwargs)
        group = self.kwargs.get('group')
        if group is None:
            tutors = Tutor.members(self.request.year)
            best = TutorGroup.objects.get(
                handle='best', year=self.request.year)
            leader = best.leader
        else:
            tg = get_object_or_404(
                TutorGroup, handle=group, year=self.request.year)
            tutors = Tutor.group_members(tg)
            leader = tg.leader

        leader_pk = leader.pk if leader else 0

        def make_tutor_dict(t):
            return {
                'pk': t.pk,
                'studentnumber': t.profile.studentnumber,
                'picture': t.profile.picture,
                'full_name': t.profile.get_full_name(),
                'street': t.profile.street,
                'city': t.profile.city,
                'phone': t.profile.phone,
                'email': t.profile.email,
                'study': t.profile.study,
                'nickname': t.profile.nickname,
            }

        tutors = [make_tutor_dict(t) for t in tutors]
        if group == 'tutorsmiley' and self.request.year in [2015]:
            tutors.append({
                'pk': ':)',
                'studentnumber': '88888888',
                'picture': None,
                'full_name': 'Smiley',
                'street': 'Skovbrynet 5',
                'city': 'Smilets By',
                'phone': '88888888',
                'email': 'SMILEY@SMILEY.☺',
                'study': 'Smil',
            })
        tutors.sort(key=lambda t: (t['pk'] != leader_pk, t['full_name']))

        groups = TutorGroup.visible_groups.all()

        context_data['group'] = group
        context_data['tutor_list'] = tutors
        context_data['groups'] = groups
        context_data['tutor_count'] = len(tutors)
        context_data['leader_pk'] = leader_pk
        if leader_pk:
            try:
                context_data['leader'] = next(
                    t for t in tutors
                    if t['pk'] == leader_pk
                )
            except StopIteration:
                # leader is not in tutors
                context_data['leader'] = make_tutor_dict(
                    Tutor.objects.get(pk=leader_pk))
        return context_data