dfsfsd
This commit is contained in:
parent
1bc0bf5233
commit
a16d56358c
9 changed files with 258 additions and 128 deletions
|
@ -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"<OauthApp(id={self.id})>"
|
||||
|
||||
|
||||
@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"
|
||||
|
||||
|
@ -55,3 +65,13 @@ class ClientAuth(Base, Stndrd):
|
|||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
user = relationship("User", lazy="joined", viewonly=True)
|
||||
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)))
|
|
@ -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"<Comment(id={self.id})>"
|
||||
|
||||
@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):
|
||||
|
|
|
@ -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"<Flag(id={self.id})>"
|
||||
|
||||
@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"<CommentFlag(id={self.id})>"
|
||||
|
||||
@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)))
|
|
@ -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)))
|
|
@ -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"<ModAction(id={self.id})>"
|
||||
|
||||
@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):
|
||||
|
|
|
@ -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"<Submission(id={self.id})>"
|
||||
|
||||
|
||||
@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)))
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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"<UserBlock(user={user.username}, target={target.username})>"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue