Example #1
0
    def show(self, uid):
        T = self.T
        CURL = self.CURL
        self.db.auth.notifier = self.notifier
        user = None
        try:
            user = self.db.auth_user[int(uid)]
        except Exception:
            user = self.db.auth_user(nickname=uid)
        self.context.user = user or redirect(self.CURL('home', 'index'))

        buttons = CAT()
        if self.session.auth and self.session.auth.user:
            relation = self.db.UserContact._relation(self.session.auth.user.id if self.session.auth else 0, user.id)
        else:
            relation = 'unknown'

        relation_text = {'unknown': T('Your are mutually oblivious'),
                'contacts': T('This person is in your contact list (following each other)'),
                'following': T('You follow this person'),
                'follower': T('This person follows you'),
                'yourself': T('This is you')}

        self.context.relation = relation
        self.context.relation_text = relation_text[relation]

        if relation != 'yourself':
            text = {'unknown': T('follow'),
                    'contacts': T('unfollow'),
                    'following': T('unfollow'),
                    'follower': T('follow')}

            post_text = {'unknown': T('Followed!'),
                    'contacts': T('Contact removed!'),
                    'following': T('Unfollowed!'),
                    'follower': T('Contact added!')}

            url = {'unknown': CURL('person', 'follow', args=[user.id, 'profile']),
                    'contacts': CURL('person', 'unfollow', args=[user.id, 'profile']),
                    'following': CURL('person', 'unfollow', args=[user.id, 'profile']),
                    'follower': CURL('person', 'follow', args=[user.id, 'profile'])}

            buttons.append(TAG.BUTTON(text[relation], _onclick="jQuery(this).text('%s');ajax('%s', [], ':eval');jQuery('#relation-text').text('%s');" % (post_text[relation], url[relation], post_text[relation]), _class="btn btn-danger" if relation in ['following', 'contacts'] else 'btn btn-success'))
            #buttons.append(TAG.BUTTON(T("Message"), _class="btn", _onclick="alert('Sorry, it is not implemented yet')"))
            buttons.append(TAG.BUTTON(T("Report/Block"), _class="btn", _onclick="alert('Sorry, it is not implemented yet')"))
        else:
            buttons.append(A(T("Edit Profile"), _class="button btn", _href=CURL('default', 'user', args='profile')))
            #buttons.append(A(T("My Messages"), _class="button btn", _href=CURL('person', 'messages', args=user.nickname or user.id)))

        self.context.buttons = buttons
        self.context.resume = UL(
                                 LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='attach_round.24.png')), A(T("Wrote %s articles", user.articles), _href=self.CURL('article', 'list', vars={'author': user.id}))),
                                 LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='favorite_rounded.24.png')), A(T("Has %s favorites", user.favorites), _href=self.CURL('article', 'list', vars={'favorite': user.id}))),
                                 LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='like_rounded.24.png')), A(T("Liked %s articles", user.likes), _href=self.CURL('article', 'list', vars={'like': user.id}))),
                                 LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='face.24.png')), A(T("Has %s contacts", user.contacts), _href=self.CURL('person', 'contacts', args=user.nickname or user.id))),
                                 #LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='movuca.24.png')), A(T("Joined %s groups", user.groups))),
                                 _class="person-resume"
                                )

        if user.id == self.db.auth.user_id:
            self.context.resume.append(LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='like_rounded.24.png')), A(T("Disliked %s articles", user.dislikes), _href=self.CURL('article', 'list', vars={'dislike': user.id}))))
            self.context.resume.append(LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='like_rounded.24.png')), A(T("Subscribed to %s articles", user.subscriptions), _href=self.CURL('article', 'list', vars={'subscribe': user.id}))))

        self.response.meta.title = "%s | %s | %s" % (
                                                     user.nickname or user.first_name,
                                                     self.T("Profile"),
                                                     self.db.config.meta.title,
                                                    )
        self.response.meta.description = str(user.tagline or user.about) + ' ' + str(user.city or '') + ' ' + str(user.country or '')
        self.response.meta.keywords = [user.first_name, user.last_name, user.nickname]

        self.context.twittername = self.context.user.twitter.split('/')[-1].strip() if self.context.user.twitter else ""
        if self.db.config.auth.use_mailhide:
            key = dict(self.db.config.get_list('auth', 'mailhide'))
            from helpers.mailhide import asurl
            self.context.hiddenmail = asurl(self.context.user.email, key['public'], key['private'])
        else:
            self.context.hiddenmail = ''

        #facebook/google issue
        if self.db.session["%s_setpassword" % self.context.user.id]:
            self.context.user.update_record(password=self.db.session["%s_setpassword" % self.context.user.id])
            self.db.session["%s_setpassword" % self.context.user.id] = None

        if self.db.session["is_new_from"]:
            self.context.alerts.append(XML(self.T("Welcome! You logged in using your %s account, please go to your <a href='%s'>settings</a> page choose your username and complete your profile!", (self.db.session["is_new_from"], self.db.CURL('person', 'account', args='profile')))))
            self.db.auth.initial_user_permission(self.context.user)

        #user extra links image
        # TODO: limit the number of links?
        self.context.extra_links = []
        if user.extra_links:
            image_map = {"github.com": 'github.png',
                         "plus.google.com": 'gplus.png',
                         'twitter.com': 'twitter.png',
                         'facebook.com': 'facebook.png'}
            titles = {"github.com": 'Github',
                         "plus.google.com": 'Google +',
                         'twitter.com': 'Twitter',
                         'facebook.com': 'Facebook'}

            for link in user.extra_links:
                for key, img in image_map.items():
                    if key in link:
                        self.context.extra_links.append({"img": URL('static', '%s/images/icons' % self.context.theme_name, args=img), "link": link, "title": titles.get(key, "")})
                        continue
                if link not in [item['link'] for item in self.context.extra_links]:
                    self.context.extra_links.append({"img": URL('static', '%s/images/icons' % self.context.theme_name, args='globe.png'), "link": link, "title": link})

        if self.context.user.privacy != 1 and \
               relation not in ['contacts', 'follower', 'yourself'] and \
                   not self.db.auth.has_membership("admin", self.db.auth.user_id):
            self.view = 'app/person/show_private'
        else:
            self.view = 'app/person/show'
Example #2
0
    def show(self, uid):
        T = self.T
        CURL = self.CURL
        try:
            user = self.db.auth_user[int(uid)]
        except Exception:
            user = self.db.auth_user(nickname=uid)
        self.context.user = user

        buttons = CAT()
        if self.session.auth and self.session.auth.user:
            relation = self.db.UserContact._relation(
                self.session.auth.user.id if self.session.auth else 0, user.id)
        else:
            relation = 'unknown'

        relation_text = {
            'unknown':
            T('Your are mutually oblivious'),
            'contacts':
            T('This person is in your contact list (following each other)'),
            'following':
            T('You follow this person'),
            'follower':
            T('This person follows you'),
            'yourself':
            T('This is you')
        }

        self.context.relation = relation
        self.context.relation_text = relation_text[relation]

        if relation != 'yourself':
            text = {
                'unknown': T('follow'),
                'contacts': T('unfollow'),
                'following': T('unfollow'),
                'follower': T('follow')
            }

            post_text = {
                'unknown': T('Followed!'),
                'contacts': T('Contact removed!'),
                'following': T('Unfollowed!'),
                'follower': T('Contact added!')
            }

            url = {
                'unknown': CURL('person', 'follow', args=[user.id, 'profile']),
                'contacts': CURL('person',
                                 'unfollow',
                                 args=[user.id, 'profile']),
                'following': CURL('person',
                                  'unfollow',
                                  args=[user.id, 'profile']),
                'follower': CURL('person', 'follow', args=[user.id, 'profile'])
            }

            buttons.append(
                TAG.BUTTON(
                    text[relation],
                    _onclick=
                    "jQuery(this).text('%s');ajax('%s', [], ':eval');jQuery('#relation-text').text('%s');"
                    %
                    (post_text[relation], url[relation], post_text[relation]),
                    _class=""))
            buttons.append(TAG.BUTTON(T("Message"), _class=""))
            buttons.append(TAG.BUTTON(T("Report/Block"), _class=""))
        else:
            buttons.append(
                A(T("Edit Profile"),
                  _class="button",
                  _href=CURL('default', 'user', args='profile')))
            buttons.append(
                A(T("My Messages"),
                  _class="button",
                  _href=CURL('person',
                             'messages',
                             args=user.nickname or user.id)))

        self.context.buttons = buttons
        self.context.resume = UL(
            LI(
                IMG(_src=URL('static',
                             '%s/images/icons' % self.context.theme_name,
                             args='attach_round.24.png')),
                A(T("Wrote %s articles", user.articles),
                  _href=self.CURL('article',
                                  'list',
                                  vars={
                                      'author': user.id,
                                      'limitby': '0,25'
                                  }))),
            LI(
                IMG(_src=URL('static',
                             '%s/images/icons' % self.context.theme_name,
                             args='favorite_rounded.24.png')),
                T("Has %s favorites", user.favorites)),
            LI(
                IMG(_src=URL('static',
                             '%s/images/icons' % self.context.theme_name,
                             args='like_rounded.24.png')),
                T("Liked %s articles", user.likes)),
            LI(
                IMG(_src=URL('static',
                             '%s/images/icons' % self.context.theme_name,
                             args='face.24.png')),
                A(T("Has %s contacts", user.contacts),
                  _href=self.CURL('person',
                                  'contacts',
                                  args=user.nickname or user.id))),
            LI(
                IMG(_src=URL('static',
                             '%s/images/icons' % self.context.theme_name,
                             args='movuca.24.png')),
                T("Joined %s groups", user.groups)),
            _class="person-resume")

        self.response.meta.title = "%s | %s | %s" % (
            user.nickname or user.first_name,
            self.T("Profile"),
            self.db.config.meta.title,
        )
        self.response.meta.description = str(
            user.tagline or user.about) + ' ' + str(
                user.city or '') + ' ' + str(user.country or '')
        self.response.meta.keywords = [
            user.first_name, user.last_name, user.nickname
        ]

        self.context.twittername = self.context.user.twitter.split(
            '/')[-1].strip() if self.context.user.twitter else ""
        if self.db.config.auth.use_mailhide:
            key = dict(self.db.config.get_list('auth', 'mailhide'))
            from helpers.mailhide import asurl
            self.context.hiddenmail = asurl('*****@*****.**',
                                            key['public'], key['private'])
        else:
            self.context.hiddenmail = ''

        #facebook issue
        if self.db.session["%s_setpassword" % self.context.user.id]:
            self.context.user.update_record(
                password=self.db.session["%s_setpassword" %
                                         self.context.user.id])
            self.db.session["%s_setpassword" % self.context.user.id] = None
Example #3
0
    def show(self, uid):
        T = self.T
        CURL = self.CURL
        try:
            user = self.db.auth_user[int(uid)]
        except Exception:
            user = self.db.auth_user(nickname=uid)
        self.context.user = user

        buttons = CAT()
        if self.session.auth and self.session.auth.user:
            relation = self.db.UserContact._relation(self.session.auth.user.id if self.session.auth else 0, user.id)
        else:
            relation = 'unknown'

        relation_text = {'unknown': T('Your are mutually oblivious'),
                'contacts': T('This person is in your contact list (following each other)'),
                'following': T('You follow this person'),
                'follower': T('This person follows you'),
                'yourself': T('This is you')}

        self.context.relation = relation
        self.context.relation_text = relation_text[relation]

        if relation != 'yourself':
            text = {'unknown': T('follow'),
                    'contacts': T('unfollow'),
                    'following': T('unfollow'),
                    'follower': T('follow')}

            post_text = {'unknown': T('Followed!'),
                    'contacts': T('Contact removed!'),
                    'following': T('Unfollowed!'),
                    'follower': T('Contact added!')}

            url = {'unknown': CURL('person', 'follow', args=[user.id, 'profile']),
                    'contacts': CURL('person', 'unfollow', args=[user.id, 'profile']),
                    'following': CURL('person', 'unfollow', args=[user.id, 'profile']),
                    'follower': CURL('person', 'follow', args=[user.id, 'profile'])}

            buttons.append(TAG.BUTTON(text[relation], _onclick="jQuery(this).text('%s');ajax('%s', [], ':eval');jQuery('#relation-text').text('%s');" % (post_text[relation], url[relation], post_text[relation]), _class=""))
            buttons.append(TAG.BUTTON(T("Message"), _class=""))
            buttons.append(TAG.BUTTON(T("Report/Block"), _class=""))
        else:
            buttons.append(A(T("Edit Profile"), _class="button", _href=CURL('default', 'user', args='profile')))
            buttons.append(A(T("My Messages"), _class="button", _href=CURL('person', 'messages', args=user.nickname or user.id)))

        self.context.buttons = buttons
        self.context.resume = UL(
                                 LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='attach_round.24.png')), A(T("Wrote %s articles", user.articles), _href=self.CURL('article', 'list', vars={'author': user.id, 'limitby': '0,25'}))),
                                 LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='favorite_rounded.24.png')), T("Has %s favorites", user.favorites)),
                                 LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='like_rounded.24.png')), T("Liked %s articles", user.likes)),
                                 LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='face.24.png')), A(T("Has %s contacts", user.contacts), _href=self.CURL('person', 'contacts', args=user.nickname or user.id))),
                                 LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='movuca.24.png')), T("Joined %s groups", user.groups)),
                                 _class="person-resume"
                                )

        self.response.meta.title = "%s | %s | %s" % (
                                                     user.nickname or user.first_name,
                                                     self.T("Profile"),
                                                     self.db.config.meta.title,
                                                    )
        self.response.meta.description = str(user.tagline or user.about) + ' ' + str(user.city or '') + ' ' + str(user.country or '')
        self.response.meta.keywords = [user.first_name, user.last_name, user.nickname]

        self.context.twittername = self.context.user.twitter.split('/')[-1].strip() if self.context.user.twitter else ""
        if self.db.config.auth.use_mailhide:
            key = dict(self.db.config.get_list('auth', 'mailhide'))
            from helpers.mailhide import asurl
            self.context.hiddenmail = asurl('*****@*****.**', key['public'], key['private'])
        else:
            self.context.hiddenmail = ''

        #facebook issue
        if self.db.session["%s_setpassword" % self.context.user.id]:
            self.context.user.update_record(password=self.db.session["%s_setpassword" % self.context.user.id])
            self.db.session["%s_setpassword" % self.context.user.id] = None
Example #4
0
    def show(self, uid):
        T = self.T
        CURL = self.CURL
        self.db.auth.notifier = self.notifier
        user = None
        try:
            user = self.db.auth_user[int(uid)]
        except Exception:
            user = self.db.auth_user(nickname=uid)
        self.context.user = user or redirect(self.CURL('home', 'index'))

        buttons = CAT()
        if self.session.auth and self.session.auth.user:
            relation = self.db.UserContact._relation(
                self.session.auth.user.id if self.session.auth else 0, user.id)
        else:
            relation = 'unknown'

        relation_text = {
            'unknown':
            T('Your are mutually oblivious'),
            'contacts':
            T('This person is in your contact list (following each other)'),
            'following':
            T('You follow this person'),
            'follower':
            T('This person follows you'),
            'yourself':
            T('This is you')
        }

        self.context.relation = relation
        self.context.relation_text = relation_text[relation]

        if relation != 'yourself':
            text = {
                'unknown': T('follow'),
                'contacts': T('unfollow'),
                'following': T('unfollow'),
                'follower': T('follow')
            }

            post_text = {
                'unknown': T('Followed!'),
                'contacts': T('Contact removed!'),
                'following': T('Unfollowed!'),
                'follower': T('Contact added!')
            }

            url = {
                'unknown': CURL('person', 'follow', args=[user.id, 'profile']),
                'contacts': CURL('person',
                                 'unfollow',
                                 args=[user.id, 'profile']),
                'following': CURL('person',
                                  'unfollow',
                                  args=[user.id, 'profile']),
                'follower': CURL('person', 'follow', args=[user.id, 'profile'])
            }

            buttons.append(
                TAG.BUTTON(
                    text[relation],
                    _onclick=
                    "jQuery(this).text('%s');ajax('%s', [], ':eval');jQuery('#relation-text').text('%s');"
                    %
                    (post_text[relation], url[relation], post_text[relation]),
                    _class="btn btn-danger" if relation
                    in ['following', 'contacts'] else 'btn btn-success'))
            #buttons.append(TAG.BUTTON(T("Message"), _class="btn", _onclick="alert('Sorry, it is not implemented yet')"))
            buttons.append(
                A(T("Report/Block"),
                  _class="btn",
                  _href=CURL('page',
                             'reportcontent',
                             args=[
                                 "Person", user.id, user.nickname
                                 or user.first_name
                             ])))
        else:
            buttons.append(
                A(T("Edit Profile"),
                  _class="button btn",
                  _href=CURL('default', 'user', args='profile')))
            #buttons.append(A(T("My Messages"), _class="button btn", _href=CURL('person', 'messages', args=user.nickname or user.id)))

        self.context.buttons = buttons
        self.context.resume = UL(
            LI(
                IMG(_src=URL('static',
                             '%s/images/icons' % self.context.theme_name,
                             args='attach_round.24.png')),
                A(T("Wrote %s articles", user.articles),
                  _href=self.CURL('article', 'list', vars={'author':
                                                           user.id}))),
            LI(
                IMG(_src=URL('static',
                             '%s/images/icons' % self.context.theme_name,
                             args='favorite_rounded.24.png')),
                A(T("Has %s favorites", user.favorites),
                  _href=self.CURL('article',
                                  'list',
                                  vars={'favorite': user.id}))),
            LI(
                IMG(_src=URL('static',
                             '%s/images/icons' % self.context.theme_name,
                             args='like_rounded.24.png')),
                A(T("Liked %s articles", user.likes),
                  _href=self.CURL('article', 'list', vars={'like': user.id}))),
            LI(
                IMG(_src=URL('static',
                             '%s/images/icons' % self.context.theme_name,
                             args='face.24.png')),
                A(T("Has %s contacts", user.contacts),
                  _href=self.CURL('person',
                                  'contacts',
                                  args=user.nickname or user.id))),
            #LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='movuca.24.png')), A(T("Joined %s groups", user.groups))),
            _class="person-resume")

        if user.id == self.db.auth.user_id:
            #self.context.resume.append(LI(IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='like_rounded.24.png')), A(T("Disliked %s articles", user.dislikes), _href=self.CURL('article', 'list', vars={'dislike': user.id}))))
            self.context.resume.append(
                LI(
                    IMG(_src=URL('static',
                                 '%s/images/icons' % self.context.theme_name,
                                 args='like_rounded.24.png')),
                    A(T("Subscribed to %s articles", user.subscriptions),
                      _href=self.CURL('article',
                                      'list',
                                      vars={'subscribe': user.id}))))

        self.response.meta.title = "%s | %s | %s" % (
            user.nickname or user.first_name,
            self.T("Profile"),
            self.db.config.meta.title,
        )
        self.response.meta.description = str(
            user.tagline or user.about) + ' ' + str(
                user.city or '') + ' ' + str(user.country or '')
        self.response.meta.keywords = ",".join(
            [user.first_name, user.last_name, user.nickname])
        self.response.meta.og_type = "profile"
        self.response.meta.og_url = self.CURL('person',
                                              'show',
                                              args=user.nickname or user.id,
                                              host=True,
                                              scheme=True)
        self.response.meta.og_images = self.response.meta.og_images or []
        self.response.meta.og_images.append(
            self.get_image(None,
                           'user',
                           themename='menu',
                           user=user,
                           host=True,
                           scheme=True))

        self.context.twittername = self.context.user.twitter.split(
            '/')[-1].strip() if self.context.user.twitter else ""
        if self.db.config.auth.use_mailhide:
            key = dict(self.db.config.get_list('auth', 'mailhide'))
            from helpers.mailhide import asurl
            self.context.hiddenmail = asurl(self.context.user.email,
                                            key['public'], key['private'])
        else:
            self.context.hiddenmail = ''

        #facebook/google issue
        if self.db.session["%s_setpassword" % self.context.user.id]:
            self.context.user.update_record(
                password=self.db.session["%s_setpassword" %
                                         self.context.user.id])
            self.db.session["%s_setpassword" % self.context.user.id] = None

        if self.db.session["is_new_from"]:
            self.context.alerts.append(
                XML(
                    self.T(
                        "Welcome! You logged in using your %s account, please go to your <a href='%s'>settings</a> page choose your username and complete your profile!",
                        (self.db.session["is_new_from"],
                         self.db.CURL('person', 'account', args='profile')))))
            self.db.auth.initial_user_permission(self.context.user)

        #user extra links image
        # TODO: limit the number of links?
        self.context.extra_links = []
        if user.extra_links:
            image_map = {
                "github.com": 'github.png',
                "plus.google.com": 'gplus.png',
                'twitter.com': 'twitter.png',
                'facebook.com': 'facebook.png'
            }
            titles = {
                "github.com": 'Github',
                "plus.google.com": 'Google +',
                'twitter.com': 'Twitter',
                'facebook.com': 'Facebook'
            }

            for link in user.extra_links:
                for key, img in image_map.items():
                    if key in link:
                        self.context.extra_links.append({
                            "img":
                            URL('static',
                                '%s/images/icons' % self.context.theme_name,
                                args=img),
                            "link":
                            link,
                            "title":
                            titles.get(key, "")
                        })
                        continue
                if link not in [
                        item['link'] for item in self.context.extra_links
                ]:
                    self.context.extra_links.append({
                        "img":
                        URL('static',
                            '%s/images/icons' % self.context.theme_name,
                            args='globe.png'),
                        "link":
                        link,
                        "title":
                        link
                    })

        if self.context.user.privacy != 1 and \
               relation not in ['contacts', 'follower', 'yourself'] and \
                   not self.db.auth.has_membership("admin", self.db.auth.user_id):
            self.view = 'app/person/show_private'
        else:
            self.view = 'app/person/show'