Coverage for chapters\views.py : 69%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Get an instance of a logger
# Create your views here.
""" Clear private notes of user for one fanfic""" raise PermissionDenied()
user=request.user).update( private_notes=None)
except Exception as e: logger.error("Error deleting private notes {}".format(e)) message = "There was an unexpected error trying to delete the " \ "private notes." messages.error(request, message)
""" Create/edit message""" False: raise PermissionDenied()
raise PermissionDenied
text.replace(" ", "")) == 0: # text is empty raise CustomError("The text cannot have more than 200 " "characters.")
user=request.user) # it already exists, update content else: else: # create new reading Reading.objects.create(chapter=chapter, user=request.user, private_notes=text)
except CustomError as e: logger.error("Error saving private notes {}".format(e)) success = False message = str(e) except Exception as e: logger.error("Error saving private notes {}".format(e)) success = False message = "There was an unexpected error trying to update the " \ "private note."
# return json "success": success, "message": message, } status=200)
""" Clear all the data of one user for one fanfic""" raise PermissionDenied()
user=request.user).delete()
except Exception as e: logger.error("Error deleting the chapters data {}".format(e)) message = "There was an unexpected error trying to delete the " \ "user data." messages.error(request, message)
""" Mark all chapters as read """ raise PermissionDenied()
fanfic=fanfic) user=request.user) reading_obj = reading.first() reading_obj.read = True reading_obj.save() else: # create reading obj chapter=chapter, read=True)
except Exception as e: logger.error("Error marking all chapters as read {}".format(e)) message = "There was an unexpected error trying to mark the " \ "chapters as read." messages.error(request, message)
""" Mark chapter as read/unread """ False: raise PermissionDenied()
raise PermissionDenied
chapter=chapter)
reading = reading.first() status = reading.read
if status is True and reading.private_notes is None: reading.delete() else: reading.read = True if status is False else False reading.save()
if status is False: notification = True else: chapter=chapter, read=True)
# create notification subject=chapter.fanfic, verb="has read chapter {} " "of".format( chapter.num_chapter), target=request.user, reverse=True, link=chapter.fanfic.get_url(), in_top_bar=False, in_feed=True)
except Exception as e: logger.error("Error marking a chapter as read/unread {}".format(e)) success = False message = "There was an unexpected error trying to update the " \ "chapter status."
# return json "success": success, "message": message, "checked": notification } status=200)
""" Mark chapter as read last chapter of a fanfic """ False: raise PermissionDenied()
chapter__fanfic=fanfic, read=True, user=request.user).values_list( 'chapter__id', flat=True) id__in=read_chapters).filter( fanfic=fanfic).order_by('num_chapter') chapter=one_unread_chapter, user=request.user, read=False) chapter=one_unread_chapter, read=True) else: reading_user = reading_user.first() reading_user.read = True reading_user.save()
else: message = "There are no more chapters to read for " \ "this fanfic."
# create notification subject=chapter_marked_as_read.fanfic, verb="has read chapter {} " "of".format( chapter_marked_as_read.num_chapter), target=request.user, reverse=True, link=chapter_marked_as_read.fanfic.get_url(), in_top_bar=False, in_feed=True)
chapter__fanfic=fanfic, user=request.user).count() else: more_chapters = True
except Exception as e: logger.error("Error marking a chapter as read {}".format(e)) success = False message = "There was an unexpected error trying to update the " \ "chapter status."
# return json 'moreChapters': more_chapters, 'totalCount': total_count, 'chaptersReadCount': chapters_read_count, 'success': success, 'message': message } content_type='text/plain', status=200) |