Пример #1
0
    def get(self):
        user = self.must_get_user()
        event_id = self.get_argument('id')
        timestamp_only = niceboolean(self.get_argument('timestamp_only',
                                                       False))
        _search = {'user.$id': user._id, '_id': ObjectId(event_id)}

        event = self.db.Event.one(_search)
        if not event:
            self.write_json(dict(error="ERROR: Invalid Event"))
            return

        timestamp = mktime(event['modify_date'].timetuple())
        data = dict(timestamp=timestamp)
        if not timestamp_only:
            event_data = dict(title=event['title'],
                              id=str(event['_id']),
                              all_day=event['all_day'],
                              description=event['description'])
            if event['all_day']:
                event_data['days'] = 1 + (event['end'] - event['start']).days
            else:
                event_data['hours'] = (event['end'] -
                                       event['start']).seconds / 60.0 / 60
            data['event'] = self.serialize_dict(event_data)
        self.write_json(data)
Пример #2
0
    def get(self):
        user = self.must_get_user()
        event_id = self.get_argument('id')
        timestamp_only = niceboolean(self.get_argument('timestamp_only', False))
        _search = {'user.$id':user._id,
                   '_id': ObjectId(event_id)}

        event = self.db.Event.one(_search)
        if not event:
            self.write_json(dict(error="ERROR: Invalid Event"))
            return

        timestamp = mktime(event['modify_date'].timetuple())
        data = dict(timestamp=timestamp)
        if not timestamp_only:
            event_data = dict(title=event['title'],
                              id=str(event['_id']),
                              all_day=event['all_day'],
                              description=event['description']
                              )
            if event['all_day']:
                event_data['days'] = 1 + (event['end'] - event['start']).days
            else:
                event_data['hours'] = (event['end'] - event['start']).seconds / 60.0 / 60
            data['event'] = self.serialize_dict(event_data)
        self.write_json(data)
Пример #3
0
    def get(self):
        user = self.must_get_user()
        year = int(self.get_argument('year'))
        month = int(self.get_argument('month'))
        day = int(self.get_argument('day'))
        timestamp_only = niceboolean(self.get_argument('timestamp_only',
                                                       False))
        _search = {'user.$id': user._id}
        date = datetime.datetime(year, month, day, 0, 0, 0)

        timestamp = 0
        for event in self.db.Event.collection\
                  .find(dict(_search,
                             start={'$gte': date, '$lt':date + datetime.timedelta(days=1)}))\
                  .limit(1).sort('modify_date', -1):
            # the reason we're after the modify_date is because we ultimately
            # need to know the latest something was changed in this day.
            timestamp = mktime(event['modify_date'].timetuple())
            break

        if not timestamp_only:
            events = []
            days_spent = hours_spent = None
            for each in self.db.Event.collection\
                  .find(dict(_search,
                             start={'$gte': date, '$lt':date + datetime.timedelta(days=1)})):
                if days_spent is None:
                    days_spent = hours_spent = 0.0

                event = dict(
                    id=str(each['_id']),
                    all_day=each['all_day'],
                    title=each['title'],
                    #tags=each['tags'],
                )
                event['description'] = each['description']
                event['external_url'] = each['external_url']
                if each['all_day']:
                    event['days'] = 1 + (each['end'] - each['start']).days
                else:
                    event['hours'] = (each['end'] -
                                      each['start']).seconds / 60.0 / 60
                event['length'] = self.describe_length(each)
                events.append(event)
                #if each['all_day']:
                #    days_spent += 1 + (each['end'] - each['start']).days
                #else:
                #    hours_spent += (each['end'] - each['start']).seconds / 60.0 / 60

        data = dict(timestamp=timestamp)
        if not timestamp_only:
            data['events'] = events
            #if days_spent or hours_spent:
            #    data['totals'] = dict()
            #    # there were some events at least
            #    if days_spent:
            #        data['totals']['days_spent'] = days_spent
            #    if hours_spent:
            #        data['totals']['hours_spent'] = '%.2f' % round(hours_spent, 1)
        self.write_json(data)
Пример #4
0
    def get(self):
        user = self.must_get_user()
        year = int(self.get_argument('year'))
        month = int(self.get_argument('month'))
        day = int(self.get_argument('day'))
        timestamp_only = niceboolean(self.get_argument('timestamp_only', False))
        _search = {'user.$id':user._id}
        date = datetime.datetime(year, month, day, 0, 0, 0)

        timestamp = 0
        for event in self.db.Event.collection\
                  .find(dict(_search,
                             start={'$gte': date, '$lt':date + datetime.timedelta(days=1)}))\
                  .limit(1).sort('modify_date', -1):
            # the reason we're after the modify_date is because we ultimately
            # need to know the latest something was changed in this day.
            timestamp = mktime(event['modify_date'].timetuple())
            break

        if not timestamp_only:
            events = []
            days_spent = hours_spent = None
            for each in self.db.Event.collection\
                  .find(dict(_search,
                             start={'$gte': date, '$lt':date + datetime.timedelta(days=1)})):
                if days_spent is None:
                    days_spent = hours_spent = 0.0

                event = dict(id=str(each['_id']),
                             all_day=each['all_day'],
                             title=each['title'],
                             #tags=each['tags'],
                             )
                event['description'] = each['description']
                event['external_url'] = each['external_url']
                if each['all_day']:
                    event['days'] = 1 + (each['end'] - each['start']).days
                else:
                    event['hours'] = (each['end'] - each['start']).seconds / 60.0 / 60
                event['length'] = self.describe_length(each)
                events.append(event)
                #if each['all_day']:
                #    days_spent += 1 + (each['end'] - each['start']).days
                #else:
                #    hours_spent += (each['end'] - each['start']).seconds / 60.0 / 60

        data = dict(timestamp=timestamp)
        if not timestamp_only:
            data['events'] = events
            #if days_spent or hours_spent:
            #    data['totals'] = dict()
            #    # there were some events at least
            #    if days_spent:
            #        data['totals']['days_spent'] = days_spent
            #    if hours_spent:
            #        data['totals']['hours_spent'] = '%.2f' % round(hours_spent, 1)
        self.write_json(data)
Пример #5
0
    def get(self):
        user = self.must_get_user()
        year = int(self.get_argument('year'))
        month = int(self.get_argument('month'))
        timestamp_only = niceboolean(self.get_argument('timestamp_only',
                                                       False))
        _search = {'user.$id': user._id}
        first_day = datetime.datetime(year, month, 1, 0, 0, 0)
        date = first_day
        #no_days = 0
        day_counts = []
        if timestamp_only:
            while date.month == first_day.month:
                date += datetime.timedelta(days=1)
        else:
            while date.month == first_day.month:
                count_events = self.db[Event.__collection__]\
                  .find(dict(_search,
                             start={'$gte': date, '$lt':date + datetime.timedelta(days=1)}))\
                             .count()
                day_counts.append(count_events)
                date += datetime.timedelta(days=1)

        timestamp = 0
        for event in self.db.Event.collection\
          .find(dict(_search,
                     start={'$gte': first_day, '$lt':date}
                     )).limit(1).sort('add_date', -1):
            timestamp = mktime(event['add_date'].timetuple())
            break

        if timestamp_only:
            self.write_json(dict(timestamp=timestamp))
        else:
            self.write_json(
                dict(month_name=first_day.strftime('%B'),
                     day_counts=day_counts,
                     first_day=first_day.strftime('%A'),
                     timestamp=timestamp))
Пример #6
0
    def get(self):
        user = self.must_get_user()
        year = int(self.get_argument('year'))
        month = int(self.get_argument('month'))
        timestamp_only = niceboolean(self.get_argument('timestamp_only', False))
        _search = {'user.$id':user._id}
        first_day = datetime.datetime(year, month, 1, 0, 0, 0)
        date = first_day
        #no_days = 0
        day_counts = []
        if timestamp_only:
            while date.month == first_day.month:
                date += datetime.timedelta(days=1)
        else:
            while date.month == first_day.month:
                count_events = self.db[Event.__collection__]\
                  .find(dict(_search,
                             start={'$gte': date, '$lt':date + datetime.timedelta(days=1)}))\
                             .count()
                day_counts.append(count_events)
                date += datetime.timedelta(days=1)

        timestamp = 0
        for event in self.db.Event.collection\
          .find(dict(_search,
                     start={'$gte': first_day, '$lt':date}
                     )).limit(1).sort('add_date', -1):
            timestamp = mktime(event['add_date'].timetuple())
            break

        if timestamp_only:
            self.write_json(dict(timestamp=timestamp))
        else:
            self.write_json(dict(month_name=first_day.strftime('%B'),
                                 day_counts=day_counts,
                                 first_day=first_day.strftime('%A'),
                                 timestamp=timestamp))
Пример #7
0
    def get(self):
        # this should perhaps use a message queue instead
        now_utc = datetime.datetime.utcnow()
        dry_run = niceboolean(self.get_argument('dry_run', False))
        if self.get_argument('now_utc', None):
            now_utc = parse_datetime(self.get_argument('now_utc'))

        search = dict(_next_send_date={'$lte': now_utc})
        for email_reminder in self.db.EmailReminder.find(search):
            self.write("TO: %s\n" % email_reminder.user.email)
            # the reason we're including the now date is so that we can
            # A) make a dry run on a specific date and B) override what "now"
            # is for unit tests.
            self._send_reminder(email_reminder, now_utc, dry_run=dry_run)

            if not dry_run:
                email_reminder.set_next_send_date(now_utc)
                email_reminder.save()

                email_reminder_log = self.db.EmailReminderLog()
                email_reminder_log.email_reminder = email_reminder
                email_reminder_log.save()

        self.write("Done\n")
Пример #8
0
    def get(self):
        # this should perhaps use a message queue instead
        now_utc = datetime.datetime.utcnow()
        dry_run = niceboolean(self.get_argument("dry_run", False))
        if self.get_argument("now_utc", None):
            now_utc = parse_datetime(self.get_argument("now_utc"))

        search = dict(_next_send_date={"$lte": now_utc})
        for email_reminder in self.db.EmailReminder.find(search):
            self.write("TO: %s\n" % email_reminder.user.email)
            # the reason we're including the now date is so that we can
            # A) make a dry run on a specific date and B) override what "now"
            # is for unit tests.
            self._send_reminder(email_reminder, now_utc, dry_run=dry_run)

            if not dry_run:
                email_reminder.set_next_send_date(now_utc)
                email_reminder.save()

                email_reminder_log = self.db.EmailReminderLog()
                email_reminder_log.email_reminder = email_reminder
                email_reminder_log.save()

        self.write("Done\n")
Пример #9
0
    def get(self):
        user = self.must_get_user()
        timestamp_only = niceboolean(self.get_argument('timestamp_only', False))
        _search = {'user.$id':user._id}
        for event in self.db.Event.collection\
          .find(_search).sort('start', 1).limit(1):
            first_date = event['start']
            break
        else:
            # No events
            first_date = datetime.date.today()
            first_date = datetime.datetime(
              first_date.year, first_date.month, 1, 0, 0, 0)

        #for event in self.db[Event.__collection__].find(_search).sort('start', -1).limit(1):
        #    last_date = event['start']
        #    break
        #else:
        last_date = datetime.date.today()
        last_date = datetime.datetime(
              last_date.year, last_date.month, 1, 0, 0, 0)

        today = datetime.date.today()

        months = []
        date = first_date
        timestamp = 0
        while date <= last_date:
            first_of_date = datetime.datetime(
              date.year, date.month, 1, 0, 0, 0)

            next_date = first_of_date + relativedelta.relativedelta(months=1)

            for event in self.db.Event.collection\
              .find(dict(_search,
                         start={'$gte': first_of_date, '$lt':next_date}))\
              .limit(1).sort('add_date', -1):
                tmp_timestamp = mktime(event['add_date'].timetuple())
                if tmp_timestamp > timestamp:
                    timestamp = tmp_timestamp
                    break

            if not timestamp_only:
                # becomes 28 for February for example
                # Haven't tested for all years :)
                count_events = self.db.Event.collection\
                  .find(dict(_search,
                             start={'$gte': first_of_date, '$lt':next_date}))\
                             .count()
                month_name = first_of_date.strftime('%B')
                #if first_of_date.year == today.year and first_of_date.month == today.month:
                #    month_name += " (today)"
                months.append(dict(month_name=month_name,
                                   year=first_of_date.year,
                                   month=first_of_date.month,
                                   count=count_events,
                                   #no_days=no_days,
                                   ))
            date = next_date

        if timestamp_only:
            self.write_json(dict(timestamp=timestamp))
        else:
            self.write_json(dict(months=months, timestamp=timestamp))
Пример #10
0
    def get(self):
        user = self.must_get_user()
        timestamp_only = niceboolean(self.get_argument('timestamp_only',
                                                       False))
        _search = {'user.$id': user._id}
        for event in self.db.Event.collection\
          .find(_search).sort('start', 1).limit(1):
            first_date = event['start']
            break
        else:
            # No events
            first_date = datetime.date.today()
            first_date = datetime.datetime(first_date.year, first_date.month,
                                           1, 0, 0, 0)

        #for event in self.db[Event.__collection__].find(_search).sort('start', -1).limit(1):
        #    last_date = event['start']
        #    break
        #else:
        last_date = datetime.date.today()
        last_date = datetime.datetime(last_date.year, last_date.month, 1, 0, 0,
                                      0)

        today = datetime.date.today()

        months = []
        date = first_date
        timestamp = 0
        while date <= last_date:
            first_of_date = datetime.datetime(date.year, date.month, 1, 0, 0,
                                              0)

            next_date = first_of_date + relativedelta.relativedelta(months=1)

            for event in self.db.Event.collection\
              .find(dict(_search,
                         start={'$gte': first_of_date, '$lt':next_date}))\
              .limit(1).sort('add_date', -1):
                tmp_timestamp = mktime(event['add_date'].timetuple())
                if tmp_timestamp > timestamp:
                    timestamp = tmp_timestamp
                    break

            if not timestamp_only:
                # becomes 28 for February for example
                # Haven't tested for all years :)
                count_events = self.db.Event.collection\
                  .find(dict(_search,
                             start={'$gte': first_of_date, '$lt':next_date}))\
                             .count()
                month_name = first_of_date.strftime('%B')
                #if first_of_date.year == today.year and first_of_date.month == today.month:
                #    month_name += " (today)"
                months.append(
                    dict(
                        month_name=month_name,
                        year=first_of_date.year,
                        month=first_of_date.month,
                        count=count_events,
                        #no_days=no_days,
                    ))
            date = next_date

        if timestamp_only:
            self.write_json(dict(timestamp=timestamp))
        else:
            self.write_json(dict(months=months, timestamp=timestamp))