Ejemplo n.º 1
0
def step2(request, teacher, lesson_type, date, time):
    hat = SortingHat(
        customer=request.user.crm,
        teacher=get_object_or_404(Teacher, pk=teacher),
        lesson_type=lesson_type,  # numeric
        date=date,
        time=time,
    )

    hat.do_the_thing()  # do the actual scheduling

    if 'check' in request.GET.keys():
        return JsonResponse({
            'result': hat.result,
            'error': hat.err,
            'text': hat.msg,
        })

    if not hat.result:
        logger.warning('Step 2 scheduling error'
                       )  # write a log entry to Sentry for future processing
        raise Http404('%s: %s' % (hat.err, hat.msg))

    hat.c.save()  # save a hat-generated class
    return redirect('/')  # TODO: a page with success story
Ejemplo n.º 2
0
 def poll(self):
     """
     Fetch a calendar, then parse it and populate the `event` property with
     events from it.
     """
     try:
         res = self.fetch_calendar(self.url)
     except:
         logger.warning('Could not fetch google calendar')
         self.events = []
     else:
         self.events = list(event for event in self.parse_events(res))
Ejemplo n.º 3
0
    def send(self):
        """
        Send message

        On the production host uses celery, on dev — django configured backend.
        """
        if not self.clean():
            logger.warning('Trying to send invalid message!')
            return

        if not settings.EMAIL_ASYNC:
            self.msg.send()
        else:
            self.queue()
Ejemplo n.º 4
0
def bill_timeline_entries():
    for entry in TimelineEntry.objects.to_be_marked_as_finished().filter(
            taken_slots__gte=1):
        entry.is_finished = True
        entry.save()

        if not AccEvent.objects.by_originator(entry).count():
            ev = AccEvent(
                teacher=entry.teacher,
                originator=entry,
                event_type='class',
            )
            ev.save()
        else:
            logger.warning('Tried to bill already billed timeline entry')
Ejemplo n.º 5
0
    def update(self):
        """
        Clean previous stored events generated by the source and store new ones.

        Notifies support when unsafe calendar update is performed, i.e. too much events got deleted.
        """
        if not self.__is_safe():  # warn admins if calendar update is unsafe
            logger.warning('Unsafe calendar update')

        self.__clear_previous_events()
        self.__save_events()

        if self.events:
            self.last_update = timezone.now()
            self.save()
Ejemplo n.º 6
0
    def parse_events(self, ical_str):
        """
        Generator of events parsed from ical_str.
        """
        try:
            ical = Calendar.from_ical(ical_str)
        except:
            logger.warning('Could not parse ical string')
            raise StopIteration

        yield from self._simple_events(
            ical)  # first, parse all non-recurring events
        yield from self._recurring_events(
            ical
        )  # second — generate instances of ExternalEvent for every recurring event
Ejemplo n.º 7
0
def save_country(strategy,
                 backend,
                 user,
                 response,
                 is_new=False,
                 *args,
                 **kwargs):
    """
    Save country guessed by geotargeting
    """
    if not is_new:
        return

    country = strategy.session_get('country')
    if country is not None:
        try:
            user.crm.country = country
            user.crm.save()
        except:
            logger.warning("Incorrect country during self-registration")
Ejemplo n.º 8
0
def save_timezone(strategy,
                  backend,
                  user,
                  response,
                  is_new=False,
                  *args,
                  **kwargs):
    if not is_new:
        return

    timezone = strategy.session_get('guessed_timezone')

    if timezone is not None:
        try:
            user.crm.timezone = timezone
            user.crm.save()
        except ValidationError:
            logger.warning("Incorrect timezone during self-registration")

    else:
        logger.warning("Could not guess timezone during self-registration")