Exemple #1
0
def should_highlight_future_quarters(registered_future_quarters, request):
    should_highlight = False
    # MUWM-2373

    for term in registered_future_quarters:
        model, newly_created, now_datetime, summer_term =\
            save_seen_registration_obj(get_user_model(), request, term)

        if not newly_created:
            # MUWM-3009
            if summer_term == "B":
                bterm_start_dt = _get_bterm_start(term)
                new_highlight = bterm_start_dt - timedelta(days=8)

                seen_before = model.first_seen_date < bterm_start_dt
                is_after = now_datetime > new_highlight

                if seen_before and is_after:
                    model.first_seen_date = now_datetime
                    model.save()

        days_diff = (now_datetime - model.first_seen_date).days
        # XXX - this needs to be changed when we can set a time in the override
        if days_diff < 1.02:
            should_highlight = True

    return should_highlight
Exemple #2
0
def should_highlight_future_quarters(schedule, request):
    should_highlight = False
    # MUWM-2373
    now = get_comparison_date(request)

    for term in schedule:
        summer_term = "F"
        if term["summer_term"] == "a-term":
            summer_term = "A"
        if term["summer_term"] == "b-term":
            summer_term = "B"

        sr_get_or_create = SeenRegistration.objects.get_or_create
        model, created = sr_get_or_create(user=get_user_model(),
                                          year=term["year"],
                                          quarter=term["quarter"],
                                          summer_term=summer_term,
                                          )

        # Want to make sure that we have a full day, not just today/tomorrow
        actual_now = timezone.now()
        now_datetime = datetime(now.year, now.month, now.day, actual_now.hour,
                                actual_now.minute, actual_now.second,
                                tzinfo=actual_now.tzinfo)
        if created:
            model.first_seen_date = now_datetime
            model.save()
        else:
            # MUWM-3009
            if summer_term == "B":
                term_obj = get_quarter(term["year"], "summer")

                bterm_start = term_obj.bterm_first_date
                bterm_start_dt = datetime(bterm_start.year,
                                          bterm_start.month,
                                          bterm_start.day,
                                          0, 0, 0, tzinfo=actual_now.tzinfo)

                new_highlight = bterm_start_dt - timedelta(days=8)

                seen_before = model.first_seen_date < bterm_start_dt
                is_after = now_datetime > new_highlight

                if seen_before and is_after:
                    model.first_seen_date = now_datetime
                    model.save()

        days_diff = (now_datetime - model.first_seen_date).days
        # XXX - this needs to be changed when we can set a time in the override
        if days_diff < 1.02:
            should_highlight = True

    return should_highlight
Exemple #3
0
def _store_tuition_notice_date(notice):
    for attrib in notice.attributes:
        if attrib.name == "Date":
            defaults = {'date': attrib.get_value()}
            td_get_or_create = TuitionDate.objects.get_or_create
            tuition_date, created = td_get_or_create(user=get_user_model(),
                                                     defaults=defaults)
            if not created:
                tuition_date.date = attrib.get_value()
                tuition_date.save()
            return tuition_date
    return None
Exemple #4
0
def get_tuition_due_date():
    tuition_date = None
    notices = get_notices_for_current_user()
    for notice in notices:
        if _is_tuition_due_notice(notice):
            tuition_notice = _store_tuition_notice_date(notice)
            if tuition_notice is not None:
                tuition_date = tuition_notice.date
    if tuition_date is None:
        try:
            stored_tuition = TuitionDate.objects.get(user=get_user_model())
            tuition_date = stored_tuition.date
        except:
            pass
    return tuition_date
Exemple #5
0
def _get_user_notices(notices):
    user = get_user_model()
    notice_dict = {}
    notices_with_read_status = []
    # Get all notice hashes
    for notice in notices:
        notice_hash = UserNotices().generate_hash(notice)
        notice.id_hash = notice_hash
        notice.is_read = False
        notice_dict[notice_hash] = notice

    # Set read status for notices already in db
    keys = notice_dict.keys()
    user_notices = UserNotices.objects.filter(user=user,
                                              notice_hash__in=keys)
    for user_notice in user_notices:
        matched_notice = notice_dict[user_notice.notice_hash]
        matched_notice.is_read = user_notice.is_read
        notices_with_read_status.append(matched_notice)
        del notice_dict[user_notice.notice_hash]

    # Create UserNotices for new notices
    user_notices_to_create = []
    for notice in notice_dict.values():
        user_notice = UserNotices()
        user_notice.notice_hash = notice.id_hash
        user_notice.user = user
        cattype = notice.notice_category + notice.notice_type
        user_notice.notice_cattype = cattype

        user_notices_to_create.append(user_notice)

    try:
        UserNotices.objects.bulk_create(user_notices_to_create)
    except IntegrityError:
        # MUWM-2016.  This should be rare - 2 processes running at just about
        # exactly the same time.  In that case especially, the bulk create list
        # should be the same.  And if it isn't, big deal?
        pass

    # Add newly created UserNotices into returned list
    notices_with_read_status = notices_with_read_status + notice_dict.values()
    return notices_with_read_status
Exemple #6
0
def add_seen_registration_context(request, context):
    user = get_user_model()

    seen_registrations = SeenRegistration.objects.filter(user=user)
    seen = []

    from_zone = tz.tzutc()
    to_zone = tz.tzlocal()
    to_zone = pytz.timezone("America/Los_Angeles")

    for reg in seen_registrations:

        seen_date = reg.first_seen_date
        utc = seen_date.replace(tzinfo=from_zone)
        local = utc.astimezone(to_zone)

        seen.append({
            'year': reg.year,
            'quarter': reg.quarter,
            'summer': reg.summer_term,
            'date_seen': local.__str__(),
        })

    context['seen_registrations'] = seen
Exemple #7
0
def add_seen_registration_context(request, context):
    user = get_user_model()

    seen_registrations = SeenRegistration.objects.filter(user=user)
    seen = []

    from_zone = tz.tzutc()
    to_zone = tz.tzlocal()
    to_zone = pytz.timezone("America/Los_Angeles")

    for reg in seen_registrations:

        seen_date = reg.first_seen_date
        utc = seen_date.replace(tzinfo=from_zone)
        local = utc.astimezone(to_zone)

        seen.append({
            'year': reg.year,
            'quarter': reg.quarter,
            'summer': reg.summer_term,
            'date_seen': local.__str__(),
        })

    context['seen_registrations'] = seen
Exemple #8
0
def mark_notices_read_for_current_user(notice_hashes):
    user = get_user_model()
    UserNotices().mark_notices_read(notice_hashes, user)