You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2019/06/17 15:54:53 UTC

[allura] 02/02: [#8283] Construct user card html in serverside using jinja

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 2b84a7eec575ff4d0cd56c8c95be8978d78202f2
Author: Shalitha Suranga <sh...@gmail.com>
AuthorDate: Sat Jun 15 21:46:27 2019 +0530

    [#8283] Construct user card html in serverside using jinja
---
 .../ext/user_profile/templates/user_card.html      | 32 ++++++++++++++++++++++
 Allura/allura/ext/user_profile/user_main.py        | 21 ++++++++++++--
 Allura/allura/nf/allura/css/site_style.css         |  7 ++++-
 Allura/allura/public/nf/js/allura-base.js          | 27 ++----------------
 .../allura/tests/functional/test_user_profile.py   | 13 +++++----
 5 files changed, 66 insertions(+), 34 deletions(-)

diff --git a/Allura/allura/ext/user_profile/templates/user_card.html b/Allura/allura/ext/user_profile/templates/user_card.html
new file mode 100644
index 0000000..e862c37
--- /dev/null
+++ b/Allura/allura/ext/user_profile/templates/user_card.html
@@ -0,0 +1,32 @@
+{#-
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+-#}
+<div class="user-card">
+  <div class="card-left">
+    <img src="{{ img }}">
+  </div>
+  <div class="card-right">
+    <div class="name">{{ name }}</div>
+    {% if location %}
+      <span class="subitem subitem-loc"><i class="fa fa-map-marker fa-fw"></i> {{ location }}</span><br/>
+    {% endif %}
+    {% if website %}
+      <span class="subitem subitem-web"><i class="fa fa-globe fa-fw"></i> {{website | urlize(60,nofollow=True)}}</span>
+    {% endif %}
+  </div>
+</div>
\ No newline at end of file
diff --git a/Allura/allura/ext/user_profile/user_main.py b/Allura/allura/ext/user_profile/user_main.py
index 67502fd..7a80a2e 100644
--- a/Allura/allura/ext/user_profile/user_main.py
+++ b/Allura/allura/ext/user_profile/user_main.py
@@ -203,14 +203,29 @@ class UserProfileController(BaseController, FeedController):
         return redirect(c.project.user_project_of.url())
         
     @without_trailing_slash
-    @expose('json:')
+    @expose('jinja:allura.ext.user_profile:templates/user_card.html')
     def user_card(self):
         u = c.project.user_project_of
+        locationData = u.get_pref('localization')
+        webpages = u.get_pref('webpages')
+        location = ''
+        website = ''
+        if locationData.city and locationData.country:
+            location = locationData.city + ', ' + locationData.country
+        elif locationData.country and not locationData.city:
+            location = locationData.country
+        elif locationData.city and not locationData.country:
+            location = locationData.city
+
+        if len(webpages) > 0:
+            website = webpages[0]
+
         return dict(
             username=u.username,
-            img=g.gravatar(u.get_pref('email_address'), size=64),
+            img=u.icon_url(),
             name=u.display_name,
-            localization=u.get_pref('localization')._deinstrument())
+            location=location,
+            website=website)
 
 
 class UserProfileRestController(AppRestControllerMixin):
diff --git a/Allura/allura/nf/allura/css/site_style.css b/Allura/allura/nf/allura/css/site_style.css
index e35b5f8..43f8c2b 100644
--- a/Allura/allura/nf/allura/css/site_style.css
+++ b/Allura/allura/nf/allura/css/site_style.css
@@ -4081,8 +4081,13 @@ Nav bar styles moved out of navbar.css since they are more stylistic than layout
 .user-card .card-right .name{
   font-size: 14px;
   font-weight: bold;
+  padding-bottom: 8px;
 }
 
-.user-card .card-right .location{
+.user-card .card-right .subitem{
   font-size: 12px;
 }
+
+.user-card .card-right .subitem a{
+  color: #00b3ff;
+}
diff --git a/Allura/allura/public/nf/js/allura-base.js b/Allura/allura/public/nf/js/allura-base.js
index 428b00e..21857b4 100644
--- a/Allura/allura/public/nf/js/allura-base.js
+++ b/Allura/allura/public/nf/js/allura-base.js
@@ -268,30 +268,7 @@ $(function(){
 var umProfileStore = {}; // caching profile data
 
 var displayUserCard = function(instance, data) {
-    var toolBody = '';
-    var locationBody = '';
-
-    if(data.localization.city || data.localization.country) {
-        locationBody += '<span class="location"><i class="fa fa-map-marker"></i> ';
-        if(data.localization.city && data.localization.country) 
-            locationBody += data.localization.city + ', ' + data.localization.country;
-        else if(data.localization.city)
-            locationBody += data.localization.city;
-        else
-            locationBody += data.localization.country;
-        locationBody += '</span>';
-    }
-
-    toolBody = '<div class="user-card">' +
-                    '<div class="card-left">'+
-                        '<img src="' + data.img + '">' +
-                    '</div>' +
-                    '<div class="card-right">' +
-                        '<span class="name">' + data.name + '</span><br/>' +
-                        locationBody +
-                    '</div>' + 
-                '</div>';
-    $(instance).tooltipster('content', toolBody);
+    $(instance).tooltipster('content', data);
 }
 
 $(function(){
@@ -305,7 +282,7 @@ $(function(){
         maxWidth: 400,
         contentAsHTML: true,
         interactive: true,
-        content: 'test',
+        content: 'Loading...',
         functionReady: function (instance, helper) {
             var userUrl = $(this).attr('href');
             
diff --git a/Allura/allura/tests/functional/test_user_profile.py b/Allura/allura/tests/functional/test_user_profile.py
index d19ebd4..fb98de5 100644
--- a/Allura/allura/tests/functional/test_user_profile.py
+++ b/Allura/allura/tests/functional/test_user_profile.py
@@ -50,13 +50,16 @@ class TestUserProfile(TestController):
             'city': 'test-city',
             'country': 'US'
         }
+        webpages = ['http://allura.apache.org/']
         user.set_pref('localization', locals)
+        user.set_pref('webpages', webpages)
         r = self.app.get('/u/test-admin/profile/user_card')
-        assert 'img' in r.json
-        assert user.display_name == r.json['name']
-        assert user.username == r.json['username']
-        assert user.get_pref('localization')['city'] == r.json['localization']['city']
-        assert user.get_pref('localization')['country'] == r.json['localization']['country']
+
+        assert user.icon_url() == r.html.find('img').attrs['src']
+        assert user.display_name == r.html.find('div', attrs={'class': 'name'}).getText()
+        assert user.get_pref('localization')['city'] in r.html.find('span', attrs={'class': 'subitem-loc'}).getText()
+        assert user.get_pref('localization')['country'] in r.html.find('span', attrs={'class': 'subitem-loc'}).getText()
+        assert user.get_pref('webpages')[0] in str(r.html.find('span', attrs={'class': 'subitem-web'}))
 
     def test_wrong_profile(self):
         self.app.get('/u/no-such-user/profile/', status=404)