|
| 1 | + |
| 2 | +from Gr33kLibrary.models import * |
| 3 | +import os |
| 4 | +import math |
| 5 | +import html |
| 6 | +import re |
| 7 | + |
| 8 | + |
| 9 | +def list2str(old_list:list): |
| 10 | + _str = "" |
| 11 | + for l in old_list: |
| 12 | + _str = _str + str(l) + ',' |
| 13 | + return _str |
| 14 | + |
| 15 | + |
| 16 | +class Article_temp(): |
| 17 | + article = None |
| 18 | + tags = [] |
| 19 | + article_num = 0 |
| 20 | + |
| 21 | + def __init__(self,article,tags): |
| 22 | + self.tags = [] |
| 23 | + self.article = article |
| 24 | + for tag in tags: |
| 25 | + try: |
| 26 | + tag_name = Tag.objects.get(id=int(tag)).name |
| 27 | + self.tags.append(tag_name) |
| 28 | + except: |
| 29 | + continue |
| 30 | + |
| 31 | + |
| 32 | +def wrire_file(img,path,img_name_new): |
| 33 | + destination = open(os.path.join(path, img_name_new), 'wb+') |
| 34 | + for chunk in img.chunks(): |
| 35 | + destination.write(chunk) |
| 36 | + destination.close() |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +def convertBytes(bytes, lst=None): |
| 41 | + if lst is None: |
| 42 | + lst=['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'] |
| 43 | + i = int(math.floor( # 舍弃小数点,取小 |
| 44 | + math.log(bytes, 1024) # 求对数(对数:若 a**b = N 则 b 叫做以 a 为底 N 的对数) |
| 45 | + )) |
| 46 | + |
| 47 | + if i >= len(lst): |
| 48 | + i = len(lst) - 1 |
| 49 | + return ('%.2f' + " " + lst[i]) % (bytes/math.pow(1024, i)) |
| 50 | + |
| 51 | +class Author(): |
| 52 | + author = None |
| 53 | + article_num = 0 |
| 54 | + invitation_user = None |
| 55 | + |
| 56 | + def __init__(self,author:Article,article_num:int,invitation_user): |
| 57 | + self.author = author |
| 58 | + self.article_num = article_num |
| 59 | + try: |
| 60 | + self.invitation_user = User.objects.get(id=int(invitation_user)) |
| 61 | + except: |
| 62 | + self.invitation_user = None |
| 63 | + |
| 64 | + |
| 65 | +class Classify_temp(): |
| 66 | + classify = None |
| 67 | + article_num = 0 |
| 68 | + |
| 69 | + def __init__(self,classify:Classify,article_num:int): |
| 70 | + self.classify = classify |
| 71 | + self.article_num = article_num |
| 72 | + |
| 73 | + |
| 74 | +class Tag_temp(): |
| 75 | + tag = None |
| 76 | + article_num = 0 |
| 77 | + |
| 78 | + def __init__(self, tag: Tag, article_num: int): |
| 79 | + self.tag = tag |
| 80 | + self.article_num = article_num |
| 81 | + |
| 82 | + |
| 83 | +def get_tag_article(tag_id): |
| 84 | + s_tag = str(tag_id) + ',' |
| 85 | + num = Article.objects.filter(state=3).filter(tags__contains=s_tag).all().count() |
| 86 | + return num |
0 commit comments