remotes/1693045480750635534/spooky-22
Aevann1 2021-09-19 20:22:57 +02:00
parent ca67562791
commit 0ff6a26335
9 changed files with 258 additions and 128 deletions

View File

@ -2,12 +2,11 @@ from flask import *
from sqlalchemy import * from sqlalchemy import *
from sqlalchemy.orm import relationship, lazyload from sqlalchemy.orm import relationship, lazyload
from .mix_ins import Stndrd
from .submission import Submission from .submission import Submission
from .comment import Comment from .comment import Comment
from files.__main__ import Base from files.__main__ import Base
class OauthApp(Base, Stndrd): class OauthApp(Base):
__tablename__ = "oauth_apps" __tablename__ = "oauth_apps"
@ -21,6 +20,17 @@ class OauthApp(Base, Stndrd):
def __repr__(self): return f"<OauthApp(id={self.id})>" 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 @property
def permalink(self): return f"/admin/app/{self.id}" 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()] return [x[0] for x in posts.all()]
class ClientAuth(Base, Stndrd): class ClientAuth(Base):
__tablename__ = "client_auths" __tablename__ = "client_auths"
@ -54,4 +64,14 @@ class ClientAuth(Base, Stndrd):
access_token = Column(String(128)) access_token = Column(String(128))
user_id = Column(Integer, ForeignKey("users.id")) user_id = Column(Integer, ForeignKey("users.id"))
user = relationship("User", lazy="joined", viewonly=True) user = relationship("User", lazy="joined", viewonly=True)
application = relationship("OauthApp", 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)))

View File

@ -6,7 +6,6 @@ from sqlalchemy.orm import relationship, deferred
from files.helpers.lazy import lazy from files.helpers.lazy import lazy
from files.helpers.const import SLURS from files.helpers.const import SLURS
from files.__main__ import Base from files.__main__ import Base
from .mix_ins import *
from .flags import CommentFlag from .flags import CommentFlag
from os import environ from os import environ
@ -23,7 +22,7 @@ class CommentAux(Base):
ban_reason = Column(String(256), default='') ban_reason = Column(String(256), default='')
class Comment(Base, Age_times): class Comment(Base):
__tablename__ = "comments" __tablename__ = "comments"
@ -75,6 +74,75 @@ class Comment(Base, Age_times):
return f"<Comment(id={self.id})>" 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 @property
@lazy @lazy
def score(self): def score(self):

View File

@ -1,9 +1,8 @@
from sqlalchemy import * from sqlalchemy import *
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from files.__main__ import Base from files.__main__ import Base
from .mix_ins import *
class Flag(Base, Stndrd): class Flag(Base):
__tablename__ = "flags" __tablename__ = "flags"
@ -18,8 +17,18 @@ class Flag(Base, Stndrd):
return f"<Flag(id={self.id})>" 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" __tablename__ = "commentflags"
@ -33,3 +42,13 @@ class CommentFlag(Base, Stndrd):
def __repr__(self): def __repr__(self):
return f"<CommentFlag(id={self.id})>" 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)))

View File

@ -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)))

View File

@ -1,10 +1,9 @@
from sqlalchemy import * from sqlalchemy import *
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from files.__main__ import Base from files.__main__ import Base
from .mix_ins import *
import time import time
class ModAction(Base, Stndrd, Age_times): class ModAction(Base):
__tablename__ = "modactions" __tablename__ = "modactions"
id = Column(BigInteger, primary_key=True) id = Column(BigInteger, primary_key=True)
@ -35,6 +34,38 @@ class ModAction(Base, Stndrd, Age_times):
def __repr__(self): def __repr__(self):
return f"<ModAction(id={self.id})>" 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 @property
def note(self): def note(self):

View File

@ -1,12 +1,11 @@
from flask import render_template, g from flask import render_template, g
from sqlalchemy import * from sqlalchemy import *
from sqlalchemy.orm import relationship, deferred from sqlalchemy.orm import relationship
import re, random import re, random
from urllib.parse import urlparse from urllib.parse import urlparse
from files.helpers.lazy import lazy from files.helpers.lazy import lazy
from files.helpers.const import SLURS from files.helpers.const import SLURS
from files.__main__ import Base from files.__main__ import Base
from .mix_ins import *
from .flags import * from .flags import *
from os import environ from os import environ
@ -28,7 +27,7 @@ class SubmissionAux(Base):
embed_url = Column(String(256)) embed_url = Column(String(256))
class Submission(Base, Age_times): class Submission(Base):
__tablename__ = "submissions" __tablename__ = "submissions"
@ -83,6 +82,82 @@ class Submission(Base, Age_times):
def __repr__(self): def __repr__(self):
return f"<Submission(id={self.id})>" 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 @property
@lazy @lazy
def score(self): def score(self):
@ -414,7 +489,7 @@ class Submission(Base, Age_times):
def ordered_flags(self): return self.flags.order_by(Flag.id).all() def ordered_flags(self): return self.flags.order_by(Flag.id).all()
class SaveRelationship(Base, Stndrd): class SaveRelationship(Base):
__tablename__="save_relationship" __tablename__="save_relationship"
@ -422,3 +497,13 @@ class SaveRelationship(Base, Stndrd):
user_id=Column(Integer, ForeignKey("users.id")) user_id=Column(Integer, ForeignKey("users.id"))
submission_id=Column(Integer, ForeignKey("submissions.id")) submission_id=Column(Integer, ForeignKey("submissions.id"))
type=Column(Integer) 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)))

View File

@ -70,7 +70,7 @@ else:
} }
} }
class User(Base, Stndrd, Age_times): class User(Base):
__tablename__ = "users" __tablename__ = "users"
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
username = Column(String) username = Column(String)
@ -180,6 +180,13 @@ class User(Base, Stndrd, Age_times):
super().__init__(**kwargs) super().__init__(**kwargs)
@property
@lazy
def created_date(self):
return time.strftime("%d %b %Y", time.gmtime(self.created_utc))
@property @property
@lazy @lazy
def user_awards(v): def user_awards(v):

View File

@ -1,9 +1,8 @@
from sqlalchemy import * from sqlalchemy import *
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from .mix_ins import *
from files.__main__ import Base from files.__main__ import Base
class UserBlock(Base, Stndrd, Age_times): class UserBlock(Base):
__tablename__ = "userblocks" __tablename__ = "userblocks"
id = Column(Integer, primary_key=True) 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) 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) 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): def __repr__(self):
return f"<UserBlock(user={user.username}, target={target.username})>" return f"<UserBlock(user={user.username}, target={target.username})>"

View File

@ -53,7 +53,7 @@
{% else %} {% else %}
<div>There's nothing here right now.</div> <div>There's nothing here right now.</div>
{% endfor %} {% endfor %}
</div> </div>
@ -61,18 +61,18 @@
<nav aria-label="Page navigation" class="mb-5"> <nav aria-label="Page navigation" class="mb-5">
<ul class="pagination pagination-sm mb-0"> <ul class="pagination pagination-sm mb-0">
{% if page>1 %} {% if page>1 %}
<li class="page-item"> <li class="page-item">
<small><a class="page-link" href="?page={{page-1}}" tabindex="-1">Prev</a></small> <small><a class="page-link" href="?page={{page-1}}" tabindex="-1">Prev</a></small>
</li> </li>
{% else %} {% else %}
<li class="page-item disabled"><span class="page-link">Prev</span></li> <li class="page-item disabled"><span class="page-link">Prev</span></li>
{% endif %} {% endif %}
{% if next_exists %} {% if next_exists %}
<li class="page-item"> <li class="page-item">
<small><a class="page-link" href="?page={{page+1}}">Next</a></small> <small><a class="page-link" href="?page={{page+1}}">Next</a></small>
</li> </li>
{% else %} {% else %}
<li class="page-item disabled"><span class="page-link">Next</span></li> <li class="page-item disabled"><span class="page-link">Next</span></li>
{% endif %} {% endif %}
</ul> </ul>
</nav> </nav>