Skip to content

Commit

Permalink
set use_reloader to false when on debug mode, clean up base.html'…
Browse files Browse the repository at this point in the history
…s `<head>`, show complete date when hovering on a post's `created_ago` link
  • Loading branch information
docyx committed Dec 22, 2019
1 parent d07a11f commit 4d162be
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 192 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added app/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions app/config.py
Expand Up @@ -22,10 +22,10 @@
# This will be unique every time create_db.py is ran when testing
# to force clear sessions

SECRET_KEY = 'not-a-real-key-|r|hGvAZExZ6H|r|'
SECRET_KEY = 'not-a-real-key-|r|zKTc5sjF3x|r|'

# Change this to your local URL. IE http://127.0.0.1
URL = 'http://dev.ieddit.com'
URL = 'http://127.0.0.1'

SQLALCHEMY_TRACK_MODIFICATIONS = False

Expand Down
14 changes: 7 additions & 7 deletions app/ieddit.py
Expand Up @@ -670,7 +670,7 @@ def get_comments(sub=None, post_id=None, inurl_title=None, comment_id=None, sort
if sub is None:
abort(404)


try:
post_id = int(post_id)
p = db.session.query(Post).filter_by(id=post_id).first()
Expand All @@ -696,7 +696,7 @@ def get_comments(sub=None, post_id=None, inurl_title=None, comment_id=None, sort
cache_for = None

comments, post, parent_comment = c_get_comments(sub=sub, post_id=post_id, inurl_title=inurl_title,
comment_id=comment_id, sort_by=sort_by, comments_only=comments_only,
comment_id=comment_id, sort_by=sort_by, comments_only=comments_only,
user_id=user_id, cache_for=cache_for)

if post is not None and 'username' in session:
Expand Down Expand Up @@ -1108,12 +1108,12 @@ def create_post(api=False, *args, **kwargs):
@app.route('/get_sub_list', methods=['GET'])
def get_sub_list():
'''
gets sub suggestion dropdown when creating a new post
gets sub suggestion dropdown when creating a new post
'''
subs = get_explore_subs(limit=30)

sublinks = ['<a class="dropdown-item sublist-dropdown"' + \
' href="javascript:setSub(\'%s\')">%s%s</a>' % (s.name, config.SUB_PREFIX, s.name)
' href="javascript:setSub(\'%s\')">%s%s</a>' % (s.name, config.SUB_PREFIX, s.name)
for s in subs]

return '\n'.join(sublinks)
Expand Down Expand Up @@ -1392,7 +1392,7 @@ def reply_message(username=None, mid=None):

return render_template('user/message-reply.html', message=message, sendto=False,
self_pgp=get_pgp_from_username(session['username']),
other_pgp=get_pgp_from_username(message.sender),
other_pgp=get_pgp_from_username(message.sender),
other_user=get_user_from_username(username))


Expand Down Expand Up @@ -1463,7 +1463,7 @@ def msg(username=None):
def view_mod_log(sub=None, limit=10):
sub = normalize_sub(sub)
modactions = db.session.query(Mod_action).filter_by(sub=sub)

if request.url[-4:] != '?all':
modactions = modactions.limit(limit)
modactions = modactions.all()
Expand Down Expand Up @@ -1857,7 +1857,7 @@ def get_stats(subi=None):
dayvotes = len(dayvotes)
dayusers = len(dayusers)

return (len(posts), len(comments), users, bans, messages,
return (len(posts), len(comments), users, bans, messages,
mod_actions, subs, len(votes), daycoms, dayposts,
dayvotes, dayusers, subscripts)

Expand Down
4 changes: 2 additions & 2 deletions app/models.py
Expand Up @@ -57,7 +57,7 @@ def __repr__(self):
return '<Sub %r>' % self.name

class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
id = db.Column(db.Integer, primary_key=True)
url = db.Column(db.String(2000), nullable=True)
self_text = db.Column(db.String(20000), nullable=True)
post_type = db.Column(db.String(15), nullable=False)
Expand Down Expand Up @@ -195,7 +195,7 @@ def __repr__(self):

class Password_reset(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), db.ForeignKey('iuser.username'), nullable=False)
username = db.Column(db.String(20), db.ForeignKey('iuser.username'), nullable=False)
rankey = db.Column(db.String(50), unique=False, nullable=False)
valid = db.Column(db.Boolean, default=True, nullable=False)
expires = db.Column(db.DateTime)
Expand Down
11 changes: 5 additions & 6 deletions app/run.py
Expand Up @@ -4,25 +4,24 @@


# Logging Initialization
import logging
import logging
from utilities.log_utils import logger_init
logger = logging.getLogger(__name__)

import config

@exception_log(logger)
def main(port=80):
app.run(host='0.0.0.0', port=port)
app.run(host='0.0.0.0', port=port, use_reloader=False if config.DEBUG else True)

if __name__ == '__main__':
try:
port = 80
if len(argv) > 1:
port = int(argv[1])
port = int(argv[1])

logger.info(f"Attempting to start app on Port: {port}")
main(port)

except:
logger.exception("Unable to start app.")



30 changes: 16 additions & 14 deletions app/static/main.js
Expand Up @@ -3,6 +3,8 @@ $(document).ready(function() {
for (i=0; i<textAreas.length; i++) {
textCount($(textAreas[i]).attr('id'));
}

$('[data-toggle="tooltip"]').tooltip();
});

var averageRGB = (function () {
Expand All @@ -19,7 +21,7 @@ var averageRGB = (function () {
for (var i=b1.length; i;) {
t = dec2hex( (hex2dec(b1[--i]) + hex2dec(b2[i])) >> 1 );

c[i] = t.length == 2? '' + t : '0' + t;
c[i] = t.length == 2? '' + t : '0' + t;
}
return '#' + c.join('');
}
Expand Down Expand Up @@ -185,7 +187,7 @@ function jsalert(message, atype) {
}

hid = highestAlertId();

html = `<div class="alert alert-dismissible alert-` + atype + ` fade show" id="alert-id-` + hid + `" role="alert">
` + message + `
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
Expand All @@ -194,7 +196,7 @@ function jsalert(message, atype) {
</div>`

$('#alert-ul').append(html);

autoFade('#alert-id-' + hid);
}

Expand All @@ -208,16 +210,16 @@ function autoFade(aid) {

function highestAlertId() {
if (alertCount === -1) {

alerts = $('.alert');

if (alerts.length === 0) {
alertCount = 0;
return 0
}

highest = 0;

for (i=0; i<alerts.length; i++) {
hid = $(alerts[i]).attr('id').split('-')[2];

Expand All @@ -227,7 +229,7 @@ function highestAlertId() {
highest = parseInt(hid);
}
}

alertCount = highest + 1;
return highest + 1;
} else {
Expand Down Expand Up @@ -383,7 +385,7 @@ if (re.test(window.location)) {

/* Preseving this in history to remind myself I should never write code like
this again. The difference between these two functions, and the new
min hide/show, is literally a 2000%+ increase in speed due to far less
min hide/show, is literally a 2000%+ increase in speed due to far less
computational complexity.
function hideComments(comment) {
Expand Down Expand Up @@ -435,7 +437,7 @@ function showComments(comment) {
plevel = parent.attr('level')
child = parent.next()
if (child != undefined) {
clevel = child.attr('level');
console.log(clevel, plevel);
Expand Down Expand Up @@ -473,7 +475,7 @@ function minHide(cid, startingLevel, hide) {
hcomment.css('display', 'block');
} else {
comment.css('display', 'none');
hcomment.css('display', 'none');
hcomment.css('display', 'none');
}

child = comment.next().next()
Expand Down Expand Up @@ -538,13 +540,13 @@ function textCount(elem_id, update=false) {
textArea = $('#' + elem_id);

if (update === false) {
$(textArea).after('<div class="textarea-count" id="textarea-count-' + elem_id + '">' +
'(' + textArea.text().length + ' / ' + textArea.attr('maxlength') + ')' +
$(textArea).after('<div class="textarea-count" id="textarea-count-' + elem_id + '">' +
'(' + textArea.text().length + ' / ' + textArea.attr('maxlength') + ')' +
'</div>');
$(textArea).on('keyup', function() {
textCount(elem_id, update=true);
});
} else {
$('#textarea-count-' + elem_id).text('(' + textArea.val().length + ' / ' + textArea.attr('maxlength') + ')');
}
}
}

0 comments on commit 4d162be

Please sign in to comment.