Ejemplo n.º 1
0
 def GET(self):
     user = users.get_current_user()
     if user:
         e = util.get_user(user=user)
         f = profile_form()
         if e.bio:
             f = profile_form(
                 nickname=e.nickname,
                 first_name=e.bio.first_name,
                 middle_name=e.bio.middle_name,
                 last_name=e.bio.last_name,
                 city=e.bio.city,
                 state=e.bio.state,
                 postal_code=e.bio.postal_code,
                 country=e.bio.country,
                 bio=e.bio.bio,
             )
         return t.render(
             util.data(
                 form=f,
                 title="Edit Profile",
                 instructions="""Please enter whatever information you feel comfortable
         sharing. (Please note that your information is not public until you
         grant us permission to share it in your Preferences)""",
             )
         )
     else:
         return t.render(util.data(title="Not Logged In!", instructions="Please Log in to Edit Your Profile"))
Ejemplo n.º 2
0
 def POST(self):
     user = users.get_current_user()
     d = web.input(
         first_name=False,
         middle_name=False,
         last_name=False,
         city=False,
         state=False,
         postal_code=False,
         country=False,
         bio=False,
     )
     f = profile_form(
         first_name=d.first_name,
         middle_name=d.middle_name,
         last_name=d.last_name,
         city=d.city,
         state=d.state,
         postal_code=d.postal_code,
         country=d.country,
         bio=d.bio,
     )
     if not f.validate():
         return t.render(
             util.data(
                 form=f, title="Preferences", instructions="Please indicate which items you wish to make public."
             )
         )
     else:
         prefs = [i.name for i in f if i.data]
         e = util.get_user(user=user)
         e.shared.public = prefs
         e.shared.put()
         mdel(key=user.user_id(), namespace="profile_data")
         raise web.seeother("/preferences")
Ejemplo n.º 3
0
    def post(self):
        f = profile_form()
        data = self.get_arguments()
        user = self.current_user
        accounts = extract_input_array(self.request.arguments, 'acc_')
        accounts = User.filter_valid_accounts(accounts)
        
        _ = self._
        
        try:
            attachments = self.get_argument('attachments', None)
            if attachments:
                data['attachments'] = parse_attachments(data['attachments'], True)

            if f.validates(tornado.web._O(data)):
                data['bank_accounts'] = accounts
                if data.get('password', None):
                    data['password_hashed'] = hashlib.sha1(data.get('password')).hexdigest()
                user.save(data, user)

                if attachments:
                    user['attachments'] = move_attachments(self.settings.upload_path, data['attachments'])
                    user.update_html()
                    user.save()
                
                self.set_flash(_("Profile saved."))
                self.redirect("/profile/%s" % user.username)
                return
            raise InvalidFormDataError(_("Form still have errors. Please correct them before saving."))
        except Exception, e:
            if not isinstance(e, InvalidFormDataError): raise
            f.note = f.note if f.note else e
            self.render('profile/edit', f=f, user=user, accounts=accounts)
Ejemplo n.º 4
0
 def get(self):
     f = profile_form()
     user = self.current_user
     accounts = user.get_bank_accounts()
     accounts = BankAccount.listify(accounts) if accounts.count() else []
     user.formify()
     f.fill(user)
     self.render("profile/edit", f=f, user=user, accounts=accounts)
Ejemplo n.º 5
0
 def user(self, *args):
     user = User.one({'username': args[0]})
     if not user:
         raise tornado.web.HTTPError(404)
         return
     accounts = user.get_bank_accounts()
     accounts = BankAccount.listify(accounts) if accounts.count() else []
     user.formify()
     f = profile_form()
     f.fill(user)
     self.render("admin/user", user=user, accounts=accounts, f=f)
Ejemplo n.º 6
0
 def user(self, *args):
     user = User.one({'username': args[0]})
     if not user:
         raise tornado.web.HTTPError(404)
         return
     accounts = user.get_bank_accounts()
     accounts = BankAccount.listify(accounts) if accounts.count() else []
     user.formify()
     f = profile_form()
     f.fill(user)
     self.render("admin/user", user=user, accounts=accounts, f=f)
     
Ejemplo n.º 7
0
 def POST(self):
     user = users.get_current_user()
     d = web.input()
     f = profile_form(
         nickname=d.nickname,
         first_name=d.first_name,
         middle_name=d.middle_name,
         last_name=d.last_name,
         city=d.city,
         state=d.state,
         postal_code=d.postal_code,
         country=d.country,
         bio=d.bio,
     )
     if not f.validate():
         return t.render(
             util.data(
                 form=f,
                 title="Edit Profile",
                 instructions="""Please enter whatever information you feel comfortable
         sharing. (Please note that your information is not shared.public until you
         grant us permission to share it in your Preferences)""",
             )
         )
     else:
         e = util.get_user(user=user)
         if e.nickname:
             e.nickname = f.nickname.data
             db.put(e)
         e.bio.first_name = f.first_name.data or ""
         e.bio.middle_name = f.middle_name.data or ""
         e.bio.last_name = f.last_name.data or ""
         e.bio.city = f.city.data or ""
         e.bio.state = f.state.data or ""
         e.bio.postal_code = f.postal_code.data or ""
         e.bio.country = f.country.data or ""
         e.bio.bio = f.bio.data or ""
         e.bio.put()
         mdel(key=user.user_id(), namespace="profile_data")
         raise web.seeother("/profile")
Ejemplo n.º 8
0
'''
This is where all the specific content for pages should go.

Both html.py patterns and content (text) can be specified here. The urls.txt
and the pre-made generic structures will compose it properly. (At least
that's the idea.)
'''
from datetime import datetime
from flask import request
from forms import login_form, logout_form, profile_form


pform_string, pform = profile_form()
pform_string = pform_string.getvalue()


def body(body, title, page_title, form, crumbs, **extra):
  '''
  A simple body renderer.
  '''
  pre = request.environ.get('SCRIPT_NAME', '')
  if 'own_URL' in extra:
    extra['own_URL'] = pre + extra['own_URL']
  body.h1(page_title)
  with body.div as d:
    d(class_='crumbs')
    n = len(crumbs) - 1
    for i, (name, URL) in enumerate(crumbs):
      a = d.a(name, href=pre + URL)
      if i < n:
        d += ' - '