def get_valid_semesters(): semesters = [] now = datetime.datetime.now() if now.month == 7 or now.month == 8 or now.month == 1: semesters.append(get_semester(-1)) semesters.append(get_semester()) return semesters
def get_valid_semesters(): semesters = [] now = datetime.datetime.now() if now.month == 7 or now.month == 8 or now.month == 1: semesters.append(get_semester(-1)) # Corona-exception in 2020. if now.year == 2020 and now.month == 9: semesters.append(get_semester(-1)) # Corona-exception in 2021 if now.year == 2021 and now.month in [6, 7]: semesters.append(get_semester_of_date(datetime.date(2020, 12, 1))) semesters.append(get_semester()) return semesters
def create(self, request, *args, **kwargs): serializer = AddInternRoleSerializer(data=request.data) serializer.is_valid(raise_exception=True) username = serializer.data['username'] user = User.objects.get_or_create(username=username)[0] intern = Intern.objects.get_or_create(user=user)[0] role = Role.objects.get(pk=serializer.data['role']) internrole = InternRole.objects.get_or_create(intern=intern, role=role)[0] creator = User.objects.get(username=request.user) # if the user have been active before we remove the old date_removed and add a comment if internrole.date_removed is not None: internrole.date_removed = None internrole.removed_by = None intern.add_log_entry(creator, '[%s] Recreated' % internrole) else: internrole.created_by = creator intern.add_log_entry(creator, '%s by %s' % (internrole, creator)) internrole.last_editor = creator intern.update_left() internrole.semesters.add(get_semester()) try: internrole.save() except IntegrityError: return Response( {'error': ('Error when adding internrole: %s %s. It already exist' % (role.name, user.username)) }, status=status.HTTP_406_NOT_ACCEPTABLE ) return Response(InternRoleFullSerializer(internrole).data, status=status.HTTP_201_CREATED)
def make_memberships(self): self.memberships.all().delete() for m in self.user.memberships.filter( role__gt=settings.SITH_MAXIMUM_FREE_ROLE).order_by("end_date"): role = str(settings.SITH_CLUB_ROLES[m.role]) if m.description: role += " (%s)" % m.description if m.end_date: end_date = get_semester(m.end_date) else: end_date = "" TrombiClubMembership( user=self, club=str(m.club), role=role[:64], start=get_semester(m.start_date), end=end_date, ).save()