Permalink
Browse files

teach api about the ways of jsonp

  • Loading branch information...
1 parent e578d06 commit 3b4ae24bf80fa75dd83a1b0693db45845c873af4 VITAS committed May 3, 2016
View
@@ -3,6 +3,7 @@
from flask.ext.htmlmin import HTMLMIN
from flask_pagedown import PageDown
from flaskext.markdown import Markdown
+from flask_json import FlaskJSON, JsonError, json_response, as_json, as_json_p
from jinja2 import FileSystemLoader, ChoiceLoader
from werkzeug.utils import secure_filename
from datetime import datetime, timedelta
@@ -42,6 +43,7 @@
from SpaceDock.blueprints.api import api
app = Flask(__name__)
+FlaskJSON(app)
app.config['MINIFY_PAGE'] = False
pagedown = PageDown(app)
app.jinja_env.filters['firstparagraph'] = firstparagraph
@@ -7,6 +7,8 @@
from SpaceDock.config import _cfg
from SpaceDock.email import send_update_notification, send_grant_notice
from datetime import datetime
+from functools import wraps
+from flask_json import FlaskJSON, JsonError, json_response, as_json, as_json_p
import time
import os
@@ -17,6 +19,7 @@
api = Blueprint('api', __name__)
+
default_description = """This is your mod listing! You can edit it as much as you like before you make it public.
To edit **this** text, you can click on the "**Edit this Mod**" button up there.
@@ -28,6 +31,7 @@
Thanks for hosting your mod on SpaceDock!"""
#some helper functions to keep things consistant
+
def user_info(user):
return {
"username": user.username,
@@ -316,7 +320,7 @@ def login():
return { 'error': False }
@api.route("/api/mod/<modid>")
-@json_output
+@as_json_p
def mod(modid):
if not modid.isdigit():
return { 'error': True, 'reason': 'Invalid mod ID.' }, 400
@@ -336,7 +340,7 @@ def mod(modid):
return info
@api.route("/api/mod/<modid>/<version>")
-@json_output
+@as_json_p
def mod_version(modid, version):
if not modid.isdigit():
return { 'error': True, 'reason': 'Invalid mod ID.' }, 400
@@ -358,7 +362,7 @@ def mod_version(modid, version):
return info
@api.route("/api/user/<username>")
-@json_output
+@as_json_p
def user(username):
user = User.query.filter(User.username == username).first()
if not user:
@@ -174,7 +174,7 @@ def mod(id, mod_name):
outdated = False
if latest:
outdated = latest.gameversion.id != game_versions[0].id and latest.gameversion.friendly_version != '1.0.5'
- return render_template("base/overview.html",ptype='mod',stype='view',
+ return render_template("detail.html",ptype='mod',stype='view',
**{
'mod': mod,
'latest': latest,
View
@@ -41,6 +41,7 @@ Flask-SQLAlchemy-Cache
flask-io
Flask-HTMLmin
Flask-Redis
+Flask-JSON
Jinja2
Mako
Markdown
@@ -2,16 +2,16 @@
{% block styles %}
{% endblock %}
-{% block modals %}
+{% block modals scoped %}
{% endblock %}
-{% block body %}
+{% block body scoped %}
<div class="contentwrap">
<div class="content">
{% block content scoped %}
{% endblock %}
- </divcontent>
+ </div>
</div>
{% endblock %}
@@ -101,12 +101,33 @@
</div>
{%- endmacro %}
+{# add page specific nav items #}
{% macro navitem(title,url,icon,ismodal=false,miscdata="") -%}
<a{%- if ismodal %} data-toggle="modal"{%- endif %} {{ miscdata }} href="{{ url }}">
<li><span class="icon-{{ icon }}"></span>&nbsp;{{ title }}</li>
</a>
{%- endmacro %}
+{# add list item to detail info list #}
+{% macro listitem(title,msg,icon) -%}
+ <div class="lmodule">
+ <div class="lnode"><span class="icon-{{ icon }}"></span></div>
+ <div class="lnodetext">
+ <h4>{{ title }}</h4>
+ {{ msg }}
+ </div>
+ </div>
+{%- endmacro %}
+
+{# add detail site warn message #}
+{% macro warnmsg(title,msg) -%}
+ <div class="module cw80">
+
+ <h2>{{ title }}</h2>
+ <p>{{ msg }}</p>
+ </div>
+{%- endmacro %}
+
{# module include #}
{# has to be below ALL macros #}
{% macro inc(smod) -%}
@@ -189,7 +210,7 @@
</nav>
{# modal modes #}
-{% block modal %}
+{% block modal scoped %}
<div class="dim">
<div class="modal">
{% if not user %}
@@ -219,7 +240,7 @@
</form>
</div>
{% endif %}
- {% block modals %}
+ {% block modals scoped %}
{% endblock %}
</div>
@@ -21,6 +21,19 @@
$('.modheader').aspectratio(0);
var mhh = $(".modheader").innerHeight();
$(".modinfo .module").height(mhh);
+
+//experimental ajax
+ $(".topright").html("loading");
+ $.ajax({
+ url: "/api/mod/{{ mod.id }}",
+ error: function(obj,status,err){
+ $(".topright").html("Status: " + status + " Error: " + err)
+ },
+ success: function(data,status,obj){
+ alert("ok");
+ }
+ });
+
});
window.mod_id = {{ mod.id }};
@@ -41,37 +54,46 @@
{%- endblock %}
-{%- block pagenav %}
- {{ inc("nav") }}
+{%- block pagenav scoped%}
+
{%- endblock %}
-{%- block content %}
+{%- block content scoped%}
<div class="cw20 leftspace modsuggestions right">
- <div class="module">
- {{ inc("farright") }}
+ <div class="module farright">
+ {%- block farright scoped %}
+ {%- endblock %}
+
</div>
</div>
<div class="cw20 modinfo leftspace right">
- <div class="module">
- {{ inc("topright") }}
+ <div class="module topright">
+ {%- block topright scoped %}
+ {%- endblock %}
</div>
</div>
<div class="cw60 modheadimg">
- <div class="module">
- {{ inc("topcenter") }}
+ <div class="module topcenter">
+ {%- block topcenter scoped %}
+ {%- endblock %}
</div>
</div>
<div class="spacer cw80"></div>
- {{ inc("infomsg") }}
- <div class="module cw80">
- {{ inc("middle") }}
+ <div class="infomsg">
+ {%- block infomsg scoped %}
+ {%- endblock %}
+ </div>
+ <div class="module cw80 middle">
+ {%- block middle scoped %}
+ {%- endblock %}
</div>
<div class="spacer cw80"></div>
- <div class="module cw80">
- {{ inc("bottommiddle") }}
+ <div class="module cw80 bottommiddle">
+ {%- block bottommiddle scoped %}
+ {%- endblock %}
</div>
{%- endblock %}
-{% block modals %}
-{{ inc("modals") }}
+{% block modals scoped %}
+
{% endblock %}
Oops, something went wrong.

0 comments on commit 3b4ae24

Please sign in to comment.