Пример #1
0
def generate_files_html(self):
    files = db.GqlQuery("SELECT * "
                "FROM File "
                "WHERE ANCESTOR IS :1 ",
                Models.file_key(users.get_current_user().user_id()))

    
    html = ""
    for file in files:
        if file.file_key:
            html += """
                <tr>
                    <td>"""+str(file.upload_date)+"""</td>
                    <td>"""+file.title+"""</td>
                    <td>"""+file.description+"""</td>
                    <td><a href="/view_file/"""+str(file.file_key.key())+"""">View</a></td>
                </tr>
            """
        else:
            html += """
                <tr>
                    <td>"""+str(file.upload_date)+"""</td>
                    <td>"""+file.title+"""</td>
                    <td>"""+file.description+"""</td>
                    <td>View</td>
                </tr>
            """
    return html
Пример #2
0
    def post(self):
        self.response.out.write("added <br />")
        user = users.get_current_user()
        
        #See if the user choose to upload a payslip or other
        if self.request.POST['type'] == "payslip":

            self.response.out.write("payslip <br />")
            
            payslip = Models.Payslip(parent=Models.payslip_key(user.user_id()))
             
            #Set the model attributes 
            payslip.ownerId = user.user_id()
            payslip.beginning = datetime.datetime.strptime(self.request.POST['beginning'],'%Y-%m-%d').date()
            payslip.ending = datetime.datetime.strptime(self.request.POST['ending'],'%Y-%m-%d').date()
            payslip.income = float(self.request.POST['income'])
            payslip.tax = float(self.request.POST['tax'])
            payslip.net = float(self.request.POST['income']) - float(self.request.POST['tax'])
            payslip.company = self.request.POST['company']
            
            #Output the given form to the confirmation page
            self.response.out.write(payslip.ownerId + "<br/>" )
            self.response.out.write(str(payslip.upload_date) + "<br/>")
            self.response.out.write(str(payslip.beginning) + "<br/>")
            self.response.out.write(str(payslip.ending) + "<br/>")
            self.response.out.write(str(payslip.income) + "<br/>")
            self.response.out.write(str(payslip.tax) + "<br/>")
            self.response.out.write(str(payslip.net) + "<br/>")
            self.response.out.write(str(payslip.company) + "<br/>")
            
            #add the model to the data store
            payslip.put()                         
             
        else:
            self.response.out.write("other <br />")
            
            file = Models.File(parent=Models.file_key(user.user_id()))
            
            #Set the model attributes 
            file.ownerId = user.user_id()
            file.title = self.request.POST['title']
            file.description = self.request.POST['description']
            
            #Output the given form to the confirmation page
            self.response.out.write( file.ownerId + "<br/>" )
            self.response.out.write(file.title + "<br/>")
            self.response.out.write(file.description + "<br/>")
            
            #add the model to the data store
            file.put()
Пример #3
0
    def post(self):
        self.response.out.write("added <br />")
        user = users.get_current_user()
        
        #See if the user choose to upload a payslip or other
        if self.request.POST['type'] == "payslip":

            self.response.out.write("payslip <br />")
            
            payslip = Models.Payslip(parent=Models.payslip_key(user.user_id()))
             
            #Set the model attributes 
            payslip.ownerId = user.user_id()
            payslip.beginning = datetime.datetime.strptime(self.request.POST['beginning'],'%Y-%m-%d').date()
            payslip.ending = datetime.datetime.strptime(self.request.POST['ending'],'%Y-%m-%d').date()
            payslip.income = float(self.request.POST['income'])
            payslip.tax = float(self.request.POST['tax'])
            payslip.net = float(self.request.POST['income']) - float(self.request.POST['tax'])
            payslip.company = self.request.POST['company']
            
            # Create the file
            file_name = files.blobstore.create(mime_type='application/octet-stream')
           
            
            # Open the file and write to it
            with files.open(file_name, 'a') as f:
                f.write("data")
            
            # Finalize the file. Do this before attempting to read it.
            files.finalize(file_name)
            
            # Get the file's blob key
            payslip.file_key = files.blobstore.get_blob_key(file_name)
            
            #Output the given form to the confirmation page
            self.response.out.write(payslip.ownerId + "<br/>" )
            self.response.out.write(str(payslip.upload_date) + "<br/>")
            self.response.out.write(str(payslip.beginning) + "<br/>")
            self.response.out.write(str(payslip.ending) + "<br/>")
            self.response.out.write(str(payslip.income) + "<br/>")
            self.response.out.write(str(payslip.tax) + "<br/>")
            self.response.out.write(str(payslip.net) + "<br/>")
            self.response.out.write(str(payslip.company) + "<br/>")
            
            #add the model to the data store
            payslip.put()             
            self.redirect('/payslips')
           
             
        else:
            self.response.out.write("other <br />")
            
            file = Models.File(parent=Models.file_key(user.user_id()))
            
            #Set the model attributes 
            file.ownerId = user.user_id()
            file.title = self.request.POST['title']
            file.description = self.request.POST['description']


            form_data = cgi.FieldStorage()
            
            if form_data.getvalue('file'):
                subject = form_data.getvalue('file')
                # Create the file
                file_name = files.blobstore.create(mime_type='application/octet-stream')
                
                # Open the file and write to it
                with files.open(file_name, 'a') as f:
                    f.write(subject)
                
                # Finalize the file. Do this before attempting to read it.
                files.finalize(file_name)
                
                # Get the file's blob key
                file.file_key = files.blobstore.get_blob_key(file_name)
               
            else:
               subject = "Not set"
               
            
            #Output the given form to the confirmation page
            self.response.out.write( file.ownerId + "<br/>" )
            self.response.out.write(file.title + "<br/>")
            self.response.out.write(file.description + "<br/>")
            
            #add the model to the data store
            file.put()
            self.redirect('/files')
    def get(self):
        
        user = users.get_current_user() 
        
        if user:
            
            pasyer_users = db.GqlQuery("SELECT * "
                "FROM Site_User "
                "WHERE userid = :1 ",
                user.user_id())
            
            current_user = False
            for pasyer_user in pasyer_users:
                current_user = pasyer_user

            if not current_user:
                self.redirect("/settings")
            else:
            
                payslips = db.GqlQuery("SELECT * "
                    "FROM Payslip "
                    "WHERE ANCESTOR IS :1 ",
                    Models.payslip_key(user.user_id()))
        
                income = 0
                tax = 0
                payslip_count = 0            
                for payslip in payslips:
                    income+= payslip.income
                    tax += payslip.tax
                    payslip_count += 1
                    
                files = db.GqlQuery("SELECT * "
                    "FROM File "
                    "WHERE ANCESTOR IS :1 ",
                    Models.file_key(user.user_id()))
                file_count = 0    
                for file in files:
                    file_count += 1
                    
    
                #set stylesheets needed per page 
                specific_urls = """
                    <link type="text/css" rel="stylesheet" href="/stylesheets/""" + self.__class__.__name__ + """.css" />
                """
                
                dashboard_template_values = {
                    'name': current_user.name,
                    'email': current_user.email,
                    'account_type': current_user.account_type,
                    'payslip_quantity': payslip_count,
                    'file_quantity': file_count,
                    'income': income,
                    'tax': tax,
                    'net': income - tax
                }
                
                template = jinja_environment.get_template('Page_Content/dashboard.html')
                dashboard_template = template.render(dashboard_template_values)
                
                url = users.create_logout_url(self.request.uri)
                nav = """
                <nav>
                    <ul>
                        <li><a href="/dashboard">Dashboard</a></li>
                        <li><a href="#">Design</a></li>
                        <li><a href="#">About</a></li>
                        <li><a href="%s">Logout</a></li>
                    </ul>
                </nav>
                """ % url
               
                    
                template_values = {
                    'specific_urls':specific_urls,
                    'nav': nav,
                    'content': dashboard_template
                }
               
                template = jinja_environment.get_template('index.html')
                self.response.out.write(template.render(template_values))
        else:
            self.redirect('/')