Skip to content

Commit 896b2cf

Browse files
committed
Final demo code exported from anvil.
1 parent f5b4dd6 commit 896b2cf

21 files changed

+1182
-1
lines changed

days/85-87-full-stack-easy/demos/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package_name: pypoint100days
2+
name: pypoint-100days
3+
startup_form: HomeForm
4+
renamed: true
5+
runtime_options: {server_version: python2-sandbox}
6+
services:
7+
- source: /runtime/services/tables.yml
8+
client_config: {}
9+
server_config: {auto_create_missing_columns: false}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from anvil import *
2+
import anvil.server
3+
import tables
4+
from tables import app_tables
5+
import utilities
6+
7+
class AddDocForm (AddDocFormTemplate):
8+
def __init__(self, **properties):
9+
# You must call self.init_components() before doing anything else in this function
10+
self.init_components(**properties)
11+
12+
# Any code you write here will run when the form opens.
13+
self.drop_down_categories.items = [('select a category', None)] + [(c, c) for c in utilities.categories]
14+
self.label_errors.text = ""
15+
16+
def button_save_click (self, **event_args):
17+
errors = self.validate()
18+
if errors:
19+
self.label_errors.text = "\n".join(errors)
20+
return
21+
22+
name = self.text_box_doc_name.text.strip()
23+
category = self.drop_down_categories.selected_value
24+
contents = self.text_area_contents.text.strip()
25+
26+
utilities.create_doc(name, category, contents)
27+
utilities.go_home()
28+
29+
30+
def validate(self):
31+
self.label_errors.text = ""
32+
errors = []
33+
if not self.text_box_doc_name.text or not self.text_box_doc_name.text.strip():
34+
errors.append('Document name is required')
35+
36+
if not self.drop_down_categories.selected_value:
37+
errors.append('Document category is required')
38+
39+
if not self.text_area_contents.text or not self.text_area_contents.text.strip():
40+
errors.append('Cannot create empty documents')
41+
42+
return errors
43+
44+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
container:
2+
type: ColumnPanel
3+
properties: {col_widths: '{"JOCGQM":15,"WPNYAI":45,"GQHPEC":15,"SSLEBU":45}'}
4+
components:
5+
- type: Label
6+
properties: {role: null, width: default, align: center, border: '', foreground: '',
7+
visible: true, text: Add a new document, font_size: 28, font: '', spacing_above: small,
8+
icon_align: left, spacing_below: small, italic: false, background: '', bold: true,
9+
underline: false, icon: ''}
10+
name: label_subtitle
11+
layout_properties: {grid_position: 'IIGYZM,LRYSUF'}
12+
- type: Label
13+
properties: {role: null, width: default, align: left, border: '', foreground: '',
14+
visible: true, text: Document name, font_size: null, font: '', spacing_above: small,
15+
icon_align: left, spacing_below: small, italic: false, background: '', bold: true,
16+
underline: false, icon: ''}
17+
name: label_1
18+
layout_properties: {grid_position: 'XYEAKB,JOCGQM'}
19+
- type: TextBox
20+
properties: {role: null, width: default, align: left, hide_text: false, placeholder: document name,
21+
border: '', enabled: true, foreground: '', visible: true, text: '', font_size: null,
22+
font: '', spacing_above: small, type: text, spacing_below: small, italic: false,
23+
background: '', bold: false, underline: false}
24+
name: text_box_doc_name
25+
layout_properties: {grid_position: 'XYEAKB,WPNYAI'}
26+
- type: Label
27+
properties: {role: null, width: default, align: left, border: '', foreground: '',
28+
visible: true, text: Category, font_size: null, font: '', spacing_above: small,
29+
icon_align: left, spacing_below: small, italic: false, background: '', bold: true,
30+
underline: false, icon: ''}
31+
name: label_2
32+
layout_properties: {grid_position: 'APMKDY,GQHPEC'}
33+
- type: DropDown
34+
properties: {}
35+
name: drop_down_categories
36+
layout_properties: {grid_position: 'APMKDY,SSLEBU'}
37+
- type: Label
38+
properties: {role: null, width: default, align: left, border: '', foreground: '',
39+
visible: true, text: Contents, font_size: null, font: '', spacing_above: small,
40+
icon_align: left, spacing_below: small, italic: false, background: '', bold: true,
41+
underline: false, icon: ''}
42+
name: label_3
43+
layout_properties: {grid_position: 'KOMUDF,ESPOFP'}
44+
- type: TextArea
45+
properties: {role: null, width: default, align: left, height: 169, placeholder: Add document contents here,
46+
border: '', enabled: true, foreground: '', visible: true, text: '', font_size: null,
47+
auto_expand: false, font: '', spacing_above: small, spacing_below: small, italic: false,
48+
background: '', bold: false, underline: false}
49+
name: text_area_contents
50+
layout_properties: {grid_position: 'KSRZHC,WQFRHQ'}
51+
- type: Button
52+
properties: {role: null, width: default, align: right, border: '', enabled: true,
53+
foreground: '#fff', visible: true, text: Create document, font_size: null, font: '',
54+
spacing_above: small, icon_align: left, spacing_below: small, italic: false, background: '#367498',
55+
bold: false, underline: false, icon: 'fa:plus'}
56+
name: button_save
57+
layout_properties: {grid_position: 'USGITF,CTBUTN'}
58+
event_bindings: {click: button_save_click}
59+
- type: Label
60+
properties: {role: null, width: default, align: center, border: '', foreground: '#941100',
61+
visible: true, text: This is an error, font_size: 18, font: '', spacing_above: small,
62+
icon_align: left, spacing_below: small, italic: false, background: '', bold: true,
63+
underline: false, icon: ''}
64+
name: label_errors
65+
layout_properties: {grid_position: 'ASTSPJ,XBGAYX'}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from anvil import *
2+
import anvil.server
3+
import tables
4+
from tables import app_tables
5+
import utilities
6+
7+
class AllDocsForm (AllDocsFormTemplate):
8+
def __init__(self, **properties):
9+
# You must call self.init_components() before doing anything else in this function
10+
self.init_components(**properties)
11+
12+
# Any code you write here will run when the form opens.
13+
self.repeating_panel_docs.items = utilities.docs
14+
15+
def text_box_filter_change (self, **event_args):
16+
self.repeating_panel_docs.items = self.filtered_docs()
17+
18+
def doc_to_text(self, d):
19+
return "{} {} {}".format(d["name"], d["contents"], d["category"]["name"])
20+
21+
def filtered_docs(self):
22+
txt = self.text_box_filter.text
23+
if not txt:
24+
return utilities.docs
25+
26+
txt = txt.lower()
27+
28+
return [
29+
d
30+
for d in utilities.docs
31+
if self.doc_to_text(d).lower().find(txt) >= 0
32+
]
33+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
container:
2+
type: ColumnPanel
3+
properties: {col_widths: '{"BIBWRZ":15,"RFXBVD":45}'}
4+
components:
5+
- type: Label
6+
properties: {role: null, width: default, align: center, border: '', foreground: '',
7+
visible: true, text: All documents, font_size: 28, font: '', spacing_above: small,
8+
icon_align: left, spacing_below: small, italic: false, background: '', bold: true,
9+
underline: false, icon: ''}
10+
name: label_subtitle
11+
layout_properties: {grid_position: 'KPLHVX,HYTIAV'}
12+
- type: Label
13+
properties: {role: null, width: default, align: left, border: '', foreground: '',
14+
visible: true, text: Filter documents, font_size: null, font: '', spacing_above: small,
15+
icon_align: left, spacing_below: small, italic: false, background: '', bold: true,
16+
underline: false, icon: ''}
17+
name: label_1
18+
layout_properties: {grid_position: 'EXTWSA,BIBWRZ'}
19+
- type: TextBox
20+
properties: {role: null, width: default, align: left, hide_text: false, placeholder: Search within your documents,
21+
border: '', enabled: true, foreground: '', visible: true, text: '', font_size: null,
22+
font: '', spacing_above: small, type: text, spacing_below: small, italic: false,
23+
background: '', bold: false, underline: false}
24+
name: text_box_filter
25+
layout_properties: {grid_position: 'EXTWSA,RFXBVD'}
26+
event_bindings: {change: text_box_filter_change}
27+
- type: Spacer
28+
properties: {height: 32}
29+
name: spacer_1
30+
layout_properties: {grid_position: 'UAROCY,KOVPNC'}
31+
- type: RepeatingPanel
32+
properties: {item_template: DocListItemTemplate}
33+
name: repeating_panel_docs
34+
layout_properties: {grid_position: 'YTHURW,DKEOGM'}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from anvil import *
2+
import anvil.server
3+
import tables
4+
from tables import app_tables
5+
6+
class DocDetailsForm (DocDetailsFormTemplate):
7+
def __init__(self, **properties):
8+
# You must call self.init_components() before doing anything else in this function
9+
self.init_components(**properties)
10+
11+
# Any code you write here will run when the form opens.
12+
doc = self.item
13+
self.label_category.text = doc['category']['name']
14+
self.label_date.text = doc["created"].strftime("%B %d, %Y")
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
container:
2+
type: ColumnPanel
3+
properties: {col_widths: '{"DNHJUG":15,"JCESCE":45,"ELLICF":15,"LLBXUV":45,"GLAPWR":15,"HEERCI":45}'}
4+
components:
5+
- type: Label
6+
properties: {role: null, width: default, align: center, border: '', foreground: '',
7+
visible: true, text: Document details, font_size: 28, font: '', spacing_above: small,
8+
icon_align: left, spacing_below: small, italic: false, background: '', bold: true,
9+
underline: false, icon: ''}
10+
name: label_subtitle
11+
layout_properties: {grid_position: 'WVCRYU,ZZNMYW'}
12+
- type: Label
13+
properties: {role: null, width: default, align: left, border: '', foreground: '',
14+
visible: true, text: Title, font_size: null, font: '', spacing_above: small, icon_align: left,
15+
spacing_below: small, italic: false, background: '', bold: true, underline: false,
16+
icon: ''}
17+
name: label_1
18+
layout_properties: {grid_position: 'JZPWOP,GLAPWR'}
19+
- type: Label
20+
properties: {role: null, width: default, align: left, border: '', foreground: '',
21+
visible: true, text: '', font_size: 24, font: '', spacing_above: small, icon_align: left,
22+
spacing_below: small, italic: false, background: '', bold: false, underline: false,
23+
icon: ''}
24+
name: label_title
25+
layout_properties: {grid_position: 'JZPWOP,HEERCI'}
26+
data_bindings:
27+
- {property: text, code: 'self.item[''name'']'}
28+
- type: Label
29+
properties: {role: null, width: default, align: left, border: '', foreground: '',
30+
visible: true, text: Created, font_size: null, font: '', spacing_above: small,
31+
icon_align: left, spacing_below: small, italic: false, background: '', bold: true,
32+
underline: false, icon: ''}
33+
name: label_2
34+
layout_properties: {grid_position: 'ABSXYH,DNHJUG'}
35+
- type: Label
36+
properties: {}
37+
name: label_date
38+
layout_properties: {grid_position: 'ABSXYH,JCESCE'}
39+
data_bindings: []
40+
- type: Label
41+
properties: {role: null, width: default, align: left, border: '', foreground: '',
42+
visible: true, text: Category, font_size: null, font: '', spacing_above: small,
43+
icon_align: left, spacing_below: small, italic: false, background: '', bold: true,
44+
underline: false, icon: ''}
45+
name: label_3
46+
layout_properties: {grid_position: 'RFNREN,ELLICF'}
47+
- type: Label
48+
properties: {}
49+
name: label_category
50+
layout_properties: {grid_position: 'RFNREN,LLBXUV'}
51+
- type: Label
52+
properties: {role: null, width: default, align: left, border: '', foreground: '',
53+
visible: true, text: '', font_size: 18, font: '', spacing_above: small, icon_align: left,
54+
spacing_below: small, italic: false, background: '', bold: false, underline: false,
55+
icon: ''}
56+
name: label_contents
57+
layout_properties: {grid_position: 'OQYTJI,QDEAGK'}
58+
data_bindings:
59+
- {property: text, code: 'self.item[''contents'']'}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from anvil import *
2+
import anvil.server
3+
import tables
4+
from tables import app_tables
5+
import utilities
6+
7+
class DocListItemTemplate (DocListItemTemplateTemplate):
8+
def __init__(self, **properties):
9+
# You must call self.init_components() before doing anything else in this function
10+
self.init_components(**properties)
11+
12+
# Any code you write here will run when the form opens.
13+
14+
15+
def form_show (self, **event_args):
16+
# This method is called when the column panel is shown on the screen
17+
self.label_created.text = self.item["created"].strftime("%B %d, %Y")
18+
19+
def link_details_click (self, **event_args):
20+
# This method is called when the link is clicked
21+
utilities.go_details(self.item)
22+
23+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
container:
2+
type: ColumnPanel
3+
properties: {col_widths: '{"JKNUPK":30,"TIDSGW":20,"KEEGAO":10}'}
4+
event_bindings: {show: form_show}
5+
components:
6+
- type: Label
7+
properties: {role: null, width: default, align: left, border: '', foreground: '',
8+
visible: true, text: '', font_size: null, font: '', spacing_above: small, icon_align: left,
9+
spacing_below: small, italic: false, background: '', bold: true, underline: false,
10+
icon: ''}
11+
name: label_title
12+
layout_properties: {grid_position: 'KYKPJJ,JKNUPK'}
13+
data_bindings:
14+
- {property: text, code: 'self.item[''name'']'}
15+
- type: Label
16+
properties: {}
17+
name: label_created
18+
layout_properties: {grid_position: 'KYKPJJ,TIDSGW'}
19+
data_bindings: []
20+
- type: Link
21+
properties: {role: null, width: default, align: left, border: '', foreground: '',
22+
visible: true, text: details, font_size: null, row_spacing: 10, wrap_on: mobile,
23+
font: '', spacing_above: small, icon_align: left, col_widths: '', spacing_below: small,
24+
italic: false, background: '', bold: false, underline: false, icon: ''}
25+
name: link_details
26+
layout_properties: {grid_position: 'KYKPJJ,KEEGAO'}
27+
event_bindings: {click: link_details_click}
28+
item_type: {table_id: 9224}

0 commit comments

Comments
 (0)