def test_repeat_logic(self): reference_time = localtime_to_timestamp(make_localtime(2020, 1, 1, 13)) repeat_policy = RepeatPolicyEntity(RepeatPolicyType.NONE) assert repeat_note(repeat_policy, reference_time=reference_time) == FAR_FUTURE choice = ChoiceEntity(skip_to_end=True) assert repeat_note(repeat_policy, choice, reference_time) - reference_time == -1 # Check hourly repeat_policy = RepeatPolicyEntity.from_json({ 'type': 'hourly', 'hours': 36 }) t2 = repeat_note(repeat_policy, reference_time=reference_time) assert t2 - reference_time == (36 * 3600) # Check daily repeat_policy = RepeatPolicyEntity.from_json({ 'type': 'daily', 'days': 3, 'timeOfDay': 'morning' }) t2 = repeat_note(repeat_policy, reference_time=reference_time) hours_between = (t2 - reference_time) / 3600 self.assertEqual(hours_between, 3 * 24 - (13 - settings.MORNING_HOURS))
def post(self, request, **kwargs): note = Note.get_note_by_id(self.request.user, self.kwargs['id']) note_entity = NoteEntity.from_json(request.data) note.from_entity(note_entity) note.updated_time = timestamp_now() note.repeat_time = repeat_note(note_entity.repeat_policy) note.save() return Response({})
def post(self, request, **kwargs): collection = Collection.get_collection(self.request.user, self.kwargs['id']) note = Note(collection=collection, created_time=timestamp_now()) note_entity = NoteEntity.from_json(request.data) note.from_entity(note_entity) note.created_time = timestamp_now() note.updated_time = timestamp_now() note.repeat_time = repeat_note(note_entity.repeat_policy) note.save() return Response({ 'note_id': note.id, 'note_url': reverse('view_note', args=[note.id]) })
def post(self, request, **kwargs): note_id = request.data['note_id'] choice = request.data['choice'] note = Note.get_note_by_id(self.request.user, note_id) note_entity = note.to_entity() choice_entity = ChoiceEntity.from_json(choice) note.last_repeat_time = timestamp_now() note.repeat_time = repeat_note(note_entity.repeat_policy, choice_entity) if choice_entity.overwrite_repeat_policy: assert choice_entity.repeat_policy is not None note_entity.repeat_policy = choice_entity.repeat_policy note.from_entity(note_entity, load_name=False, load_contents=False, load_metadata=True) note.save() return Response({})
def get(self, request, **kwargs): # Is it a diary? is_diary = ('diary' in self.request.GET) # Get collection collection = Collection.get_collection(self.request.user, self.kwargs['id']) # Handle name name = '' if is_diary: dt_now = localtime_now() name = dt_now.strftime('Diary, %A, %Y-%m-%d') # TODO: Configurable default repeat and learn policies repeat_policy = RepeatPolicyEntity(RepeatPolicyType.DAILY, days=1, time_of_day=TimeOfDay.MORNING) if is_diary: repeat_policy = RepeatPolicyEntity(RepeatPolicyType.DAILY, days=365, time_of_day=TimeOfDay.MORNING) learn_policy = LearnPolicyEntity(LearnPolicyType.EXPONENTIAL) note_entity = NoteEntity(name, ContentsEntity([MarkdownSectionEntity("")]), repeat_policy=repeat_policy, learn_policy=learn_policy) note = Note(collection=collection, created_time=timestamp_now()) note.from_entity(note_entity) note.created_time = timestamp_now() note.updated_time = timestamp_now() note.repeat_time = repeat_note(note_entity.repeat_policy) note.save() return redirect('edit_note', id=note.id)