Пример #1
0
 def post(self, request, **kwargs):
     collection = Collection.get_collection(self.request.user,
                                            self.kwargs['id'])
     action = request.data['action']
     if action == 'delete':
         collection.delete()
     else:
         raise ValueError(f'Invalid action: {action}')
     return Response({})
Пример #2
0
 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])
     })
Пример #3
0
    def get_context_data(self, **kwargs):
        collection = Collection.get_collection(self.request.user,
                                               self.kwargs['id'])
        q_obj = Q(collection=collection)

        q = self.request.GET.get('q', '').strip()
        filter_for_archived = False
        if q:
            for word in q.split():
                if word.lower() == 'archived':
                    filter_for_archived = True
                else:
                    q_obj = q_obj & Q(name__icontains=word)

        if filter_for_archived:
            q_obj = q_obj & Q(archived=True)
        else:
            q_obj = q_obj & Q(archived=False)
        notes = Note.objects.filter(q_obj).order_by('-updated_time').only(
            'name', 'created_time', 'updated_time', 'repeat_time')
        paginator = Paginator(notes, per_page=12)

        p = int(self.request.GET.get('p', '1'))
        page = paginator.page(p)

        reference_time = timestamp_to_localtime(timestamp_now())

        return {
            'notes': page.object_list,
            'page': page,
            'p': p,
            'q': q,
            'paginator': paginator,
            'collection': collection,
            'reference_time': reference_time,
            'pretty_format_timedelta': pretty_format_timedelta
        }
Пример #4
0
    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)