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

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

from users.models import CustomUser 

from django.db import models 

 

from multiselectfield import MultiSelectField 

from django.db.models import Q 

 

import re 

 

class Type(models.Model): 

name = models.CharField(max_length=10, primary_key=True) 

 

def __str__(self): 

return self.name 

 

 

class Fandom(models.Model): 

id_fandom = models.AutoField(primary_key=True) 

name = models.CharField(max_length=30, blank=False, null=False) 

type_name = models.ForeignKey(Type, on_delete=models.CASCADE) 

 

def __str__(self): 

return self.name 

 

 

class Character(models.Model): 

id_character = models.AutoField(primary_key=True) 

name_surname = models.CharField(max_length=255, unique=True, blank=False, 

null=False) 

fandom_id = models.ForeignKey(Fandom, on_delete=models.SET_NULL, null=True) 

 

def __str__(self): 

return self.name_surname 

 

 

class Fanfic(models.Model): 

id_fanfic = models.AutoField(primary_key=True) 

name = models.CharField(max_length=255, blank=False, null=False) 

author = models.CharField(max_length=255, blank=False, null=False) 

web = models.CharField(max_length=255, blank=False, null=False, 

unique=True) 

language = models.CharField(max_length=255, blank=True, null=True) 

 

GENRE = ( 

('adv', 'adventure'), 

('ang', 'angst'), 

('dra', 'drama'), 

('fri', 'friendship'), 

('gen', 'general'), 

('hum', 'humor'), 

('hur', 'hurt/comfort'), 

('mys', 'mystery'), 

('rom', 'romance'), 

('tra', 'tragedy') 

) 

genre1 = MultiSelectField(choices=GENRE, blank=False, null=False) 

genre2 = MultiSelectField(choices=GENRE, blank=True, null=True) 

genre3 = MultiSelectField(choices=GENRE, blank=True, null=True) 

genre4 = MultiSelectField(choices=GENRE, blank=True, null=True) 

 

last_time_checked = models.DateTimeField(blank=True, null=True) 

 

STATUS = ( 

('c', 'completed'), 

('i', 'in progress'), 

) 

status = models.CharField(max_length=1, choices=STATUS, blank=False, 

null=False) 

 

last_time_updated = models.DateTimeField(blank=True, null=True) 

numChapters = models.IntegerField(blank=True, null=True) 

numWords = models.IntegerField(blank=True, null=True) 

 

RATING = ( 

('a', 'K -> T'), 

('b', 'K -> K+'), 

('c', 'K'), 

('d', 'K+'), 

('e', 'T'), 

('f', 'M'), 

) 

rating = models.CharField(max_length=1, choices=RATING, blank=True, 

null=True) 

average_score = models.FloatField(blank=True, null=True) 

 

def __str__(self): 

return self.name 

 

def get_domain(self): 

''' Returns the domain of where it's hosted ''' 

regex = "(http[s]?|www\.)" 

split_url = re.compile(regex).split(self.web) 

split_url = split_url[len(split_url)-1] 

 

regex = "(:?[\/]{2})" 

split_url = re.compile(regex).split(split_url) 

split_url = split_url[len(split_url)-1] 

 

regex = "\.[\D]{3}\/" 

split_url = re.compile(regex).split(split_url) 

domain_name = split_url[0] 

 

return domain_name 

 

@staticmethod 

def get_similar_by_title_and_author(title, author): 

''' Gets the fanfics with similar title and author to 

the given ones 

''' 

qset = Q() 

for term in title.split(): 

qset |= Q(name__icontains=term) 

 

similar_to_title = Fanfic.objects.filter(qset) 

 

similar_to_author = Fanfic.objects.filter( 

author__icontains=author) 

similar = similar_to_author | similar_to_title 

return similar 

 

 

class Pairing(models.Model): 

fanfic_id = models.ForeignKey(Fanfic, on_delete=models.CASCADE) 

group = models.IntegerField(blank=False, null=False) 

character_id = models.ForeignKey(Character, on_delete=models.CASCADE) 

 

 

class CharacterFanfic(models.Model): 

character_id = models.ForeignKey(Character, on_delete=models.CASCADE) 

fanfic_id = models.ForeignKey(Fanfic, on_delete=models.CASCADE) 

 

 

class Review(models.Model): 

id_review = models.AutoField(primary_key=True) 

text = models.TextField(blank=True, null=True) 

score = models.FloatField(blank=True, null=True) 

date = models.DateField(auto_now=True) 

fanfic_id = models.ForeignKey(Fanfic, on_delete=models.CASCADE) 

user_id = models.ForeignKey(CustomUser, on_delete=models.SET_NULL, 

null=True) 

 

 

class FandomFanfic(models.Model): 

fandom_id = models.ForeignKey(Fandom, on_delete=models.CASCADE) 

fanfic_id = models.ForeignKey(Fanfic, on_delete=models.CASCADE) 

 

 

class Related(models.Model): 

fanfic_id_one = models.ForeignKey(Fanfic, on_delete=models.CASCADE, 

related_name="fanfic_one") 

fanfic_id_two = models.ForeignKey(Fanfic, on_delete=models.CASCADE, 

related_name="fanfic_two") 

 

 

class Following(models.Model): 

user_id_one = models.ForeignKey(CustomUser, on_delete=models.SET_NULL, 

null=True, 

related_name="user_one_following") 

user_id_two = models.ForeignKey(CustomUser, on_delete=models.SET_NULL, 

null=True, 

related_name="user_two_following") 

date = models.DateField(auto_now=True) 

 

 

class PrivateMessage(models.Model): 

user_id_sender = models.ForeignKey(CustomUser, on_delete=models.SET_NULL, 

null=True, related_name="user_sender") 

user_id_receiver = models.ForeignKey(CustomUser, on_delete=models.SET_NULL, 

null=True, 

related_name="user_receiver") 

text = models.TextField(blank=False, null=False) 

subject = models.CharField(max_length=100, blank=False, null=False) 

date = models.DateField(auto_now=True) 

 

 

class Chapter(models.Model): 

id_chapter = models.AutoField(primary_key=True) 

title = models.CharField(max_length=255, blank=True, null=True) 

num_chapter = models.IntegerField(blank=False, null=False) 

url_chapter = models.CharField(max_length=255, blank=True, null=True) 

fanfic_id = models.ForeignKey(Fanfic, on_delete=models.SET_NULL, null=True) 

 

 

class Reading(models.Model): 

chapter_id = models.ForeignKey(Chapter, on_delete=models.SET_NULL, 

null=True) 

user_id = models.ForeignKey(CustomUser, on_delete=models.SET_NULL, 

null=True) 

date = models.DateField(auto_now=True) 

private_notes = models.TextField(blank=True, null=True) 

 

 

class List(models.Model): 

id_list = models.AutoField(primary_key=True) 

name = models.CharField(max_length=255, blank=False, null=False, 

unique=True) 

user_id = models.ForeignKey(CustomUser, on_delete=models.SET_NULL, 

null=True) 

 

def __str__(self): 

return self.name 

 

 

class FanficList(models.Model): 

list_id = models.ForeignKey(List, on_delete=models.CASCADE) 

fanfic_id = models.ForeignKey(Fanfic, on_delete=models.CASCADE) 

date = models.DateTimeField(auto_now=True)