Hide keyboard shortcuts

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

from django.contrib.auth.decorators import login_required 

from django.utils.decorators import method_decorator 

from django.urls import reverse_lazy 

from django.views import View 

from django.shortcuts import render 

from main.views_functions import url_without_errors, Fanfic 

from django.http import HttpResponse 

from .models import Fanfic 

 

 

@method_decorator(login_required(login_url=reverse_lazy('login')), 

name='dispatch') 

class DashboardView(View): 

''' See the dashboard ''' 

template_name = 'dashboard.html' 

 

def get(self, request, *args, **kwargs): 

return render(request, self.template_name) 

 

 

@method_decorator(login_required(login_url=reverse_lazy('login')), 

name='dispatch') 

class AddExternalFanfic(View): 

''' Add an external fanfic ''' 

template_name = 'add_external_fanfic.html' 

 

def get(self, request, *args, **kwargs): 

return render(request, self.template_name) 

 

def post(self, request, *args, **kwargs): 

if request.is_ajax() is True: 

url_fanfic = request.POST.get("url_fanfic") 

clean_url_fanfic = url_without_errors(url_fanfic) 

 

if "Error" in clean_url_fanfic: 

msg_error = clean_url_fanfic 

return HttpResponse(msg_error, content_type='text/plain', 

status=200) 

try: 

title, author = Fanfic.get_title_and_author( 

clean_url_fanfic) 

 

similar_fanfics = Fanfic.get_similar_by_title_and_author( 

title, author) 

 

if similar_fanfics.count() != 0: 

# if there are similars show on screen for the 

# user "no, keep going" and "choose this" 

# appear on screen 

data = {} 

data['similar'] = [] 

fanfics_info = [] 

for fanfic in similar_fanfics: 

fanfic_info = {} 

fanfic_info['title'] = fanfic.name 

fanfic_info['author'] = fanfic.author 

print(fanfic.name) 

return HttpResponse( 

content_type='text/plain', 

status=200) 

else: 

# there aren't similar ones, continue button 

# appear, if it's archiveofourown confirm fandom-type 

# with user. A fanfic can belong to more than one fandom 

# spinoff 

pass 

 

except Exception: 

# couldn't parse well, server error, it's our fault 

# we'll fix it soon, try again in a few minutes 

return HttpResponse("Error: We have a server error and we'll " 

" fix it soon. It's our fault and we " 

"apologize. ", 

content_type='text/plain', 

status=200) 

else: 

if "choose_this" in request.POST: 

# Similar fanfic has been chosen 

# get id of fanfic, make another version (parse,...) 

# queue and notification when it's done to the user 

pass 

elif "keep_going" in request.POST: 

# there is not a similar fanfic in database 

# create new fanfic (parse,..) 

# queue and notification when it's done to the user 

pass 

else: 

return HttpResponse("Method not Allowed", status=405) 

 

@method_decorator(login_required(login_url=reverse_lazy('login')), 

name='dispatch') 

class ExternalFanficAdded(View): 

''' Show that an external fanfic has been added and user has to wait ''' 

template_name = 'dashboard.html' 

 

def get(self, request, *args, **kwargs): 

return render(request, self.template_name)