Skip to content

Commit

Permalink
some restyling and reimplementation
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jan 5, 2015
1 parent 41aca85 commit ee3cbc2
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 69 deletions.
20 changes: 16 additions & 4 deletions COMET/__init__.py
Expand Up @@ -69,13 +69,23 @@ def generate_menu_alt():
</ul>
</li>""".format(current_user.realname, current_user.username, edit_entry)

def _author_get(post):
a = post.meta['en']['author']
return a if a else current_user.realname

def _author_uid_get(post):
u = post.meta['en']['author.uid']
return u if u else current_user.uid

def render(template_name, context=None):
if context is None:
context = {}
context['g'] = g
context['request'] = request
context['session'] = session
context['current_user'] = current_user
context['_author_get'] = _author_get
context['_author_uid_get'] = _author_uid_get
return _site.render_template(template_name, None, context)

def unauthorized():
Expand All @@ -97,12 +107,12 @@ class User(object):
active = False
is_admin = False
can_see_others_posts = False
want_see_others_posts = True
wants_see_others_posts = True
can_upload_attachments = True
can_rebuild_site = True

def __init__(self, uid, username, realname, password, active, is_admin,
can_see_others_posts, want_see_others_posts,
can_see_others_posts, wants_see_others_posts,
can_upload_attachments, can_rebuild_site):
self.uid = uid
self.username = username
Expand All @@ -111,7 +121,7 @@ def __init__(self, uid, username, realname, password, active, is_admin,
self.active = active
self.is_admin = is_admin
self.can_see_others_posts = can_see_others_posts
self.want_see_others_posts = want_see_others_posts
self.wants_see_others_posts = wants_see_others_posts
self.can_upload_attachments = can_upload_attachments
self.can_rebuild_site = can_rebuild_site

Expand Down Expand Up @@ -165,7 +175,7 @@ def write_users():
'active': user.active,
'is_admin': user.is_admin,
'can_see_others_posts': user.can_see_others_posts,
'want_see_others_posts': user.want_see_others_posts,
'wants_see_others_posts': user.wants_see_others_posts,
'can_upload_attachments': user.can_upload_attachments,
'can_rebuild_site': user.can_rebuild_site,
}
Expand Down Expand Up @@ -298,7 +308,9 @@ def new_post():
def new_page():
title = request.form['title']
try:
_site.config['ADDITIONAL_METADATA']['author.uid'] = current_user.uid
_site.commands.new_page(title=title, author=current_user.realname, content_format='html')
del _site.config['ADDITIONAL_METADATA']['author.uid']
except SystemExit:
return "This post already exists!", 500
# reload post list and go to index
Expand Down
9 changes: 8 additions & 1 deletion COMET/templates/jinja/comet_post_edit.tmpl
Expand Up @@ -77,8 +77,15 @@
<h3 class="panel-title">Metadata</h3>
</div>
<div class="panel-body">
<input name="author.uid" value="{{ _author_uid_get(post) }}" type="hidden">
<div class="form-group">
<label for="author" class="col-sm-2 control-label">Author</label>
<div class="col-sm-10">
<input name="author" value="{{ _author_get(post) }}" class="form-control">
</div>
</div>
{% for k,v in post.meta['en'].items() %}
{% if k != 'title' %}
{% if k not in ['title', 'author', 'author.uid'] %}
<div class="form-group">
<label for="{{ k }}" class="col-sm-2 control-label">{{ k }}</label>
<div class="col-sm-10">
Expand Down
9 changes: 8 additions & 1 deletion COMET/templates/mako/comet_post_edit.tmpl
Expand Up @@ -77,8 +77,15 @@
<h3 class="panel-title">Metadata</h3>
</div>
<div class="panel-body">
<input name="author.uid" value="${_author_uid_get(post)}" type="hidden">
<div class="form-group">
<label for="author" class="col-sm-2 control-label">Author</label>
<div class="col-sm-10">
<input name="author" value="${_author_get(post)}" class="form-control">
</div>
</div>
% for k,v in post.meta['en'].items():
% if k != 'title':
% if k not in ['title', 'author', 'author.uid']:
<div class="form-group">
<label for="${k}" class="col-sm-2 control-label">${k}</label>
<div class="col-sm-10">
Expand Down
68 changes: 49 additions & 19 deletions COMET/templates/mako/comet_profile.tmpl
Expand Up @@ -9,25 +9,55 @@
<div class="alert alert-${alert_status}" role="alert">${alert}</div>
% endif

<form action="/profile/save" method="POST">
<div class="form-group">
<label for="name">Real name</label>
<input class="form-control" id="realname" name="realname" value="${current_user.realname}" placeholder="Real name">
</div>
<div class="form-group">
<label for="oldpwd">Old password:</label>
<input type="password" class="form-control" id="oldpwd" name="oldpwd" placeholder="Old password">
<p class="help-block">If you do not want to change your password, leave the fields blank.</p>
</div>
<div class="form-group">
<label for="newpwd1">New password:</label>
<input type="password" class="form-control" id="newpwd1" name="newpwd1" placeholder="New password">
</div>
<div class="form-group">
<label for="newpwd2">Repeat new password:</label>
<input type="password" class="form-control" id="newpwd2" name="newpwd2" placeholder="Repeat new password">
</div>
<button type="submit" class="btn btn-default">Save</button>
<form action="/profile/save" method="POST" class="form-horizontal">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Details</h3>
</div>
<div class="panel-body">

<div class="form-group">
<label for="name" class="col-sm-2 control-label">Real name</label>
<div class="col-sm-10"><input class="form-control" id="realname" name="realname" value="${current_user.realname}" placeholder="Real name"></div>
</div>
<div class="form-group">
<label for="oldpwd" class="col-sm-2 control-label">Old password</label>
<div class="col-sm-10"><input type="password" class="form-control" id="oldpwd" name="oldpwd" placeholder="Old password">
<p class="help-block">If you do not want to change your password, leave the fields blank.</p></div>
</div>
<div class="form-group">
<label for="newpwd1" class="col-sm-2 control-label">New password</label>
<div class="col-sm-10"><input type="password" class="form-control" id="newpwd1" name="newpwd1" placeholder="New password"></div>
</div>
<div class="form-group">
<label for="newpwd2" class="col-sm-2 control-label">Repeat password</label>
<div class="col-sm-10"><input type="password" class="form-control" id="newpwd2" name="newpwd2" placeholder="Repeat new password"></div>
</div>
</div>
</div>


<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Preferences</h3>
</div>
<div class="panel-body">
<div class="checkbox"><label><input type="checkbox" name="wants_see_others_posts"
% if current_user.can_see_others_posts and current_user.wants_see_others_posts:
checked
% endif
% if not current_user.can_see_others_posts:
disabled
% endif
> Show me posts of other users
</label></div>
</div>
</div>


<div style="text-align: center;">
<button type="submit" class="btn btn-primary btn-lg"><i class="fa fa-save"></i> Save</button>
</div>
</form>

</%block>
114 changes: 74 additions & 40 deletions COMET/templates/mako/comet_users_edit.tmpl
Expand Up @@ -4,53 +4,87 @@
</%block>
<%block name="content">
% if not new:
<h1 class="title">Editing profile <tt>${user.username}</tt></h1>
<h1 class="title">Editing user <tt>${user.username}</tt></h1>
% else:
<h1 class="title">Creating profile <tt>${user.username}</tt></h1>
<h1 class="title">Creating user <tt>${user.username}</tt></h1>
% endif

% if alert:
<div class="alert alert-${alert_status}" role="alert">${alert}</div>
% endif

<form action="/users/save" method="POST">
<input name="uid" type="hidden" value="${user.uid}">
<div class="form-group">
<label for="name">Real name</label>
<input class="form-control" id="realname" name="realname" value="${user.realname}"
placeholder="Real name" required>
</div>
% if user.password:
<div class="form-group">
<label for="newpwd1">New password:</label>
<input type="password" class="form-control" id="newpwd1" name="newpwd1" placeholder="New password">
<p class="help-block">If you do not want to change the password, leave the fields blank.</p>
</div>
<div class="form-group">
<label for="newpwd2">Repeat new password:</label>
<input type="password" class="form-control" id="newpwd2" name="newpwd2" placeholder="Repeat new password">
</div>
% else:
<div class="form-group">
<label for="newpwd1">Password:</label>
<input type="password" class="form-control" id="newpwd1" name="newpwd1" placeholder="Password" required>
</div>
<div class="form-group">
<label for="newpwd2">Repeat password:</label>
<input type="password" class="form-control" id="newpwd2" name="newpwd2" placeholder="Repeat password" required>
</div>
% endif
<div class="checkbox"><label>
<input type="checkbox" name="is_admin"
% if user.is_admin:
checked
% endif
% if user == current_user:
disabled
% endif
> Is administrator
</label></div>
<button type="submit" class="btn btn-default">Save</button>
<form action="/users/save" method="POST" class="form-horizontal">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Details</h3>
</div>
<div class="panel-body">

<input name="uid" type="hidden" value="${user.uid}">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Real name</label>
<div class="col-sm-10"><input class="form-control" id="realname" name="realname" value="${user.realname}" @placeholder="Real name" required></div>
</div>
% if user.password:
<div class="form-group">
<label for="newpwd1" class="col-sm-2 control-label">New password</label>
<div class="col-sm-10"><input type="password" class="form-control" id="newpwd1" name="newpwd1" placeholder="New password">
<p class="help-block">If you do not want to change the password, leave the fields blank.</p></div>
</div>
<div class="form-group">
<label for="newpwd2" class="col-sm-2 control-label">Repeat password</label>
<div class="col-sm-10"><input type="password" class="form-control" id="newpwd2" name="newpwd2" placeholder="Repeat password"></div>
</div>
% else:
<div class="form-group">
<label for="newpwd1" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10"><input type="password" class="form-control" id="newpwd1" name="newpwd1" placeholder="Password" required></div>
</div>
<div class="form-group">
<label for="newpwd2" class="col-sm-2 control-label">Repeat password</label>
<div class="col-sm-10"><input type="password" class="form-control" id="newpwd2" name="newpwd2" placeholder="Repeat password" required></div>
</div>
% endif
</div>
</div>

<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Preferences</h3>
</div>
<div class="panel-body">
<div class="checkbox"><label><input type="checkbox" name="wants_see_others_posts"
% if user.can_see_others_posts and user.wants_see_others_posts:
checked
% endif
% if not user.can_see_others_posts:
disabled
% endif
> Show this user posts of other users
</label></div>
</div>
</div>

<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Permissions</h3>
</div>
<div class="panel-body">
<div class="checkbox"><label><input type="checkbox" name="is_admin"
% if user.is_admin:
checked
% endif
% if user == current_user:
disabled
% endif
> User is an administrator
</label></div>
</div>
</div>

<div style="text-align: center;">
<button type="submit" class="btn btn-primary btn-lg"><i class="fa fa-save"></i> Save</button>
</div>
</form>

</%block>
8 changes: 4 additions & 4 deletions COMET/users.json
Expand Up @@ -3,7 +3,7 @@
"username": "admin",
"realname": "Website Administrator",
"can_see_others_posts": true,
"want_see_others_posts": true,
"wants_see_others_posts": true,
"can_upload_attachments": true,
"can_rebuild_site": true,
"is_admin": true,
Expand All @@ -14,7 +14,7 @@
"username": "user3",
"realname": "User Three",
"can_see_others_posts": false,
"want_see_others_posts": true,
"wants_see_others_posts": true,
"can_upload_attachments": true,
"can_rebuild_site": true,
"is_admin": false,
Expand All @@ -25,7 +25,7 @@
"username": "user2",
"realname": "User Two",
"can_see_others_posts": false,
"want_see_others_posts": true,
"wants_see_others_posts": true,
"can_upload_attachments": true,
"can_rebuild_site": true,
"is_admin": false,
Expand All @@ -36,7 +36,7 @@
"username": "user4",
"realname": "User Four",
"can_see_others_posts": false,
"want_see_others_posts": true,
"wants_see_others_posts": true,
"can_upload_attachments": true,
"can_rebuild_site": true,
"is_admin": true,
Expand Down

0 comments on commit ee3cbc2

Please sign in to comment.