Esempio n. 1
0
    def get(self):
        auth_level = self.is_user_authorized()
        if auth_level == models.AUTH_LEVEL_REGISTERED_USER:
            self.redirect("/account/activate/reminder/")
        elif auth_level == models.AUTH_LEVEL_ACTIVATED_USER:
            today = datetime.utcnow()

            year = self.request.get("year")
            month = self.request.get("month")

            if not year or not month:
                year = today.year
                month = today.month
            else:
                year = dec(year)
                month = dec(month)
            articles = Article.get_all_published_student_articles_for_month(year, month)
            books = Book.get_latest(count=10)
            response = render_template(
                "blog_students.html",
                year_list=models.BLOG_YEAR_LIST,
                month_list=models.MONTH_LIST,
                today=today,
                requested_year=year,
                requested_month=month,
                articles=articles,
                books=books,
            )
            self.response.out.write(response)
        else:
            response = render_template("index.html")
            self.response.out.write(response)
def index(request):
    if tokens_p(request):
        # get the realname here. we already have it in the js account model
        api = get_api()
        account_id = urllib.unquote(request.session['oauth_token_set']['account_id'])
        try:
            res = api.account_info(account_id = account_id)
        except:
            res = None
        
        # got account info from the server
        if res and res.response:
            if 200 == res.response.get('response_status', 0):
                e = ET.fromstring(res.response.get('response_data', '<xml/>'))
                fullname = e.findtext('fullName')
                return utils.render_template('ui/index', { 'ACCOUNT_ID': account_id,
                                                             'FULLNAME': fullname,
                                                 'ALLOW_ADDING_RECORDS': settings.ALLOW_ADDING_RECORDS,
                                                   'HIDE_GET_MORE_APPS': settings.HIDE_GET_MORE_APPS,
                                                         'HIDE_SHARING': settings.HIDE_SHARING })
            # error
            return_url = request.session.get('return_url', '/')
            err_msg = res.response.get('response_data', '500: Unknown Error')
            return utils.render_template(LOGIN_PAGE, {'ERROR': ErrorStr(err_msg), 'RETURN_URL': return_url, 'SETTINGS': settings})
    
    return HttpResponseRedirect(reverse(login))
Esempio n. 3
0
    def POST(self, key):
        i = web.input(v=None, _method="GET")

        if spamcheck.is_spam():
            return render_template("message.html",
                "Oops",
                'Something went wrong. Please try again later.')

        recap = get_recaptcha()

        if recap and not recap.validate():
            return render_template("message.html",
                'Recaptcha solution was incorrect',
                'Please <a href="javascript:history.back()">go back</a> and try again.'
            )

        v = i.v and safeint(i.v, None)
        work = web.ctx.site.get(key, v)
        if work is None:
            raise web.notfound()

        try:
            helper = SaveBookHelper(work, None)
            helper.save(web.input())
            add_flash_message("info", utils.get_message("flash_work_updated"))
            raise web.seeother(work.url())
        except (ClientException, ValidationException) as e:
            add_flash_message('error', str(e))
            return self.GET(key)
Esempio n. 4
0
def register(request):
    """
    http://localhost/change_password
    Returns the register template (GET) or creates a new account (POST)
    """
    if HTTP_METHOD_POST == request.method:
        if not settings.REGISTRATION.get('enable', False):
            return utils.render_template('ui/error', {'error_message': ErrorStr('Registration disabled'), 'error_status': 403})
        
        # create the account
        post = request.POST
        set_primary = settings.REGISTRATION.get('set_primary_secret', 1)
        user_hash = {'account_id': post.get('account_id'),
                 'contact_email': post.get('account_id'),        # TODO:the contact_email key is not present in the register form for now, so use the account_id
                     'full_name': post.get('full_name'),
              'primary_secret_p': set_primary,
            'secondary_secret_p': settings.REGISTRATION.get('set_secondary_secret', 1)}
        api = get_api()
        res, content = api.account_create(body=user_hash)
        
        # on success, forward to page according to the secrets that were or were not generated
        if '200' == res['status']:
            account_xml = content or '<root/>'
            account = utils.parse_account_xml(account_xml)
            account_id = account.get('id')
            if not set_primary:
                return utils.render_template(LOGIN_PAGE, {'MESSAGE': _('You have successfully registered.') + ' ' + _('After an administrator has approved your account you may login.'), 'SETTINGS': settings})
            
            # display the secondary secret if there is one
            has_secondary_secret = (None != account.get('secret') and len(account.get('secret')) > 0)
            if has_secondary_secret:
                return utils.render_template('ui/register', {'SETTINGS': settings, 'ACCOUNT_ID': account_id, 'SECONDARY': account.get('secret'), 'MESSAGE': _('You have successfully registered.') + ' ' + _('At the link sent to your email address, enter the following activation code:')})
            return HttpResponseRedirect('/accounts/%s/send_secret/sent' % account_id)
        return utils.render_template('ui/register', {'ERROR': ErrorStr((content or 'Setup failed')), 'SETTINGS': settings})
    return utils.render_template('ui/register', {'SETTINGS': settings})
Esempio n. 5
0
    def GET(self, key):
        if not is_admin():
            return render_template('permission_denied', web.ctx.path, "Permission denied.")
    
        edition = web.ctx.site.get(key)
        if not edition:
            raise web.notfound()

        if edition.ocaid:
            ebook_key = "ebooks/" + edition.ocaid
            ebook = web.ctx.site.store.get(ebook_key) or {}
        else:
            ebook = None

        i = web.input(updatestatus=None)
        if i.updatestatus == 't':
            edition.update_loan_status()
        edition_loans = get_edition_loans(edition)
            
        user_loans = []
        user = accounts.get_current_user()
        if user:
            user_loans = get_loans(user)
            
        return render_template("borrow_admin", edition, edition_loans, ebook, user_loans, web.ctx.ip)
Esempio n. 6
0
def create_developer_account(request):
  if request.method == "GET":
    return utils.render_template('ui/create_developer_account',
      {})
    

  api = get_api()

  username = request.POST.get("username")
  password = request.POST.get("password")
  given_name = request.POST.get("given_name")
  family_name = request.POST.get("family_name")
  department = request.POST.get("department")
  role = request.POST.get("role")

  data = {"account_id" : username, "password" : password, 
          "given_name" : given_name, "family_name" : family_name, 
          "department": department, "role" : role}

  ret = api.call("POST", "/users/", options={'data': data})
  if (ret == "account_exists"):
    return utils.render_template('ui/create_developer_account',
      { 'error': "Account '%s' is already registered."%username })
  

  return utils.render_template(LOGIN_PAGE, 
                                 {"error": "Account %s has been created.  Please log in."%username,
                                  "account" : username
                                  }
                                 )
Esempio n. 7
0
def account_initialization_2(request):
  if request.method == HTTP_METHOD_POST:
    account_id = request.path_info.split('/')[3]
    username = request.POST['username'].lower().strip()
    password = request.POST['pw1']
    errors = {
        'generic': 'There was a problem updating your data. Please try again. If you are unable to change your password please contact support.',
        'collision': 'That username is already taken. Please enter different one.'
    }
    api = IndivoClient(settings.CONSUMER_KEY, settings.CONSUMER_SECRET, settings.INDIVO_SERVER_LOCATION)
    ret = api.add_auth_system(
      account_id = account_id,
      data = {'system':'password',
              'username': username,
              'password': password})
    
    if ret.response['response_status'] == 200:
      # everything's OK, log this person in, hard redirect to change location
      tokens_get_from_server(request, username, password)
      return HttpResponseRedirect('/')
    elif ret.response['response_status'] == 400:
       return utils.render_template('ui/account_init_2', {'ERROR': errors['collision']})
    else:
      return utils.render_template('ui/account_init_2', {'ERROR': errors['generic']})
  else:
    return utils.render_template('ui/account_init_2', {})
Esempio n. 8
0
  def get(self):
	tweets = models.Tweet.all().search(self.request.get("q")).order('-created_at').fetch(1000)
	template_values = {
		"tweets": tweets,
		"searchterm": self.request.get("q")
	}
	utils.render_template(self, "views/search.html", template_values)
Esempio n. 9
0
  def get(self, path):
    if not path.startswith(config.url_prefix):
      if path not in ROOT_ONLY_FILES:
        self.error(404)
        self.response.out.write(utils.render_template('404.html'))
        return
    else:
      if config.url_prefix != '':
        path = path[len(config.url_prefix):]# Strip off prefix
        if path in ROOT_ONLY_FILES:# This lives at root
          self.error(404)
          self.response.out.write(utils.render_template('404.html'))
          return
    content = get(path)
    if not content:
      self.error(404)
      self.response.out.write(utils.render_template('404.html'))
      return

    serve = True
    if 'If-Modified-Since' in self.request.headers:
      try:
        last_seen = datetime.datetime.strptime(
            self.request.headers['If-Modified-Since'].split(';')[0],# IE8 '; length=XXXX' as extra arg bug
            HTTP_DATE_FMT)
        if last_seen >= content.last_modified.replace(microsecond=0):
          serve = False
      except ValueError, e:
        import logging
        logging.error('StaticContentHandler in static.py, ValueError:' + self.request.headers['If-Modified-Since'])
Esempio n. 10
0
    def get(self):
        from pickle import dumps
        from ebs.merchant.api import get_ebs_request_parameters

        dr = self.request.get('DR')
        if dr:
            billing_settings = BillingSettings.get_settings(deployment_mode=ebs_mode)
            request = get_ebs_request_parameters(dr, billing_settings.secret_key)

            response_code = request.get('ResponseCode', None)
            response_message = request.get('ResponseMessage', 'There was no response from the billing system.')

            group = self.session.get('participant_group')
            group.transaction_response_id = str(request.get('PaymentID'))
            group.transaction_response_code = str(response_code)
            group.transaction_response_message = response_message
            group.transaction_response_type = TRANSACTION_TYPE_EBS
            group.transaction_response_amount = request.get('Amount', '0')
            group.transaction_response = str(request)
            group.transaction_response_object = db.Blob(dumps(request))
            group.when_transaction_response_occurred = request.get('DateCreated')
            group.put()

            if response_code == 0:
                # mark the participant group as paid.
                message_title = 'Thank you for participating in the summit'
                group_id = group.key().id()
                logging.info('Payments for group: %s with %d processed.' % (group.title, group_id))

                participants = self.session.get('participants')
                if participants:
                    # Send email to all the participants about their attendance.
                    for participant in participants:
                        queue_mail_task(url='/worker/mail/thanks/registration/',
                            params=dict(
                                full_name=participant.full_name,
                                email = participant.email,
                                key=str(participant.key())
                            ),
                            method='POST'
                        )
                    # Send email to the payer the invoice.
                    primary_participant = self.session.get('primary_participant')
                    queue_mail_task(url='/worker/mail/thanks/registration_payment/',
                        params=dict(
                            full_name=primary_participant.full_name,
                            email = primary_participant.email,
                            key=str(primary_participant.key()),
                            transaction_amount=group.transaction_response_amount
                        ),
                        method='POST'
                    )
            else:
                message_title = 'There was an error processing your payment.'
            response = render_template('thank_you.html', message_title=message_title, message_body=response_message + ''' Thank you for registering for the summit. An email confirming your payment and registration shall be sent to you shortly. In case you don't receive the email confirmation within 24 hours or you have any queries, please contact +91 22 66301060 / 22026166 from 10.30 AM IST to 6.30 AM IST''')
        else:
            response = render_template('thank_you.html', message_title="A problem occurred with the billing system.", message_body="We did not receive a proper response from the billing system.")

        self.response.out.write(response)
Esempio n. 11
0
def generate_local_dockerfile():
    loginfo('Generating local Dockerfile ...')
    context = {
        'seafile_version': seafile_version,
        'https': is_https(),
        'domain': get_conf('server.domain'),
    }
    render_template('/templates/Dockerfile.template', join(generated_dir, 'Dockerfile'), context)
Esempio n. 12
0
 def GET(self, key):
     if not web.ctx.site.can_write(key):
         return render_template("permission_denied", web.ctx.fullpath, "Permission denied to edit " + key + ".")
     
     author = web.ctx.site.get(key)
     if author is None:
         raise web.notfound()
     return render_template("type/author/edit", author)
Esempio n. 13
0
    def GET(self, key):
        if not web.ctx.site.can_write(key):
            return render_template("permission_denied", web.ctx.fullpath, "Permission denied to edit " + key + ".")

        author = web.ctx.site.get(key)
        if author is None:
            raise web.notfound()
        return render_template("type/author/edit", author)
Esempio n. 14
0
def token_login_index(request, token):
   request.session.flush()
   api = get_api()

   reqstore = request.GET
   if (request.method == 'POST'): reqstore = request.POST
    
   initial_app= reqstore.get('initial_app', "")

   options = {'data': {'token':token}}
   pin= reqstore.get('pin', "")   
   if pin: 
     options['data']['pin'] = pin

   logintokenxml =   api.call("GET", "/session/from_direct_url", 
                              options=options)

   if logintokenxml.startswith("Permission Denied"):
     return utils.render_template("ui/need_pin",{})

   logintoken= ET.fromstring(logintokenxml) 
   record_id = logintoken.find("Record").get("id")
   record_name = logintoken.find("Record").get("label")

   session_tokens = dict(urlparse.parse_qsl(logintoken.get("value")))
   account_id = session_tokens['account_id']
   request.session['oauth_token_set'] = session_tokens
   request.session['account_id'] = urllib.unquote(account_id)

   api = get_api(request)
   account_id = urllib.unquote(request.session['oauth_token_set']['account_id'])
   ret = api.account_info(account_id = account_id)

   e = ET.fromstring(ret.response['response_data'])
   fullname = e.findtext('givenName') +" "+ e.findtext('familyName')

   target_template = "ui/proxy_index"


   credentials = "''"
   manifest = "''"

   if (initial_app != ""):
     target_template = "ui/single_app_view"
     credentials = single_app_get_credentials(api, account_id, initial_app, record_id)
     manifest = single_app_get_manifest(api, initial_app)

   return utils.render_template(target_template,
         { 
         'ACCOUNT_ID': session_tokens["account_id"],
         'FULLNAME': fullname,
         'PROXIED_RECORD_ID' : record_id,
         'PROXIED_RECORD_NAME': record_name,
         'INITIAL_APP': initial_app,
         'SMART_PASSTHROUGH_SERVER': passthrough_server ,
         'CREDENTIALS': credentials,
         'MANIFEST': manifest 
         })
def launch_app(request, app_id):
    """ Entry point for a given app.

    If the app does not exist (or another exception occurrs), will render /ui/error with the given error message. On
    success, renders /ui/record_select after the user has logged in. Selecting a record will call the app's start_url.
    
    """
    
    # make the user login first
    login_url = "%s?return_url=%s" % (reverse(login), urllib.quote(request.get_full_path()))
    account_id = urllib.unquote(request.session.get('account_id', ''))
    if not account_id:
        return HttpResponseRedirect(login_url)
    
    # logged in, get information about the desired app
    api = get_api()         # gets the API with chrome credentials
    ret = api.get_app_info(app_id=app_id)
    res = ret.response if ret else {}
    status = res.get('response_status', 500)
    
    error_message = None
    if 404 == status:
        error_message = ErrorStr('No such App').str()
    elif 200 != status:
        error_message = ErrorStr(res.get('response_data', 'Error getting app info')).str()
    
    if error_message is not None:
        return utils.render_template('ui/error', {'error_message': error_message, 'error_status': status})
    
    # success, find start URL template
    xml = res.get('response_data', '<root />')
    e = ET.fromstring(xml)
    start_url = e.findtext('startURLTemplate')
    
    # read account records
    api.update_token(request.session.get('oauth_token_set'))        # must be in app-credential-mode now
    ret = api.read_records(account_id = account_id)
    res = ret.response if ret else {}
    status = res.get('response_status', 500)
    
    if 404 == status:
        error_message = ErrorStr('Unknown account').str()
    elif 403 == status:
        return HttpResponseRedirect(login_url)
    elif 200 != status:
        error_message = ErrorStr(res.get('response_data', 'Error getting account records')).str()
    if error_message:
        return utils.render_template('ui/error', {'error_message': error_message, 'error_status': status})
    
    # parse records XML
    records_xml = res.get('response_data', '<root/>')
    records_extracted = [[r.get('id'), r.get('label')] for r in ET.fromstring(records_xml).findall('Record')]
    records = []
    for rec_id, rec_label in records_extracted:
        rec_dict = { 'record_id': rec_id, 'carenet_id' : '' }           # TODO: Carenets are not yet supported
        records.append([rec_id, rec_label, _interpolate_url_template(start_url, rec_dict)])
    
    return utils.render_template('ui/record_select', {'SETTINGS': settings, 'APP_ID': app_id, 'RECORD_LIST': records})
Esempio n. 16
0
def generate_local_nginx_conf():
    # Now create the final nginx configuratin
    domain = get_conf('server.hostname')
    context = {
        'https': is_https(),
        'domain': domain,
    }
    render_template('/templates/seafile.nginx.conf.template',
                    '/etc/nginx/sites-enabled/seafile.nginx.conf', context)
Esempio n. 17
0
def generate_local_nginx_conf():
    # Now create the final nginx configuratin
    domain = get_conf('SEAFILE_SERVER_HOSTNAME', 'seafile.example.com')
    context = {
        'https': is_https(),
        'domain': domain,
    }
    render_template('/templates/seafile.nginx.conf.template',
                    '/etc/nginx/sites-enabled/seafile.nginx.conf', context)
Esempio n. 18
0
 def get(self):
     project_json = map(lambda x: x.as_json(include_relationships=True), self.auth.user.projects)
     task_json = map(lambda x: x.as_json(), self.auth.user.tasks);
     params = {
         'courses': self.auth.user.courses,
         'project_json': project_json,
         'task_json': task_json
     }
     render_template(self, 'home.html', params)
Esempio n. 19
0
    def GET(self):

        if not self.has_permission():
            return render_template("permission_denied", "/books/add", "Permission denied to add a book to Open Library.")

        i = web.input(work=None, author=None)
        work = i.work and web.ctx.site.get(i.work)
        author = i.author and web.ctx.site.get(i.author)

        return render_template('books/add', work=work, author=author, recaptcha=get_recaptcha())
Esempio n. 20
0
    def GET(self):

        if not self.has_permission():
            return render_template("permission_denied", "/books/add", "Permission denied to add a book to Open Library.")

        i = web.input(work=None, author=None)
        work = i.work and web.ctx.site.get(i.work)
        author = i.author and web.ctx.site.get(i.author)

        return render_template('books/add', work=work, author=author, recaptcha=get_recaptcha())
Esempio n. 21
0
	def get(self, mode):
		tweets = models.Tweet.all().order('-created_at').fetch(10)
		template_values = {
			"tweets": tweets,
			"searchterm": self.request.get("q")
		}
		if mode == "panel":
			utils.render_template(self, "views/panel.html", template_values)
		else:
			utils.render_template(self, "views/live.html", template_values)
    def consume(self, client, frame):
        ''' Consumes a frame from the queue '''
        try:
            # get configuration
            mail_host = self.config['mail']['host']

            # get parameters
            params = json.loads(frame.body.decode())
            self.logger.debug(params)

            # call submit method of flask application
            # generates output file and
            self.logger.debug('processing input file: ' + params['file_id'])
            self.process_file(params['file_id'], params['model_version'])
            self.logger.debug('finished processing input file: ' + params['file_id'])

            # send user results
            self.logger.debug('sending results email to user')
            send_mail(
                host=mail_host,
                sender='SOCcer<*****@*****.**>',
                recipient=params['recipient'],
                subject='SOCcer - Your file has been processed',
                contents=render_template('templates/user_email.html', params)
            )

        except Exception as e:
            # capture error information
            error_info = {
                'file_id': params['file_id'],
                'params': json.dumps(params, indent=4),
                'exception_info': format_exc(),
                'process_output': getattr(e, 'output', 'None')
            }
            self.logger.exception(error_info)

            # send user error email
            self.logger.debug('sending error email to user')
            send_mail(
                host=mail_host,
                sender='SOCcer<*****@*****.**>',
                recipient=params['recipient'],
                subject='SOCcer - An error occurred while processing your file',
                contents=render_template('templates/user_error_email.html', params)
            )

            # send admin error email
            self.logger.debug('sending error email to administrator')
            send_mail(
                host=mail_host,
                sender='SOCcer<*****@*****.**>',
                recipient=self.config['mail']['admin'],
                subject='SOCcer - Exception occurred',
                contents=render_template('templates/admin_error_email.html', error_info)
            )
Esempio n. 23
0
def render_kube_services(config):
    """overwrite config['kubelables'] if want to change node type for certain services"""
    """prepare /etc/kubernetes/kubelet.service for nodes by roles"""
    utils.render_template_directory("./services/", "./deploy/services/",
                                    config)
    config['labels'] = ["{{cnf['labels'] | join(',')}}"]
    for role in ["infra", "worker"]:
        utils.render_template(
            "template/cloud-config/{}.kubelet.service.template".format(role),
            "./deploy/cloud-config/{}.kubelet.service.template".format(role),
            config)
Esempio n. 24
0
def render_restfulapi(config):
    if not os.path.exists("./deploy/RestfulAPI"):
        os.system("mkdir -p ./deploy/RestfulAPI")
    config = get_stat_of_sku(config)
    utils.render_template("./template/RestfulAPI/config.yaml",
                          "./deploy/RestfulAPI/config.yaml", config)
    utils.render_template("./template/master/restapi-kubeconfig.yaml",
                          "./deploy/master/restapi-kubeconfig.yaml", config)
    config["restapi"] = "http://{}:{}".format(
        config["kubernetes_master_node"][0], config["restfulapiport"])
    return config
Esempio n. 25
0
 def POST(self):
     i = web.input(email='', irl='', comment='')
     fields = web.storage({
         'email': i.email,
         'irl': i.irl,
         'comment': i.comment,
         'sent': datetime.datetime.utcnow(),
     })
     msg = render_template('email/spam_report', fields)
     web.sendmail(config.from_address, config.report_spam_address, 'Open Library spam report', str(msg))
     return render_template("contact/spam/sent")
Esempio n. 26
0
    def GET(self, key):
        i = web.input(v=None)
        v = i.v and safeint(i.v, None)

        if not web.ctx.site.can_write(key):
            return render_template("permission_denied", web.ctx.fullpath,
                                   "Permission denied to edit " + key + ".")

        edition = web.ctx.site.get(key, v)
        if edition is None:
            raise web.notfound()

        work = edition.works and edition.works[0]

        if not work:
            # HACK: create dummy work when work is not available to make edit form work
            work = web.ctx.site.new(
                '', {
                    'key':
                    '',
                    'type': {
                        'key': '/type/work'
                    },
                    'title':
                    edition.title,
                    'authors': [{
                        'type': '/type/author_role',
                        'author': {
                            'key': a['key']
                        }
                    } for a in edition.get('authors', [])]
                })

        recap_plugin_active = is_plugin_enabled('recaptcha')

        #check to see if account is more than two years old
        old_user = False
        user = web.ctx.site.get_user()
        account = user and user.get_account()
        if account:
            create_dt = account.creation_time()
            now_dt = datetime.datetime.utcnow()
            delta = now_dt - create_dt
            if delta.days > 365 * 2:
                old_user = True

        if recap_plugin_active and not old_user:
            public_key = config.plugin_recaptcha.public_key
            private_key = config.plugin_recaptcha.private_key
            recap = recaptcha.Recaptcha(public_key, private_key)
        else:
            recap = None

        return render_template('books/edit', work, edition, recaptcha=recap)
Esempio n. 27
0
    def GET(self, key):
        i = web.input(v=None, _method="GET")
        v = i.v and safeint(i.v, None)
        
        if not web.ctx.site.can_write(key):
            return render_template("permission_denied", web.ctx.fullpath, "Permission denied to edit " + key + ".")
        
        work = web.ctx.site.get(key, v)
        if work is None:
            raise web.notfound()

        return render_template('books/edit', work)
Esempio n. 28
0
    def GET(self, key):
        i = web.input(v=None, _method="GET")
        v = i.v and safeint(i.v, None)

        if not web.ctx.site.can_write(key):
            return render_template("permission_denied", web.ctx.fullpath, "Permission denied to edit " + key + ".")

        work = web.ctx.site.get(key, v)
        if work is None:
            raise web.notfound()

        return render_template('books/edit', work, recaptcha=get_recaptcha())
Esempio n. 29
0
 def POST(self):
     data = web.input()
     print(data)
     param = {'username': data.username, 'password': data.password}
     ret = utils.db.users.find(param)
     print(ret.count())
     flag = True if ret.count() > 0 else False
     print(flag)
     if flag:
         return utils.render_template('main.html', msg=u'密码正确', **data)
     else:
         return utils.render_template('login.html', msg=u'密码错误', **data)
Esempio n. 30
0
 def POST(self):
     data = web.input()
     print(data)
     param = {'username':data.username,'password':data.password}
     ret = utils.db.users.find(param)
     print(ret.count())
     flag = True if ret.count()>0 else False 
     print(flag)
     if flag:
         return utils.render_template('main.html',msg=u'密码正确',**data)
     else:
         return utils.render_template('login.html',msg=u'密码错误',**data)
Esempio n. 31
0
 def POST(self):
     i = web.input(email='', irl='', comment='')
     fields = web.storage({
         'email': i.email,
         'irl': i.irl,
         'comment': i.comment,
         'sent': datetime.datetime.utcnow(),
         'browser': web.ctx.env.get('HTTP_USER_AGENT', '')
     })
     msg = render_template('email/spam_report', fields)
     web.sendmail(i.email, config.report_spam_address, msg.subject, str(msg))
     return render_template("contact/spam/sent")
Esempio n. 32
0
def generate_local_nginx_conf():
    # Now create the final nginx configuratin
    domain = get_conf('server.hostname')
    context = {
        'https': is_https(),
        'domain': domain,
    }
    render_template(
        '/templates/seafile.nginx.conf.template',
        join(generated_dir, 'seafile.nginx.conf'),
        context
    )
Esempio n. 33
0
  def get(self, uid):
	users = models.User.all().order('-tweetcount')
	user = models.User.get_by_key_name("u_" + uid)
	tweets = models.Tweet.get(user.tweetlist)
	details = utils.get_user_details(user)
	template_values = {
		"users": users,
		"user": user,
		"tweets": tweets,
		"details": details
	}
	utils.render_template(self, "views/person.html", template_values)
def update_ecs_service(airflow_service):
    aws_account_id = get_aws_account_id()
    ecs_service = render_template(
        '{{ serviceName }}-{{ ENVIRONMENT }}-{airflow_service}').format(
            airflow_service=airflow_service)
    ecs_cluster = render_template(
        'arn:aws:ecs:{{ AWS_REGION }}:{aws_account_id}:cluster/{{ serviceName }}-{{ ENVIRONMENT }}-ecs-cluster'
    ).format(aws_account_id=aws_account_id)
    logging.info(f'RESTARTING SERVICE: {ecs_service}')
    ecs_client.update_service(cluster=ecs_cluster,
                              service=ecs_service,
                              forceNewDeployment=True)
Esempio n. 35
0
def login(request, info="", template=LOGIN_PAGE):
    """
  clear tokens in session, show a login form, get tokens from indivo_server, then redirect to index
  FIXME: make note that account will be disabled after 3 failed logins!!!
  """
    # generate a new session
    request.session.flush()

    # set up the template
    errors = {
        'missing':
        'Either the username or password is missing. Please try again',
        'incorrect': 'Incorrect username or password.  Please try again.',
        'disabled': 'This account has been disabled/locked.'
    }

    FORM_USERNAME = '******'
    FORM_PASSWORD = '******'
    FORM_RETURN_URL = 'return_url'

    # process form vars
    if request.method == HTTP_METHOD_GET:
        return_url = request.GET.get(FORM_RETURN_URL, '/')
        if (return_url.strip() == ""): return_url = '/'
        template_data = {FORM_RETURN_URL: return_url}

        return utils.render_template(template, template_data)

    if request.method == HTTP_METHOD_POST:
        return_url = request.POST.get(FORM_RETURN_URL, '/')
        if (return_url.strip() == ""): return_url = '/'
        if request.POST.has_key(FORM_USERNAME) and request.POST.has_key(
                FORM_PASSWORD):
            username = request.POST[FORM_USERNAME]
            password = request.POST[FORM_PASSWORD]
        else:
            # Also checked initially in js
            return utils.render_template(template, {
                'error': errors['missing'],
                FORM_RETURN_URL: return_url
            })
    else:
        utils.log('error: bad http request method in login. redirecting to /')
        return HttpResponseRedirect('/')

    # get tokens from the backend server and save in this user's django session
    ret = tokens_get_from_server(request, username, password)
    if not ret:
        return utils.render_template(LOGIN_PAGE, {
            'error': errors['incorrect'],
            FORM_RETURN_URL: return_url
        })
    return HttpResponseRedirect(return_url)
Esempio n. 36
0
def render_template_or_dir(config, args):
    nargs = args.nargs
    # no destination, then mirror one in ./deploy folder
    src = nargs[0]
    if len(nargs) == 1:
        dst = os.path.join("deploy", src.split("template/")[1])
    else:
        dst = nargs[1]
    if os.path.isdir(src):
        utils.render_template_directory(src, dst, config)
    else:
        utils.render_template(src, dst, config)
Esempio n. 37
0
    def POST(self):
        i = web.input(title="", author_name="", author_key="", publisher="", publish_date="", id_name="", id_value="", _test="false")

        if spamcheck.is_spam(i):
            return render_template("message.html",
                "Oops",
                'Something went wrong. Please try again later.')

        if not web.ctx.site.get_user():
            recap = get_recaptcha()
            if recap and not recap.validate():
                return render_template('message.html',
                    'Recaptcha solution was incorrect',
                    'Please <a href="javascript:history.back()">go back</a> and try again.'
                )

        match = self.find_matches(i)

        saveutil = DocSaveHelper()

        if i.author_key == '__new__':
            if i._test != 'true':
                a = new_doc('/type/author', name=i.author_name)
                comment = utils.get_message('comment_new_author')
                # Save, but don't commit, new author.
                # It will be committed when the Edition is created below.
                saveutil.save(a)
                i.author_key = a.key
            # since new author is created it must be a new record
            match = None

        if i._test == 'true' and not isinstance(match, list):
            if match:
                return 'Matched <a href="%s">%s</a>' % (match.key, match.key)
            else:
                return 'No match found'

        if isinstance(match, list):
            # multiple matches
            return render_template('books/check', i, match)

        elif match and match.key.startswith('/books'):
            # work match and edition match, match is an Edition
            return self.work_edition_match(match)

        elif match and match.key.startswith('/works'):
            # work match but not edition
            work = match
            return self.work_match(saveutil, work, i)
        else:
            # no match
            return self.no_match(saveutil, i)
Esempio n. 38
0
def render_for_worker_generic(config, args):
    # TODO: split into generic + specific node for options.env and worker-kubeconfig.yaml
    config["etcd_endpoints"] = "$ETCD_ENDPOINTS"
    orig_api_servers = config["api_servers"] if "api_servers" in config else ''
    config["api_servers"] = "$KUBE_API_SERVER"
    utils.render_template_directory("template/kubelet", "deploy/kubelet",
                                    config)
    utils.render_template("template/cloud-config/worker.upgrade.list",
                          "./deploy/cloud-config/worker.upgrade.list", config)
    utils.render_template("template/cloud-config/worker_fallback.sh.template",
                          "./deploy/cloud-config/worker_fallback.sh", config)
    if orig_api_servers:
        config["api_servers"] = orig_api_servers
Esempio n. 39
0
def showcase_index(request):
   api = get_api()

   initial_app= request.GET.get('initial_app', "")

   ret = tokens_get_from_server(request, settings.PROXY_USER, settings.PROXY_PASSWORD)
   if not ret:
     return utils.render_template(LOGIN_PAGE, {'error': 'Could not find proxied user'})

   return utils.render_template('ui/showcase',
          { 'ACCOUNT_ID': settings.PROXY_USER,
            'INITIAL_APP': initial_app,
            'SMART_PASSTHROUGH_SERVER': passthrough_server })
Esempio n. 40
0
def generate_local_nginx_conf():
    custom = get_conf('SEAFILE_SERVER_NGINX_CONF_CUSTOM', 'false')

    if custom:
        return

    # Now create the final nginx configuration
    domain = get_conf('SEAFILE_SERVER_HOSTNAME', 'seafile.example.com')
    context = {
        'https': is_https(),
        'domain': domain,
    }
    render_template('/templates/seafile.nginx.conf.template',
                    '/etc/nginx/sites-enabled/seafile.nginx.conf', context)
Esempio n. 41
0
 def __call__(self, ctx, mgr):
   source = resolve(self.source, ctx)
   dest = resolve(self.dest, ctx)
   if self.mode:
     ldest = '_%s'%source
     render_template(source, ldest, ctx)
     put(ldest, ldest)
     run('sudo mv %s %s'%(ldest, dest))
     run('sudo chmod %s %s'%(self.mode, dest))
     if self.owner:
       run('sudo chown %s %s'%(self.owner, dest))
     local('rm -f %s'%ldest)
   else:
     render_template(source, dest, ctx)
Esempio n. 42
0
 def get(self):
     course = self.params.course
     projects = self.auth.user.projects_for_course(course)
     project_json = map(lambda p: p.as_json(include_relationships=True),
                        projects)
     tasks = self.auth.user.tasks_for_course(course)
     task_json = map(lambda t: t.as_json(), tasks)
     params = {
         'course': course,
         'project_json': project_json,
         'course_key': course.key.urlsafe(),
         'task_json': task_json
     }
     render_template(self, 'course.html', params)
Esempio n. 43
0
    def POST(self):
        i = web.input(title="",
                      author_name="",
                      author_key="",
                      publisher="",
                      publish_date="",
                      id_name="",
                      id_value="",
                      _test="false")

        if spamcheck.is_spam(i):
            return render_template(
                "message.html", "Oops",
                'Something went wrong. Please try again later.')

        recap_plugin_active = is_plugin_enabled('recaptcha')
        if recap_plugin_active and not web.ctx.site.get_user():
            public_key = config.plugin_recaptcha.public_key
            private_key = config.plugin_recaptcha.private_key
            recap = recaptcha.Recaptcha(public_key, private_key)

            if not recap.validate():
                return 'Recaptcha solution was incorrect. Please <a href="javascript:history.back()">go back</a> and try again.'

        saveutil = DocSaveHelper()

        match = self.find_matches(saveutil, i)

        if i._test == "true" and not isinstance(match, list):
            if match:
                return 'Matched <a href="%s">%s</a>' % (match.key, match.key)
            else:
                return 'No match found'

        if isinstance(match, list):
            # multiple matches
            return render_template("books/check", i, match)

        elif match and match.key.startswith('/books'):
            # work match and edition match
            return self.work_edition_match(match)

        elif match and match.key.startswith('/works'):
            # work match but not edition
            work = match
            return self.work_match(saveutil, work, i)
        else:
            # no match
            return self.no_match(saveutil, i)
Esempio n. 44
0
def render_storagemanager(config, nodename):
    deploy_path = "./deploy/StorageManager/{}_storage_manager.yaml".format(
        nodename)
    utils.render_template("./template/StorageManager/config.yaml", deploy_path,
                          config)
    with open("./deploy/cloud-config/file_map.yaml") as rf:
        file_map = yaml.safe_load(rf)
        file_map["{}_storage_manager".format(nodename)] = [{
            "src":
            deploy_path,
            "dst":
            "/etc/StorageManager/config.yaml"
        }]
    with open("./deploy/cloud-config/file_map.yaml", "w") as wf:
        yaml.dump(file_map, wf)
Esempio n. 45
0
def generate_local_nginx_conf():
    # Now create the final nginx configuratin
    domain = get_conf('SEAFILE_SERVER_HOSTNAME', 'seafile.example.com')
    context = {
        'https': is_https(),
        'domain': domain,
    }

    if not os.path.isfile('/shared/nginx/conf/seafile.nginx.conf'):
        render_template('/templates/seafile.nginx.conf.template',
                        '/etc/nginx/sites-enabled/seafile.nginx.conf', context)
        nginx_etc_file = '/etc/nginx/sites-enabled/seafile.nginx.conf'
        nginx_shared_file = '/shared/nginx/conf/seafile.nginx.conf'
        call('mv {0} {1} && ln -sf {1} {0}'.format(nginx_etc_file,
                                                   nginx_shared_file))
Esempio n. 46
0
def change_password(request):
  if request.method == HTTP_METHOD_POST:
    account_id = request.POST['account_id']
    old_password = request.POST['oldpw']
    password = request.POST['pw1']
    errors = {'generic': 'There was a problem updating your password. Please try again. If you are unable to set up your account please contact support.'}
    api = get_api(request)
    ret = api.account_change_password(account_id = account_id, data={'old':old_password, 'new':password})
    if ret.response['response_status'] == 200:
      return utils.render_template('ui/change_password_success', {})
    else:
      return utils.render_template('ui/change_password', {'ERROR': errors['generic'], 'ACCOUNT_ID': account_id})
  else:
    account_id = urllib.unquote(request.session['oauth_token_set']['account_id'])
    return utils.render_template('ui/change_password', {'ACCOUNT_ID': account_id})
Esempio n. 47
0
    def GET(self, key):
        i = web.input(v=None)
        v = i.v and safeint(i.v, None)

        if not web.ctx.site.can_write(key):
            return render_template("permission_denied", web.ctx.fullpath, "Permission denied to edit " + key + ".")
                    
        edition = web.ctx.site.get(key, v)
        if edition is None:
            raise web.notfound()
            
        work = edition.works and edition.works[0]
        # HACK: create dummy work when work is not available to make edit form work
        work = work or web.ctx.site.new('', {'key': '', 'type': {'key': '/type/work'}, 'title': edition.title})
        return render_template('books/edit', work, edition)
Esempio n. 48
0
    def get(self):
        auth_level = self.is_user_authorized()
        if auth_level == models.AUTH_LEVEL_REGISTERED_USER:
            self.redirect("/account/activate/reminder/")
        elif auth_level == models.AUTH_LEVEL_ACTIVATED_USER:
            from datetime import datetime

            today = datetime.utcnow()

            training_announcements = TrainingProgram.get_all_approved_for_month(today.year, today.month)
            response = render_template("training_announcements.html", training_announcements=training_announcements)
            self.response.out.write(response)
        else:
            response = render_template("index.html")
            self.response.out.write(response)
Esempio n. 49
0
    def POST(self):
        i = web.input(title="",
                      publisher="",
                      publish_date="",
                      id_name="",
                      id_value="",
                      _test="false")

        if spamcheck.is_spam(i):
            return render_template(
                "message.html", "Oops",
                'Something went wrong. Please try again later.')

        if not web.ctx.site.get_user():
            recap = get_recaptcha()
            if recap and not recap.validate():
                return render_template(
                    'message.html', 'Recaptcha solution was incorrect',
                    'Please <a href="javascript:history.back()">go back</a> and try again.'
                )

        i = utils.unflatten(i)
        saveutil = DocSaveHelper()
        created_author = saveutil.create_authors_from_form_data(
            i.authors, i.author_names, _test=i._test == 'true')
        match = None if created_author else self.find_matches(i)

        if i._test == 'true' and not isinstance(match, list):
            if match:
                return 'Matched <a href="%s">%s</a>' % (match.key, match.key)
            else:
                return 'No match found'

        if isinstance(match, list):
            # multiple matches
            return render_template('books/check', i, match)

        elif match and match.key.startswith('/books'):
            # work match and edition match, match is an Edition
            return self.work_edition_match(match)

        elif match and match.key.startswith('/works'):
            # work match but not edition
            work = match
            return self.work_match(saveutil, work, i)
        else:
            # no match
            return self.no_match(saveutil, i)
Esempio n. 50
0
def remote_config_update(config, args, check_module=False):
    '''
    client end(infra/NFS node) config file update
    ./ctl.py -s svc configupdate restfulapi
    ./ctl.py [-r storage_machine1 [-r storage_machine2]] -s svc configupdate storage_manager
    by default sudo
    '''
    if check_module:
        assert set(args.nargs[1:]) - set([
            "restfulapi", "storagemanager", "repairmanager", "dashboard"
        ]) == set(), "not supported"
    # need to get node list for this subcommand of svc, so load status.yaml
    if not os.path.exists(FILE_MAP_PATH):
        utils.render_template("template/cloud-config/file_map.yaml",
                              FILE_MAP_PATH, config)
    with open(FILE_MAP_PATH) as f:
        file_map = yaml.load(f)
    for module in args.nargs[1:]:
        if module == "jobmanager":
            module = "restfulapi"
        if module in ["restfulapi", "dashboard", "repairmanager"]:
            render_func = eval("render_{}".format(module))
            render_func(config)
            infra_nodes, _ = load_node_list_by_role_from_config(
                config, ["infra"], False)
            for file_pair in file_map[module]:
                src_dst_list = [file_pair["src"], file_pair["dst"]]
                execute_in_parallel(config,
                                    infra_nodes,
                                    src_dst_list,
                                    True,
                                    copy2_wrapper,
                                    noSupressWarning=args.verbose)
        elif module == "storagemanager":
            nfs_nodes, _ = load_node_list_by_role_from_config(
                config, ["nfs"], False)
            for node in nfs_nodes:
                config["storage_manager"] = config["machines"][node][
                    "storage_manager"]
                render_storagemanager(config, node)
                src_dst_list = [
                    "./deploy/StorageManager/{}_storage_manager.yaml".format(
                        node), "/etc/StorageManager/config.yaml"
                ]
                args_list = (config["machines"][node]["fqdns"],
                             config["ssh_cert"], config["admin_username"],
                             src_dst_list, True, args.verbose)
                copy2_wrapper(args_list)
Esempio n. 51
0
   def get(self, path):
      """Handle GET request on static blog content. Only get the
      static content and pass it to 'output_content'."""

      if not path.startswith(config.url_prefix):
         # Query does not start with prefix. It is OK if it should
         # be so, like for robots, else that's a 404 error.
         if path not in ROOT_ONLY_FILES:
            self.error(404)
            self.response.out.write(utils.render_template('404.html'))
            return
      else:
         # Query starts with prefix.
         if config.url_prefix != '':
            # Strip it off.
            path = path[len(config.url_prefix):]
            if path in ROOT_ONLY_FILES: # This lives at root
               self.error(404)
               self.response.out.write(utils.render_template('404.html'))
               return

      # Retrive the 'StaticContent' object from datastore or memcache.
      content = get(path)
      if not content:
         self.error(404)
         self.response.out.write(utils.render_template('404.html'))
         return

      # Ready to serve...
      serve = True

      # ... but first check If-Modified-Since and If-None-Match HTTP
      # headers (that are used for serving only if content has changed).
      if 'If-Modified-Since' in self.request.headers:
         try:
            last_seen = datetime.datetime.strptime(
                # IE8 '; length=XXXX' as extra arg bug
                self.request.headers['If-Modified-Since'].split(';')[0],
                HTTP_DATE_FMT
            )
            if last_seen >= content.last_modified.replace(microsecond=0):
               serve = False
         except ValueError, e:
            import logging
            logging.error(
                'StaticContentHandler in static.py, ValueError: ' + \
                self.request.headers['If-Modified-Since']
            )
Esempio n. 52
0
def init_letsencrypt():
    loginfo('Preparing for letsencrypt ...')
    wait_for_nginx()

    if not exists(ssl_dir):
        os.mkdir(ssl_dir)

    domain = get_conf('SEAFILE_SERVER_HOSTNAME', 'seafile.example.com')
    context = {
        'ssl_dir': ssl_dir,
        'domain': domain,
    }
    render_template('/templates/letsencrypt.cron.template',
                    join(generated_dir, 'letsencrypt.cron'), context)

    ssl_crt = '/shared/ssl/{}.crt'.format(domain)
    if exists(ssl_crt):
        loginfo('Found existing cert file {}'.format(ssl_crt))
        if cert_has_valid_days(ssl_crt, 30):
            loginfo(
                'Skip letsencrypt verification since we have a valid certificate'
            )
            if exists(join(ssl_dir, 'letsencrypt')):
                # Create a crontab to auto renew the cert for letsencrypt.
                call('/scripts/auto_renew_crt.sh {0} {1}'.format(
                    ssl_dir, domain))
            return

    loginfo('Starting letsencrypt verification')
    # Create a temporary nginx conf to start a server, which would accessed by letsencrypt
    context = {
        'https': False,
        'domain': domain,
    }
    if not os.path.isfile('/shared/nginx/conf/seafile.nginx.conf'):
        render_template('/templates/seafile.nginx.conf.template',
                        '/etc/nginx/sites-enabled/seafile.nginx.conf', context)

    call('nginx -s reload')
    time.sleep(2)

    call('/scripts/ssl.sh {0} {1}'.format(ssl_dir, domain))
    # if call('/scripts/ssl.sh {0} {1}'.format(ssl_dir, domain), check_call=False) != 0:
    #     eprint('Now waiting 1000s for postmortem')
    #     time.sleep(1000)
    #     sys.exit(1)

    call('/scripts/auto_renew_crt.sh {0} {1}'.format(ssl_dir, domain))
Esempio n. 53
0
    def POST(self):
        i = web.input(title="", author_name="", author_key="", publisher="", publish_date="", id_name="", id_value="", _test="false")
        
        saveutil = DocSaveHelper()
        
        match = self.find_matches(saveutil, i)

        if i._test == "true" and not isinstance(match, list):
            if match:
                return 'Matched <a href="%s">%s</a>' % (match.key, match.key)
            else:
                return 'No match found'
        
        if isinstance(match, list):
            # multiple matches
            return render_template("books/check", i, match)

        elif match and match.key.startswith('/books'):
            # work match and edition match
            return self.work_edition_match(match)

        elif match and match.key.startswith('/works'):
            # work match but not edition
            work = match
            return self.work_match(saveutil, work, i)
        else:
            # no match
            return self.no_match(saveutil, i)
Esempio n. 54
0
    def export_xml(self):

        documents = copy.deepcopy(self.resources)
        dottable_documents = []
        for document in documents:
            document[
                "grading_criteria"] = True if document in self.grading_criteria else None
            dottable_documents.append(DottableDict(document))

        milestones = [
            DottableDict({
                "name": key,
                "mmddyy": value.strftime("%m/%d/%Y")
            }) for key, value in self.milestone_dates.iteritems()
        ]

        data = {
            "documents":
            dottable_documents,
            "milestones":
            milestones,
            "group_activity":
            self,
            "activity_component_path":
            resource_filename(__name__, 'templates/activity_component.xml')
        }

        return render_template('/templates/xml/group_activity.xml', data)
Esempio n. 55
0
    def _add_kube_proxy_windows(self):
        template_file = os.path.join(
            os.getcwd(), "cluster-api/kube-proxy/kube-proxy-windows.yaml.j2")
        server_core_tag = "windowsservercore-%s" % (
            self.opts.base_container_image_tag)
        context = {
            "kubernetes_version": self.kubernetes_version,
            "server_core_tag": server_core_tag,
            "enable_win_dsr": str(self.opts.enable_win_dsr).lower(),
            "flannel_mode": self.opts.flannel_mode
        }
        output_file = "/tmp/kube-proxy-windows.yaml"
        utils.render_template(template_file, output_file, context)

        cmd = [self.kubectl, "apply", "-f", output_file]
        utils.retry_on_error()(utils.run_shell_cmd)(cmd)
Esempio n. 56
0
def render_elasticsearch_node_specific(config, args):
    if not "elasticsearch_node" in config or len(
            config["elasticsearch_node"]) == 0:
        print(
            "Warning: no elasticsearch node specified, logging service might not work as expected."
        )
        return
    config.pop("mount_and_link", [])
    config = escaped_etcd_end_point_and_k8s_api_server(config)
    example_node_name = config["elasticsearch_node"][0].split(".")[0]
    config["kube_labels"] = get_kube_labels_of_machine_name(
        config, example_node_name)
    config["file_modules_2_copy"] = ["kubernetes_common", "kubelet_worker"]
    utils.render_template(
        "./template/cloud-config/cloud_init_worker.txt.template",
        "./deploy/cloud-config/cloud_init_elasticsearch.txt", config)
Esempio n. 57
0
def to_card_thumbnail(card_json: JsonDict) -> str:
    """Generates HTML that shows card thumbnail(s).

    Args:
        card_json (JsonDict): JSON of a Scryfall Card object.

    Returns:
        str: htmlbox code.
    """
    # img_uris ~ URI for card thumbnail(s)
    if "card_faces" in card_json and "image_uris" in card_json["card_faces"][0]:
        # Double-faced cards have 2 thumbnails, i.e. transform cards.
        img_uris = [
            face["image_uris"]["normal"] for face in card_json["card_faces"]
        ]
    elif "image_uris" in card_json:
        # Most cards have 1 thumbnail. Split cards fall under this category.
        img_uris = [card_json["image_uris"]["normal"]]
    else:
        # Fallback: image_uris isn't guaranteed to exist or be non-null but the previous
        # conditional cases should cover most cards.
        return 'Immagine per <a href="{}">{}</a> non disponibile.'.format(
            card_json["scryfall_uri"],
            card_json["name"],
        )

    return utils.render_template(
        "commands/mtg_card.html",
        img_uris=img_uris,
        scryfall_uri=card_json["scryfall_uri"],
    )
Esempio n. 58
0
  def generate_resource(cls, post, resource, pagenum=1, start_ts=None):
    import models
    q = models.BlogPost.all().order('-published')
    q.filter('published <', start_ts or datetime.datetime.max)
    cls._filter_query(resource, q)

    posts = q.fetch(config.posts_per_page + 1)
    more_posts = len(posts) > config.posts_per_page

    path_args = {
        'resource': resource,
    }
    _get_path = lambda: \
                  cls.first_page_path if path_args['pagenum'] == 1 else cls.path
    path_args['pagenum'] = pagenum - 1
    prev_page = _get_path() % path_args
    path_args['pagenum'] = pagenum + 1
    next_page = cls.path % path_args
    template_vals = {
        'generator_class': cls.__name__,
        'posts': posts[:config.posts_per_page],
        'prev_page': prev_page if pagenum > 1 else None,
        'next_page': next_page if more_posts else None,
    }
    rendered = utils.render_template("listing.html", template_vals)

    path_args['pagenum'] = pagenum
    static.set(_get_path() % path_args, rendered, config.html_mime_type)
    if more_posts:
        deferred.defer(cls.generate_resource, None, resource, pagenum + 1,
                       posts[-2].published)
Esempio n. 59
0
    def GET(self, key):
        page = web.ctx.site.get(key)

        if not page:
            raise web.notfound()

        return render_template("books/daisy", page)
Esempio n. 60
0
    def POST(self, key):
        author = web.ctx.site.get(key)
        if author is None:
            raise web.notfound()

        i = web.input(_comment=None)
        formdata = self.process_input(i)
        try:
            if not formdata:
                raise web.badrequest()
            elif "_save" in i:
                author.update(formdata)
                author._save(comment=i._comment)
                raise web.seeother(key)
            elif "_delete" in i:
                author = web.ctx.site.new(key, {
                    "key": key,
                    "type": {
                        "key": "/type/delete"
                    }
                })
                author._save(comment=i._comment)
                raise web.seeother(key)
        except (ClientException, ValidationException) as e:
            add_flash_message('error', str(e))
            author.update(formdata)
            author['comment_'] = i._comment
            return render_template("type/author/edit", author)