Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import random
- import string
- import sqlite3
- import cherrypy
- from peewee import *
- from datetime import date
- db = SqliteDatabase('Spravki.db')
- class Spravki(Model):
- number = IntegerField()
- date = DateField()
- fio = CharField()
- grant = IntegerField()
- destination = CharField()
- class Meta:
- database = db
- Spravki.create_table()
- class Table(object):
- @cherrypy.expose
- def index(self):
- html_code = """<html>
- <head>
- <meta charset="utf-8">
- <title>Tаблица</title>
- <style>
- body {{
- background-color: black;
- font-family: Comic Sans MS, cursive, sans-serif;
- }}
- h1 {{
- color: yellow;
- font-size: 200px;
- text-align: center;
- text-shadow: -10px -10px 0 red, 10px -10px 0 red, -10px 10px 0 red, 10px 10px 0 red;
- background-image: url("https://i.imgur.com/Xxj2d6c.jpg");
- background-repeat: repeat;
- background-blur: 10px;
- }}
- td, th {{
- padding: 50px;
- font-size: 50px;
- border: 30px dotted yellow;
- cursor: pointer;
- border-radius: 100px;
- box-shadow: inset 0px 0px 20px rgba(255, 0, 0, 0.75), 0px 0px 30px green, 0px 0px 50px blue;
- text-shadow: none;
- }}
- th {{
- background-color: green;
- color: red;
- }}
- tr {{
- transition: transform 10s ease-in-out, opacity 5s ease;
- }}
- tr:hover {{
- opacity: 1;
- background-color: yellow !important;
- }}
- td:hover {{
- color: blue;
- background-image: url("https://i.imgur.com/IrV8oD9.jpg");
- background-repeat: repeat;
- text-shadow: 0px 0px 30px white;
- }}
- </style>
- </head>
- <body>
- <form method="get" action="add">
- <input type="text" value="number" name="number" />
- <input type="text" value="date" name="date" />
- <input type="text" value="fio" name="fio" />
- <input type="text" value="grant" name="grant" />
- <input type="text" value="destination" name="destination" />
- <button type="submit">add to database</button>
- </form>
- <table align="center">
- <style type="text/css">
- TABLE {
- margin: auto;
- max-width: 800px;
- width: 80%;
- border-collapse: separate;
- border-spacing: 20px;
- background-color: magenta;
- opacity: 0.5;
- }
- TD, TH {
- padding: 3px;
- border: 1px solid black;
- }
- </style>
- <p align="center">Справки из деканата</p>
- <tr>
- <td align="center">number</td>
- <td align="center">date</td>
- <td align="center">fio</td>
- <td align="center">grant</td>
- <td align="center">destination</td>
- </tr>"""
- for item in Spravki.select():
- html_code += """<tr><form method="get" action="changes">
- <td><input type="text" value=" """ + str(item.number) + """"name="number" /></td>
- <td><input type="text" value=" """ + str(item.date) + """"name="date" /></td>
- <td><input type="text" value=" """ + str(item.fio) + """"name="fio" /></td>
- <td><input type="text" value=" """ + str(item.grant) + """"name="grant" /></td>
- <td><input type="text" value=" """ + str(item.destination) + """"name="destination" /></td>
- <td><input type="hidden" value=" """ + str(item.id) + """"name="id" /></td>
- <td><button type="submit">change</button></td></tr>
- </form>"""
- html_code += """</table>
- </body>
- </html>"""
- return html_code
- @cherrypy.expose
- def add(self, number="number", date="date", fio="fio", grant="grant",
- destination="destination"):
- flag = True
- for item in Spravki.select():
- if item.number == int(number):
- flag = False
- break
- if flag:
- Spravki(number=int(number), date=str(date), fio=str(fio), grant=int(grant),
- destination=str(destination)).save()
- return Table.index(self)
- @cherrypy.expose
- def changes(self, number="number", date="date", fio="fio", grant="grant",
- destination="destination", id="id"):
- Spravki(number=int(number), date=str(date), fio=str(fio), grant=int(grant),
- destination=str(destination)).update(number=number)
- for item in Spravki.select():
- if item.id == int(id):
- item.number = int(number)
- item.date = date.replace(' ', '')
- item.fio = fio.strip()
- item.grant = int(grant)
- item.destination = destination.strip()
- item.save()
- break
- return Table.index(self)
- if __name__ == '__main__':
- cherrypy.quickstart(Table())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement