Beispiel #1
0
def update_readthrough(request, book=None, create=True):
    ''' updates but does not save dates on a readthrough '''
    try:
        read_id = request.POST.get('id')
        if not read_id:
            raise models.ReadThrough.DoesNotExist
        readthrough = models.ReadThrough.objects.get(id=read_id)
    except models.ReadThrough.DoesNotExist:
        if not create or not book:
            return None
        readthrough = models.ReadThrough(
            user=request.user,
            book=book,
        )

    start_date = request.POST.get('start_date')
    if start_date:
        try:
            start_date = dateutil.parser.parse(start_date)
            readthrough.start_date = start_date
        except ParserError:
            pass

    finish_date = request.POST.get('finish_date')
    if finish_date:
        try:
            finish_date = dateutil.parser.parse(finish_date)
            readthrough.finish_date = finish_date
        except ParserError:
            pass

    return readthrough
Beispiel #2
0
 def test_currently_reading_reads(self):
     expected = [
         models.ReadThrough(start_date=datetime.datetime(2019, 4, 9, 0, 0))
     ]
     actual = models.ImportItem.objects.get(index=1)
     self.assertEqual(actual.reads[0].start_date, expected[0].start_date)
     self.assertEqual(actual.reads[0].finish_date, expected[0].finish_date)
Beispiel #3
0
 def test_currently_reading_reads(self):
     """infer currently reading dates where available"""
     expected = [
         models.ReadThrough(start_date=datetime.datetime(
             2019, 4, 9, 0, 0, tzinfo=timezone.utc))
     ]
     actual = models.ImportItem.objects.get(index=1)
     self.assertEqual(actual.reads[0].start_date, expected[0].start_date)
     self.assertEqual(actual.reads[0].finish_date, expected[0].finish_date)
Beispiel #4
0
def update_readthrough(request, book=None, create=True):
    ''' updates but does not save dates on a readthrough '''
    try:
        read_id = request.POST.get('id')
        if not read_id:
            raise models.ReadThrough.DoesNotExist
        readthrough = models.ReadThrough.objects.get(id=read_id)
    except models.ReadThrough.DoesNotExist:
        if not create or not book:
            return None
        readthrough = models.ReadThrough(
            user=request.user,
            book=book,
        )

    start_date = request.POST.get('start_date')
    if start_date:
        try:
            start_date = timezone.make_aware(dateutil.parser.parse(start_date))
            readthrough.start_date = start_date
        except ParserError:
            pass

    finish_date = request.POST.get('finish_date')
    if finish_date:
        try:
            finish_date = timezone.make_aware(
                dateutil.parser.parse(finish_date))
            readthrough.finish_date = finish_date
        except ParserError:
            pass

    progress = request.POST.get('progress')
    if progress:
        try:
            progress = int(progress)
            readthrough.progress = progress
        except ValueError:
            pass

    progress_mode = request.POST.get('progress_mode')
    if progress_mode:
        try:
            progress_mode = models.ProgressMode(progress_mode)
            readthrough.progress_mode = progress_mode
        except ValueError:
            pass

    if not readthrough.start_date and not readthrough.finish_date:
        return None

    return readthrough
Beispiel #5
0
def update_readthrough(request, book=None, create=True):
    """updates but does not save dates on a readthrough"""
    try:
        read_id = request.POST.get("id")
        if not read_id:
            raise models.ReadThrough.DoesNotExist
        readthrough = models.ReadThrough.objects.get(id=read_id)
    except models.ReadThrough.DoesNotExist:
        if not create or not book:
            return None
        readthrough = models.ReadThrough(
            user=request.user,
            book=book,
        )

    start_date = request.POST.get("start_date")
    if start_date:
        try:
            readthrough.start_date = load_date_in_user_tz_as_utc(
                start_date, request.user)
        except ParserError:
            pass

    finish_date = request.POST.get("finish_date")
    if finish_date:
        try:
            readthrough.finish_date = load_date_in_user_tz_as_utc(
                finish_date, request.user)
        except ParserError:
            pass

    progress = request.POST.get("progress")
    if progress:
        try:
            progress = int(progress)
            readthrough.progress = progress
        except ValueError:
            pass

    progress_mode = request.POST.get("progress_mode")
    if progress_mode:
        try:
            progress_mode = models.ProgressMode(progress_mode)
            readthrough.progress_mode = progress_mode
        except ValueError:
            pass

    if not readthrough.start_date and not readthrough.finish_date:
        return None

    return readthrough
 def test_currently_reading_reads(self):
     """infer currently reading dates where available"""
     expected = [
         models.ReadThrough(start_date=datetime.datetime(
             2019, 4, 9, 0, 0, tzinfo=timezone.utc))
     ]
     item = models.ImportItem.objects.create(
         index=1,
         job=self.job,
         data={},
         normalized_data={
             "isbn_13": '="9780356506999"',
             "shelf": "reading",
             "date_added": "2019/04/09",
         },
     )
     self.assertEqual(item.reads[0].start_date, expected[0].start_date)
     self.assertIsNone(item.reads[0].finish_date)