Skip to content

Commit

Permalink
New profile page and permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
rochacbruno committed Feb 7, 2012
1 parent b74f15e commit 267c0f7
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 34 deletions.
9 changes: 9 additions & 0 deletions controllers/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,12 @@ def check_availability():
else:
items['img'] = str(IMG(_title=T("Available"), _class="%(field)s_availability_img" % items, _src=URL('static', person.context.theme_name, args=['images', 'icons', 'right.24.png'])))
return "jQuery('.%(field)s_availability_img').hide();jQuery('#auth_user_%(field)s').css({'border': '1px solid green'});jQuery('#auth_user_%(field)s').parent().append('%(img)s');" % items


def notificationpermission():
person = Person()
pid = request.args(0)
way = request.args(1)
action = request.args(2)
person.notificationpermission(pid, way, action)
return person.context.button
15 changes: 14 additions & 1 deletion modules/datamodel/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def set_fixtures(self):
def initial_user_permission(self, user):
try:
for event, value in self.events:
self.entity.update_or_insert(self.entity.unikey == "%s_%s" % (user.id, event),
self.entity.update_or_insert(self.entity.unikey == "%s_%s" % (user['id'], event),
user_id=user['id'],
event_type=event,
way=[key for key, val in self.ways])
Expand All @@ -54,6 +54,19 @@ def initial_user_permission(self, user):
else:
self.db.commit()

def add_permission_if_dont_exists(self, user):
try:
for event, value in self.events:
permission = self.entity(unikey="%s_%s" % (user['id'], event))
if not permission:
self.entity.insert(user_id=user['id'],
event_type=event,
way=[key for key, val in self.ways])
except Exception:
self.db.rollback()
else:
self.db.commit()

def set_permission_to_all(self):
users = self.db(self.db.auth_user.id > 0).select()
for user in users:
Expand Down
38 changes: 10 additions & 28 deletions modules/datamodel/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,21 @@ def set_properties(self):
"last_name": T("Last Name"),
"email": T("E-mail"),
"password": T("Password"),
"nickname": T("Username"),
"privacy": T("Privacy"),
"tagline": T("Tagline"),
"twitter": T("twitter"),
"facebook": T("Facebook"),
"website": T("website"),
"extra_links": T("Your Links"),
"avatar": T("avatar"),
"photo_source": T("Photo source"),
"about": T("about"),
"gender": T("Gender"),
"birthdate": T("Birth Date"),
"country": T("Country"),
"city": T("City"),
"languages": T("Languages")
}

self.comments = {
"nickname": T("Your desired username"),
"privacy": T("Your profile privacy"),
"tagline": T("A short sentence about you"),
"twitter": T("twitter account"),
"facebook": T("Facebook username or ID"),
"website": T("website or blog"),
"extra_links": T("Include more links (flickr, facebook page, github, etc)"),
"avatar": T("your profile picture"),
"photo_source": T("Which photo to use in your profile"),
"nickname": T("Nickname - will be used for links and signatures"),
"privacy": T("Privacy - Profile and content visibility"),
"tagline": T("Tagline - short sentence about you"),
"twitter": T("twitter - your twitter username"),
"facebook": T("Facebook - Your facebook username or id"),
"website": T("website - your primary link on the web"),
"extra_links": T("Extra links - up to 5 links for your profiles (blog, github, company etc)"),
"avatar": T("Avatar - Used only when photo source is 'upload'"),
"photo_source": T("Photo source - you can use the avatar from:"),
"about": T("about you"),
"gender": T("Gender"),
"birthdate": T("Birth Date"),
"country": T("Country"),
"city": T("City"),
"languages": T("Languages you speak")
"languages": T("Languages")
}

def set_validators(self):
Expand Down
56 changes: 56 additions & 0 deletions modules/handlers/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ def account(self):

self.context.auth = self.db.auth
self.context.form = self.db.auth()
self.context.customfield = customfield
if 'profile' in self.request.args:
self.notifier.permission.add_permission_if_dont_exists(self.db.auth.user)
self.context.permissions = self.db(self.notifier.permission.entity.user_id == self.db.auth.user_id).select()
self.context.permission_events = dict(self.notifier.permission.events)

def loginbare(self):
username = self.request.vars.email
Expand Down Expand Up @@ -499,3 +504,54 @@ def check_availability(self, items):
return {}

return self.db.auth_user._validate(**items_to_check)

def notificationpermission(self, pid, way, action):
permission = self.notifier.permission.entity(user_id=self.db.auth.user.id, id=pid)
if permission:
current_way = permission.way
if action == "enable" and not way in current_way:
current_way.append(way)
permission.update_record(way=current_way)
self.db.commit()
self.context.button = TAG.BUTTON(TAG['i'](_class="icon-ok", _style="margin-right:5px;"),
self.T("Enabled"),
_class="notificationpermission btn btn-success",
_id="%s_%s" % (way, pid),
**{"_data-url": URL('person', 'notificationpermission', args=[pid, way, 'disable'])})
elif action == "disable" and way in current_way:
current_way.remove(way)
permission.update_record(way=current_way)
self.db.commit()
self.context.button = TAG.BUTTON(TAG['i'](_class="icon-off", _style="margin-right:5px;"),
self.T("Disabled"),
_class="notificationpermission btn btn-danger",
_id="%s_%s" % (way, pid),
**{"_data-url": URL('person', 'notificationpermission', args=[pid, way, 'enable'])})


def customfield(form, field, css={"main": "row", "label": "", "comment": "", "widget": "", "input": "", "error": ""}):
tablefield = (form.table, field)
maindiv = DIV(_id="%s_%s__row" % tablefield, _class=css.get("main", ""))
if field in form.errors:
maindiv["_class"] += css.get("error", "")
labeldiv = DIV(_class="w2p_fl %s" % css.get("label", ""))
commentdiv = DIV(_class="w2p_fc %s" % css.get("comment", ""))
widgetdiv = DIV(_class="w2p_fw %s" % css.get("widget", ""))

label = LABEL(form.custom.label[field], _for="%s_%s" % tablefield, _id="%s_%s__label" % tablefield)
comment = form.custom.comment[field]
widget = form.custom.widget[field]

widget_class = widget.attributes.get("_class", "")
widget_class += css.get("input", "")
widget["_class"] = widget_class

labeldiv.append(label)
commentdiv.append(comment)
widgetdiv.append(widget)

maindiv.append(labeldiv)
maindiv.append(commentdiv)
maindiv.append(widgetdiv)

return maindiv
3 changes: 2 additions & 1 deletion modules/movuca.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(self, db):
#self.settings.register_onaccept = lambda form: add_to_users_group(form)
self.settings.register_onaccept = [lambda form: self.send_welcome_email(form.vars),
lambda form: self.initial_user_permission(form.vars)]
#self.settings.login_onaccept = [lambda form: self.initial_user_permission(form.vars)]
#self.settings.profile_onvalidation = []
self.settings.profile_onaccept = [lambda form: self.remove_facebook_google_alert(form)] # remove facebook / google alert session
#self.settings.change_password_onaccept = [] # send alert email
Expand All @@ -77,7 +78,7 @@ def __init__(self, db):
self.settings.logged_url = self.url('account', args='profile')
self.settings.login_next = self.db.CURL('person', 'show')
self.settings.register_next = self.db.CURL('person', 'show')
self.settings.profile_next = self.db.CURL('person', 'show')
self.settings.profile_next = self.db.CURL('person', 'account', args='profile')
self.settings.retrieve_username_next = self.url('account', args='login')
self.settings.retrieve_password_next = self.url('account', args='login')
self.settings.request_reset_password_next = self.url('account', args='login')
Expand Down
23 changes: 19 additions & 4 deletions views/bootstrap/app/person/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,28 @@
});
</script>
{{pass}}
<h2>{{=T( request.args(0).replace('_',' ').capitalize() )}}</h2>
<hr />

{{if 'profile' in request.args:}}
<h2>{{=T("Your settings")}}</h2>
{{else:}}
<h2>{{=T( request.args(0).replace('_',' ').capitalize() )}}</h2>
<hr />
{{pass}}



<div id="web2py_user_form">
{{submit_button = form.elements(_type="submit")[0]}}
{{submit_button['_class'] = "btn btn-primary"}}
{{=form}}
<hr />


{{if 'profile' in request.args:}}
{{include "bootstrap/app/person/profile.html"}}
{{else:}}
{{=form}}
<hr />
{{pass}}

{{if request.args(0) in ['login', 'register'] and use_facebook:}}
<a href="{{=URL('person', 'facebook', args='login')}}">{{=IMG(_src=URL('static', 'basic', args=['images', 'facebook-connect.png']))}}</a>
{{pass}}
Expand Down
94 changes: 94 additions & 0 deletions views/bootstrap/app/person/profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{{
css = {"main": "row-fluid", "widget": "", "input":" span12", "error": " control-group error"}
}}
<div class="tabbable">

<ul class="nav nav-tabs">
<li class="active"><a href="#1" data-toggle="tab">Profile</a></li>
<li><a href="#2" data-toggle="tab">Notifications</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active row-fluid" id="1" style="padding:0;margin:0;padding-bottom:20px;">
{{=form.custom.begin}}
<fieldset class="span5" style="margin-right:40px;">
{{=customfield(form,'first_name', css=css)}}
{{=customfield(form,'last_name', css=css)}}
{{=customfield(form,'nickname', css=css)}}
{{=customfield(form,'tagline', css=css)}}
{{=customfield(form,'about', css=css)}}
{{=customfield(form,'birthdate', css=css)}}
{{=customfield(form,'website', css=css)}}
{{=customfield(form,'extra_links', css=css)}}

</fieldset>
<fieldset class="span5">
{{=customfield(form,'privacy',css=css)}}
{{=customfield(form,'email',css=css)}}
{{=customfield(form,'twitter',css=css)}}
{{=customfield(form,'facebook',css=css)}}
{{=customfield(form,'photo_source',css=css)}}
{{=customfield(form,'avatar',css=css)}}
{{=customfield(form,'gender',css=css)}}
{{=customfield(form,'languages',css=css)}}
{{=customfield(form,'city', css=css)}}
{{=customfield(form,'country', css=css)}}
</fieldset>
<fieldset class="span12">
<button class="btn btn-primary btn-large" style="width:100%">{{=T("Save changes")}}</button>
</fieldset>


{{=form.custom.end}}
</div>
<div class="tab-pane" id="2">
<div class="alert">
{{=T("Choose how do you want to get notifications")}}
</div>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>{{=iicon('question-sign')}}{{=T("When someone")}}</th>
<th>{{=iicon('exclamation-sign')}}{{=T("Site notification")}}</th>
<th>{{=iicon('envelope')}}{{=T("Email notification")}}</th>
</tr>
</thead>
<tbody>
{{for permission in permissions:}}
<tr id="row_{{=permission.id}}">
<td>{{=permission_events[permission.event_type] % ("", "")}}</td>
<td id="cel_site_{{=permission.id}}">
<button id="site_{{=permission.id}}" data-loading-text="loading" class="notificationpermission {{='btn btn-success' if 'site' in permission.way else 'btn btn-danger'}}" data-url="{{=URL('person', 'notificationpermission', args=[permission.id, 'site', 'disable' if 'site' in permission.way else 'enable'])}}">
{{=iicon('ok' if 'site' in permission.way else 'off')}}
{{=T('Enabled' if 'site' in permission.way else 'Disabled')}}
</button>
</td>
<td id="cel_email_{{=permission.id}}">
<button id="email_{{=permission.id}}" data-loading-text="loading" class="notificationpermission {{='btn btn-success' if 'email' in permission.way else 'btn btn-danger'}}" data-url="{{=URL('person', 'notificationpermission', args=[permission.id, 'email', 'disable' if 'email' in permission.way else 'enable'])}}">
{{=iicon('ok' if 'email' in permission.way else 'off')}}
{{=T('Enabled' if 'email' in permission.way else 'Disabled')}}
</button>
</td>
</tr>
{{pass}}
</tbody>
</table>
</div>
</div>
</div>
<script>
jQuery(document).on("click", ".notificationpermission", function(){
url = jQuery(this).attr('data-url');
target = jQuery(this).parent().attr("id");
ajax(url,[],target);
return false;

});
// jQuery(function() {
// jQuery(".notificationpermission").click(function(){
// url = jQuery(this).attr('data-url');
// target = jQuery(this).parent().attr("id");
// ajax(url,[],target);
// return false;
// });
// });
</script>

0 comments on commit 267c0f7

Please sign in to comment.