From 0ff6a263351db920724edb837d45aa65744d5c37 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 19 Sep 2021 20:22:57 +0200 Subject: [PATCH] dfsfsd --- files/classes/clients.py | 28 ++++++++-- files/classes/comment.py | 72 ++++++++++++++++++++++++- files/classes/flags.py | 25 +++++++-- files/classes/mix_ins.py | 104 ------------------------------------ files/classes/mod_logs.py | 35 +++++++++++- files/classes/submission.py | 93 ++++++++++++++++++++++++++++++-- files/classes/user.py | 9 +++- files/classes/userblock.py | 8 ++- files/templates/log.html | 12 ++--- 9 files changed, 258 insertions(+), 128 deletions(-) delete mode 100644 files/classes/mix_ins.py diff --git a/files/classes/clients.py b/files/classes/clients.py index 857ba7ebe..922197d12 100644 --- a/files/classes/clients.py +++ b/files/classes/clients.py @@ -2,12 +2,11 @@ from flask import * from sqlalchemy import * from sqlalchemy.orm import relationship, lazyload -from .mix_ins import Stndrd from .submission import Submission from .comment import Comment from files.__main__ import Base -class OauthApp(Base, Stndrd): +class OauthApp(Base): __tablename__ = "oauth_apps" @@ -21,6 +20,17 @@ class OauthApp(Base, Stndrd): def __repr__(self): return f"" + + @property + @lazy + def created_date(self): + return time.strftime("%d %B %Y", time.gmtime(self.created_utc)) + + @property + @lazy + def created_datetime(self): + return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) + @property def permalink(self): return f"/admin/app/{self.id}" @@ -45,7 +55,7 @@ class OauthApp(Base, Stndrd): return [x[0] for x in posts.all()] -class ClientAuth(Base, Stndrd): +class ClientAuth(Base): __tablename__ = "client_auths" @@ -54,4 +64,14 @@ class ClientAuth(Base, Stndrd): access_token = Column(String(128)) user_id = Column(Integer, ForeignKey("users.id")) user = relationship("User", lazy="joined", viewonly=True) - application = relationship("OauthApp", lazy="joined", viewonly=True) \ No newline at end of file + application = relationship("OauthApp", lazy="joined", viewonly=True) + + @property + @lazy + def created_date(self): + return time.strftime("%d %B %Y", time.gmtime(self.created_utc)) + + @property + @lazy + def created_datetime(self): + return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) \ No newline at end of file diff --git a/files/classes/comment.py b/files/classes/comment.py index 2b5deb3dd..94fa4538b 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -6,7 +6,6 @@ from sqlalchemy.orm import relationship, deferred from files.helpers.lazy import lazy from files.helpers.const import SLURS from files.__main__ import Base -from .mix_ins import * from .flags import CommentFlag from os import environ @@ -23,7 +22,7 @@ class CommentAux(Base): ban_reason = Column(String(256), default='') -class Comment(Base, Age_times): +class Comment(Base): __tablename__ = "comments" @@ -75,6 +74,75 @@ class Comment(Base, Age_times): return f"" + @property + @lazy + def created_datetime(self): + return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) + + @property + @lazy + def age_string(self): + + age = int(time.time()) - self.created_utc + + if age < 60: + return "just now" + elif age < 3600: + minutes = int(age / 60) + return f"{minutes}m ago" + elif age < 86400: + hours = int(age / 3600) + return f"{hours}hr ago" + elif age < 2678400: + days = int(age / 86400) + return f"{days}d ago" + + now = time.gmtime() + ctd = time.gmtime(self.created_utc) + + # compute number of months + months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year) + # remove a month count if current day of month < creation day of month + if now.tm_mday < ctd.tm_mday: + months -= 1 + + if months < 12: + return f"{months}mo ago" + else: + years = int(months / 12) + return f"{years}yr ago" + + @property + @lazy + def edited_string(self): + + if not self.edited_utc: + return "never" + + age = int(time.time()) - self.edited_utc + + if age < 60: + return "just now" + elif age < 3600: + minutes = int(age / 60) + return f"{minutes}m ago" + elif age < 86400: + hours = int(age / 3600) + return f"{hours}hr ago" + elif age < 2678400: + days = int(age / 86400) + return f"{days}d ago" + + now = time.gmtime() + ctd = time.gmtime(self.edited_utc) + months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year) + + if months < 12: + return f"{months}mo ago" + else: + years = now.tm_year - ctd.tm_year + return f"{years}yr ago" + @property @lazy def score(self): diff --git a/files/classes/flags.py b/files/classes/flags.py index f15b610fe..51eec2e17 100644 --- a/files/classes/flags.py +++ b/files/classes/flags.py @@ -1,9 +1,8 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base -from .mix_ins import * -class Flag(Base, Stndrd): +class Flag(Base): __tablename__ = "flags" @@ -18,8 +17,18 @@ class Flag(Base, Stndrd): return f"" + @property + @lazy + def created_date(self): + return time.strftime("%d %B %Y", time.gmtime(self.created_utc)) -class CommentFlag(Base, Stndrd): + @property + @lazy + def created_datetime(self): + return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) + + +class CommentFlag(Base): __tablename__ = "commentflags" @@ -33,3 +42,13 @@ class CommentFlag(Base, Stndrd): def __repr__(self): return f"" + + @property + @lazy + def created_date(self): + return time.strftime("%d %B %Y", time.gmtime(self.created_utc)) + + @property + @lazy + def created_datetime(self): + return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) \ No newline at end of file diff --git a/files/classes/mix_ins.py b/files/classes/mix_ins.py deleted file mode 100644 index d967695d1..000000000 --- a/files/classes/mix_ins.py +++ /dev/null @@ -1,104 +0,0 @@ -from files.helpers.lazy import lazy -import math -import random -import time - -class Stndrd: - - @property - @lazy - def created_date(self): - return time.strftime("%d %B %Y", time.gmtime(self.created_utc)) - - @property - @lazy - def created_datetime(self): - return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) - -class Age_times: - - @property - def age(self): - - now = int(time.time()) - - return now - self.created_utc - - @property - def created_date(self): - - return time.strftime("%d %b %Y", time.gmtime(self.created_utc)) - - @property - def created_datetime(self): - return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) - - @property - def age_string(self): - - age = self.age - - if age < 60: - return "just now" - elif age < 3600: - minutes = int(age / 60) - return f"{minutes}m ago" - elif age < 86400: - hours = int(age / 3600) - return f"{hours}hr ago" - elif age < 2678400: - days = int(age / 86400) - return f"{days}d ago" - - now = time.gmtime() - ctd = time.gmtime(self.created_utc) - - # compute number of months - months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year) - # remove a month count if current day of month < creation day of month - if now.tm_mday < ctd.tm_mday: - months -= 1 - - if months < 12: - return f"{months}mo ago" - else: - years = int(months / 12) - return f"{years}yr ago" - - @property - def edited_string(self): - - if not self.edited_utc: - return "never" - - age = int(time.time()) - self.edited_utc - - if age < 60: - return "just now" - elif age < 3600: - minutes = int(age / 60) - return f"{minutes}m ago" - elif age < 86400: - hours = int(age / 3600) - return f"{hours}hr ago" - elif age < 2678400: - days = int(age / 86400) - return f"{days}d ago" - - now = time.gmtime() - ctd = time.gmtime(self.edited_utc) - months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year) - - if months < 12: - return f"{months}mo ago" - else: - years = now.tm_year - ctd.tm_year - return f"{years}yr ago" - - @property - def edited_date(self): - return time.strftime("%d %B %Y", time.gmtime(self.edited_utc)) - - @property - def edited_datetime(self): - return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.edited_utc))) \ No newline at end of file diff --git a/files/classes/mod_logs.py b/files/classes/mod_logs.py index 09dbef7d8..29067e20f 100644 --- a/files/classes/mod_logs.py +++ b/files/classes/mod_logs.py @@ -1,10 +1,9 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base -from .mix_ins import * import time -class ModAction(Base, Stndrd, Age_times): +class ModAction(Base): __tablename__ = "modactions" id = Column(BigInteger, primary_key=True) @@ -35,6 +34,38 @@ class ModAction(Base, Stndrd, Age_times): def __repr__(self): return f"" + @property + def age_string(self): + + age = self.age + + if age < 60: + return "just now" + elif age < 3600: + minutes = int(age / 60) + return f"{minutes}m ago" + elif age < 86400: + hours = int(age / 3600) + return f"{hours}hr ago" + elif age < 2678400: + days = int(age / 86400) + return f"{days}d ago" + + now = time.gmtime() + ctd = time.gmtime(self.created_utc) + + # compute number of months + months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year) + # remove a month count if current day of month < creation day of month + if now.tm_mday < ctd.tm_mday: + months -= 1 + + if months < 12: + return f"{months}mo ago" + else: + years = int(months / 12) + return f"{years}yr ago" + @property def note(self): diff --git a/files/classes/submission.py b/files/classes/submission.py index 8102dac64..364a32c54 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -1,12 +1,11 @@ from flask import render_template, g from sqlalchemy import * -from sqlalchemy.orm import relationship, deferred +from sqlalchemy.orm import relationship import re, random from urllib.parse import urlparse from files.helpers.lazy import lazy from files.helpers.const import SLURS from files.__main__ import Base -from .mix_ins import * from .flags import * from os import environ @@ -28,7 +27,7 @@ class SubmissionAux(Base): embed_url = Column(String(256)) -class Submission(Base, Age_times): +class Submission(Base): __tablename__ = "submissions" @@ -83,6 +82,82 @@ class Submission(Base, Age_times): def __repr__(self): return f"" + + @property + @lazy + def created_datetime(self): + return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) + + @property + @lazy + def age_string(self): + + age = int(time.time()) - self.created_utc + + if age < 60: + return "just now" + elif age < 3600: + minutes = int(age / 60) + return f"{minutes}m ago" + elif age < 86400: + hours = int(age / 3600) + return f"{hours}hr ago" + elif age < 2678400: + days = int(age / 86400) + return f"{days}d ago" + + now = time.gmtime() + ctd = time.gmtime(self.created_utc) + + # compute number of months + months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year) + # remove a month count if current day of month < creation day of month + if now.tm_mday < ctd.tm_mday: + months -= 1 + + if months < 12: + return f"{months}mo ago" + else: + years = int(months / 12) + return f"{years}yr ago" + + @property + @lazy + def edited_string(self): + + if not self.edited_utc: return "never" + + age = int(time.time()) - self.edited_utc + + if age < 60: + return "just now" + elif age < 3600: + minutes = int(age / 60) + return f"{minutes}m ago" + elif age < 86400: + hours = int(age / 3600) + return f"{hours}hr ago" + elif age < 2678400: + days = int(age / 86400) + return f"{days}d ago" + + now = time.gmtime() + ctd = time.gmtime(self.edited_utc) + months = now.tm_mon - ctd.tm_mon + 12 * (now.tm_year - ctd.tm_year) + + if months < 12: + return f"{months}mo ago" + else: + years = now.tm_year - ctd.tm_year + return f"{years}yr ago" + + + @property + @lazy + def edited_datetime(self): + return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.edited_utc))) + + @property @lazy def score(self): @@ -414,7 +489,7 @@ class Submission(Base, Age_times): def ordered_flags(self): return self.flags.order_by(Flag.id).all() -class SaveRelationship(Base, Stndrd): +class SaveRelationship(Base): __tablename__="save_relationship" @@ -422,3 +497,13 @@ class SaveRelationship(Base, Stndrd): user_id=Column(Integer, ForeignKey("users.id")) submission_id=Column(Integer, ForeignKey("submissions.id")) type=Column(Integer) + + @property + @lazy + def created_date(self): + return time.strftime("%d %B %Y", time.gmtime(self.created_utc)) + + @property + @lazy + def created_datetime(self): + return str(time.strftime("%d/%B/%Y %H:%M:%S UTC", time.gmtime(self.created_utc))) diff --git a/files/classes/user.py b/files/classes/user.py index bd8f5bb0f..273ccfaf5 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -70,7 +70,7 @@ else: } } -class User(Base, Stndrd, Age_times): +class User(Base): __tablename__ = "users" id = Column(Integer, primary_key=True) username = Column(String) @@ -180,6 +180,13 @@ class User(Base, Stndrd, Age_times): super().__init__(**kwargs) + + @property + @lazy + def created_date(self): + + return time.strftime("%d %b %Y", time.gmtime(self.created_utc)) + @property @lazy def user_awards(v): diff --git a/files/classes/userblock.py b/files/classes/userblock.py index f0e6b56ec..b7954dea4 100644 --- a/files/classes/userblock.py +++ b/files/classes/userblock.py @@ -1,9 +1,8 @@ from sqlalchemy import * from sqlalchemy.orm import relationship -from .mix_ins import * from files.__main__ import Base -class UserBlock(Base, Stndrd, Age_times): +class UserBlock(Base): __tablename__ = "userblocks" id = Column(Integer, primary_key=True) @@ -13,6 +12,11 @@ class UserBlock(Base, Stndrd, Age_times): user = relationship("User", innerjoin=True, primaryjoin="User.id==UserBlock.user_id", viewonly=True) target = relationship("User", innerjoin=True, primaryjoin="User.id==UserBlock.target_id", viewonly=True) + @property + @lazy + def created_date(self): + return time.strftime("%d %b %Y", time.gmtime(self.created_utc)) + def __repr__(self): return f"" diff --git a/files/templates/log.html b/files/templates/log.html index 077d4b557..ed8710886 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -53,7 +53,7 @@ {% else %} -
There's nothing here right now.
+
There's nothing here right now.
{% endfor %} @@ -61,18 +61,18 @@