Introducing settings for blender-cloud
Moved Blender Cloud specific settings from Pillar into this application.
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
import itertools
|
||||
import json
|
||||
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 flask_login import current_user
|
||||
from flask import Blueprint, current_app, render_template, redirect, session, url_for
|
||||
from flask_login import current_user, login_required
|
||||
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 attach_project_pictures
|
||||
from pillar.web.settings import blueprint as blueprint_settings
|
||||
|
||||
blueprint = Blueprint('cloud', __name__)
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -204,3 +209,62 @@ def get_random_featured_nodes():
|
||||
featured_node_documents.append(node_document)
|
||||
|
||||
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')
|
||||
|
Reference in New Issue
Block a user