Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
godarklight committed May 10, 2016
2 parents 9bd3b2e + 90555dc commit 301e0ec
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
*.pyc
*,orig
bin/
config.ini
alembic.ini
Expand Down
14 changes: 7 additions & 7 deletions SpaceDock/blueprints/anonymous.py
Expand Up @@ -35,7 +35,7 @@ def game(gameshort):
new = Mod.query.filter(Mod.published,Mod.game_id == ga.id).order_by(desc(Mod.created)).limit(6)[:6]
recent = Mod.query.filter(Mod.published,Mod.game_id == ga.id, ModVersion.query.filter(ModVersion.mod_id == Mod.id).count() > 1).order_by(desc(Mod.updated)).limit(6)[:6]
user_count = User.query.count()
mod_count = Mod.query.count()
mod_count = Mod.query.filter(Mod.game_id == ga.id).count()
yours = list()
if current_user:
yours = sorted(current_user.following, key=lambda m: m.updated, reverse=True)[:6]
Expand Down Expand Up @@ -120,7 +120,7 @@ def browse_top():
page = int(page)
else:
page = 1
mods, total_pages = search_mods(False,"", page, 30)
mods, total_pages = search_mods(None, "", page, 30)
return render_template("mods/mod_view_browse.html", mods=mods, page=page, total_pages=total_pages,\
url="/browse/top", name="Popular Mods", site_name=_cfg('site-name'), support_mail=_cfg('support-mail'))

Expand Down Expand Up @@ -163,7 +163,7 @@ def browse_all():
page = int(page)
else:
page = 1
mods, total_pages = search_mods(False,"", page, 30)
mods, total_pages = search_mods(None, "", page, 30)
return render_template("mods/mod_view_browse.html", mods=mods, page=page, total_pages=total_pages,\
url="/browse/all", name="All Mods", site_name=_cfg('site-name'), support_mail=_cfg('support-mail'))

Expand Down Expand Up @@ -336,7 +336,7 @@ def singlegame_browse_top(gameshort):
page = int(page)
else:
page = 1
mods, total_pages = search_mods(ga,"", page, 30)
mods, total_pages = search_mods(ga, "", page, 30)
return render_template("mods/mod_view_browse.html", mods=mods, page=page, total_pages=total_pages,ga = ga,\
url="/browse/top", name="Popular Mods", site_name=_cfg('site-name'), support_mail=_cfg('support-mail'))

Expand Down Expand Up @@ -400,7 +400,7 @@ def singlegame_browse_all(gameshort):
page = int(page)
else:
page = 1
mods, total_pages = search_mods(False,"", page, 30)
mods, total_pages = search_mods(ga, "", page, 30)
return render_template("mods/mod_view_browse.html", mods=mods, page=page, total_pages=total_pages,ga = ga,\
url="/browse/all", name="All Mods", site_name=_cfg('site-name'), support_mail=_cfg('support-mail'))

Expand Down Expand Up @@ -442,7 +442,7 @@ def search():
page = int(page)
else:
page = 1
mods, total_pages = search_mods(False,query, page, 30)
mods, total_pages = search_mods(None, query, page, 30)
return render_template("mods/mod_view_browse.html", mods=mods, page=page, total_pages=total_pages, search=True, query=query)

@anonymous.route("/<gameshort>/search")
Expand All @@ -462,5 +462,5 @@ def singlegame_search(gameshort):
page = int(page)
else:
page = 1
mods, total_pages = search_mods(ga,query, page, 30)
mods, total_pages = search_mods(ga, query, page, 30)
return render_template("mods/mod_view_browse.html", mods=mods, page=page, total_pages=total_pages, search=True, query=query,ga=ga)
5 changes: 4 additions & 1 deletion SpaceDock/blueprints/api.py
Expand Up @@ -7,6 +7,7 @@
from SpaceDock.common import *
from SpaceDock.config import _cfg
from SpaceDock.email import send_update_notification, send_grant_notice
from KerbalStuff.celery import notify_ckan
from datetime import datetime
from functools import wraps
from SpaceDock.app import cache
Expand Down Expand Up @@ -268,7 +269,7 @@ def search_mod():
query = '' if not query else query
page = 1 if not page or not page.isdigit() else int(page)
results = list()
for m in search_mods(False,query, page, 30)[0]:
for m in search_mods(None, query, page, 30)[0]:
a = mod_info(m)
a['versions'] = list()
for v in m.versions:
Expand Down Expand Up @@ -836,6 +837,7 @@ def create_mod():
session['gamename'] = ga.name;
session['gameshort'] = ga.short;
session['gameid'] = ga.id;
notify_ckan.delay(mod.id, 'create')
return { 'url': url_for("mods.mod", id=mod.id, mod_name=mod.name), "id": mod.id, "name": mod.name }

@api.route('/api/mod/<mod_id>/update', methods=['POST'])
Expand Down Expand Up @@ -907,4 +909,5 @@ def update_mod(mod_id):
db.commit()
mod.default_version_id = version.id
db.commit()
notify_ckan.delay(mod_id, 'update')
return { 'url': url_for("mods.mod", id=mod.id, mod_name=mod.name), "id": version.id }
18 changes: 6 additions & 12 deletions SpaceDock/blueprints/mods.py
Expand Up @@ -8,6 +8,7 @@
from SpaceDock.config import _cfg
from SpaceDock.blueprints.api import default_description
from SpaceDock.ckan import send_to_ckan
from KerbalStuff.celery import notify_ckan
from werkzeug.utils import secure_filename
from datetime import datetime, timedelta
from shutil import rmtree, copyfile
Expand Down Expand Up @@ -76,21 +77,12 @@ def mod_rss(id, mod_name):
@mods.route("/mod/<int:id>/<path:mod_name>")
@with_session
def mod(id, mod_name):
games = Game.query.filter(Game.active == True).order_by(desc(Game.id)).all()
if session.get('gameid'):
if session['gameid']:
ga = Game.query.filter(Game.id == session['gameid']).order_by(desc(Game.id)).first()
else:
ga = Game.query.filter(Game.short == 'kerbal-space-program').order_by(desc(Game.id)).first()
else:
ga = Game.query.filter(Game.short == 'kerbal-space-program').order_by(desc(Game.id)).first()
mod = Mod.query.filter(Mod.id == id).first()
ga = mod.game
session['game'] = ga.id;
session['gamename'] = ga.name;
session['gameshort'] = ga.short;
session['gameid'] = ga.id;
mod = Mod.query.filter(Mod.id == id,Mod.game_id == ga.id).first()
if not mod:
abort(404)
if not mod or not ga:
abort(404)
editable = False
Expand Down Expand Up @@ -378,6 +370,7 @@ def delete(mod_id):
base_path = os.path.join(secure_filename(mod.user.username) + '_' + str(mod.user.id), secure_filename(mod.name))
full_path = os.path.join(_cfg('storage'), base_path)
db.commit()
notify_ckan.delay(mod_id, 'delete')
rmtree(full_path)
return redirect("/profile/" + current_user.username)

Expand Down Expand Up @@ -569,7 +562,7 @@ def publish(mod_id, mod_name):
mod.published = True
mod.updated = datetime.now()
send_to_ckan(mod)
return redirect(url_for("mods.mod", id=mod.id, mod_name=mod.name,ga=game))
return redirect(url_for("mods.mod", id=mod.id, mod_name=mod.name))

@mods.route('/mod/<int:mod_id>/download/<version>', defaults={ 'mod_name': None })
@mods.route('/mod/<int:mod_id>/<path:mod_name>/download/<version>')
Expand Down Expand Up @@ -764,4 +757,5 @@ def autoupdate(mod_id):
default = mod.default_version()
default.gameversion_id = GameVersion.query.filter(GameVersion.game_id == mod.game_id).order_by(desc(GameVersion.id)).first().id
send_autoupdate_notification(mod)
notify_ckan.delay(mod_id, 'version-update')
return redirect(url_for("mods.mod", id=mod.id, mod_name=mod.name,ga=game))
8 changes: 8 additions & 0 deletions SpaceDock/celery.py
@@ -1,3 +1,4 @@
import requests
import smtplib
from celery import Celery
from email.mime.text import MIMEText
Expand Down Expand Up @@ -42,6 +43,13 @@ def send_mail(sender, recipients, subject, message, important=False):
smtp.sendmail(sender, group, message.as_string())
smtp.quit()

@app.task
def notify_ckan(mod_id, event_type):
if _cfg("notify-url") == "":
return
send_data = { 'mod_id': mod_id, 'event_type': event_type }
requests.post(_cfg("notify-url"), send_data)

@app.task
def update_patreon():
donation_cache.set('patreon_update_time', time.time())
Expand Down
2 changes: 1 addition & 1 deletion SpaceDock/ckan.py
Expand Up @@ -43,10 +43,10 @@ def send_to_ckan(mod):
Mod details:
name = {2}
author = {0}
description = {5}
abstract = {6}
license = {7}
Homepage = {8}
description = {5}
Please direct questions about this pull request to [{0}]({4}{3}).
""".format(mod.user.username, mod.name,\
Expand Down
3 changes: 3 additions & 0 deletions config.ini.example
Expand Up @@ -100,6 +100,9 @@ github_pass=
# Thumbnail size in WxH format, leave blank to disable screenshots
thumbnail_size=320x320

# SpaceDock-Notify dispatcher
notify-url=

# Patreon details
patreon_user_id=
patreon_campaign=
18 changes: 18 additions & 0 deletions db_initialize.py
Expand Up @@ -12,13 +12,31 @@
if not User.query.filter(User.username.ilike("admin")).first():
admin = User("admin", "admin@example.com", "development")
admin.admin = True
user.public = True
admin.confirmation = None
db.add(admin)
db.commit()

# Create normal user if doesn't exist
if not User.query.filter(User.username.ilike("user")).first():
user = User("user", "user@example.com", "development")
user.public = True
user.confirmation = None
db.add(user)
db.commit()

if not Publisher.query.first():
pub = Publisher("Squad")
db.add(pub)
db.commit()

if not Game.query.first():
game = Game("Kerbal Space Program", 1, "kerbal-space-program")
game.active = True
db.add(game)
db.commit()

if not GameVersion.query.first():
gameversion = GameVersion('1.0', 1)
db.add(gameversion)
db.commit()

0 comments on commit 301e0ec

Please sign in to comment.