Introducing settings for blender-cloud

Moved Blender Cloud specific settings from Pillar into this application.
This commit is contained in:
2017-08-30 23:13:03 +02:00
parent 0b2583c22e
commit a9280dd05f
4 changed files with 182 additions and 3 deletions

View File

@@ -1,12 +1,17 @@
import itertools import itertools
import json
import logging import logging
from pillarsdk import Node, Project import pillar.api
from pillar.web.users import forms
from pillarsdk import Node, Project, User, exceptions as sdk_exceptions, Group
from pillarsdk.exceptions import ResourceNotFound from pillarsdk.exceptions import ResourceNotFound
from flask_login import current_user from flask_login import current_user, login_required
from flask import Blueprint, current_app, render_template, redirect, session, url_for from flask import Blueprint, current_app, render_template, redirect, session, url_for, abort, flash
from pillar.web.utils import system_util, get_file, current_user_is_authenticated from pillar.web.utils import system_util, get_file, current_user_is_authenticated
from pillar.web.utils import attach_project_pictures from pillar.web.utils import attach_project_pictures
from pillar.web.settings import blueprint as blueprint_settings
blueprint = Blueprint('cloud', __name__) blueprint = Blueprint('cloud', __name__)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@@ -204,3 +209,62 @@ def get_random_featured_nodes():
featured_node_documents.append(node_document) featured_node_documents.append(node_document)
return featured_node_documents return featured_node_documents
@blueprint_settings.route('/emails', methods=['GET', 'POST'])
@login_required
def emails():
"""Main email settings.
"""
if current_user.has_role('protected'):
return abort(404) # TODO: make this 403, handle template properly
api = system_util.pillar_api()
user = User.find(current_user.objectid, api=api)
# Force creation of settings for the user (safely remove this code once
# implemented on account creation level, and after adding settings to all
# existing users)
if not user.settings:
user.settings = dict(email_communications=1)
user.update(api=api)
if user.settings.email_communications is None:
user.settings.email_communications = 1
user.update(api=api)
# Generate form
form = forms.UserSettingsEmailsForm(
email_communications=user.settings.email_communications)
if form.validate_on_submit():
try:
user.settings.email_communications = form.email_communications.data
user.update(api=api)
flash("Profile updated", 'success')
except sdk_exceptions.ResourceInvalid as e:
message = json.loads(e.content)
flash(message)
return render_template('users/settings/emails.html', form=form, title='emails')
@blueprint_settings.route('/billing')
@login_required
def billing():
"""View the subscription status of a user
"""
if current_user.has_role('protected'):
return abort(404) # TODO: make this 403, handle template properly
api = system_util.pillar_api()
user = User.find(current_user.objectid, api=api)
groups = []
if user.groups:
for group_id in user.groups:
group = Group.find(group_id, api=api)
groups.append(group.name)
store_user = pillar.api.blender_cloud.subscription.fetch_subscription_info(user.email)
return render_template(
'users/settings/billing.html',
store_user=store_user, groups=groups, title='billing')

View File

@@ -0,0 +1,20 @@
#settings-sidebar
.settings-header
.settings-title Settings
.settings-content
ul
a(class="{% if title == 'profile' %}active{% endif %}",
href="{{ url_for('settings.profile') }}")
li
i.pi-vcard
| Profile
a(class="{% if title == 'emails' %}active{% endif %}",
href="{{ url_for('settings.emails') }}")
li
i.pi-email
| Emails
a(class="{% if title == 'billing' %}active{% endif %}",
href="{{ url_for('settings.billing') }}")
li
i.pi-credit-card
| Subscription

View File

@@ -0,0 +1,68 @@
| {% extends 'layout.html' %}
| {% block head %}
style(type='text/css').
button#recheck_subscription {
margin-top: 1em;
}
| {% endblock %}
| {% block body %}
.container
#settings
| {% include 'users/settings/_sidebar.html'%}
#settings-container
.settings-header
.settings-title Subscription
.settings-content
| {% if store_user['cloud_access'] %}
h3.subscription-active
i.pi-check
| Your subscription is active
h4 Thank you for supporting us!
hr
p Subscription expires on: <strong>{{ store_user['expiration_date'][:10] }}</strong>
a(href="https://store.blender.org/my-account/subscriptions/") Manage your subscription on Blender Store
| {% else %}
| {% if 'demo' in groups %}
h3.subscription-demo
i.pi-heart-filled
| You have a free account
hr
p You have full access to the Blender Cloud, provided by the Blender Institute. This account is meant for free evaluation of the service. Get in touch with #[a(href="mailto:cloudsupport@blender.org") cloudsupport@blender.org] if you have any questions.
| {% else %}
h3.subscription-missing
i.pi-info
| You do not have an active subscription.
h3
a(href="https://store.blender.org/product/membership/") Get full access to Blender Cloud now!
| {% endif %}
| {% endif %}
p
button#recheck_subscription.btn.btn-default(onclick="javascript:recheck_subscription(this)") Re-check my subscription
hr
script.
function recheck_subscription(button) {
$(button).text('Checking');
$.get('/api/bcloud/update-subscription')
.done(function() {
window.location.reload();
})
.fail(function() {
alert('Unable to update subscription, please check your internet connection.');
})
;
}
| {% endblock %}

View File

@@ -0,0 +1,27 @@
| {% extends 'layout.html' %}
| {% block body %}
.container
#settings
| {% include 'users/settings/_sidebar.html'%}
#settings-container
.settings-header
.settings-title Emails
.settings-content
.settings-form
form#settings-form(method='POST', action="{{url_for('settings.emails')}}")
| {{ form.csrf_token }}
| {% for subfield in form.email_communications %}
.form-group.
{{ subfield }}
{{ subfield.label }}
| {% endfor %}
.buttons
button.btn.btn-default.button-submit(type='submit')
i.pi-check
| Save Changes
| {% endblock %}