def layout(service_id): service = app_controller.get_club_service(CLUB_NAME, service_id) service.increase_user_view_times() app_controller.save(service) major_img_link = filestore.get_service_img_link(service_id, MAJOR_IMG) print(major_img_link) return html.Div(children=[ html.Label( # service uuid title=service.id, id="service_book_uuid", style={"display": 'none'} ), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ html.H1(service.name) ]) ]), html.Hr(), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ html.Label(_("Price: {}").format(service.price)) ]) ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ html.Label(_("Discount:{}").format(service.discount)) ]) ]), html.Hr(), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ html.P(service.description) ]) ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ html.Img(id="service_book_img_major", src=filestore.get_service_img_link(service_id, MAJOR_IMG), className="img-fluid"), ]), ]), html.Div(id="service_book_imgs_and_texts", children=[ generate_img_txt(service_id, i) for i in range(MAX_IMG_TXT) ]), html.Hr(), dcc.Link(href= "/shop/cart", className="btn btn-primary secondfloat", children=[_("Goto cart")]), html.Button(id="service_book_add_to_cart", className="btn btn-primary float", children=[ _("Add to cart")]), LocalStorageWriter(id="service_book_cart_storage_writer", label=CART_STORAGE), LocalStorageReader(id="service_book_cart_storage_reader", label=CART_STORAGE), ])
def service_to_article(self, service, club_name): article = {} article['title'] = service.name article['description'] = service.description article['image'] = filestore.get_service_img_link( service.id, MAJOR_IMG) article['url'] = "/service/book/{}".format(service.id) return article
def generate_img_txt(service_id, index): section_id, upload_id, img_id, txt_id = generate_id(index) img_src = filestore.get_service_img_link(service_id, index) print(img_src) txt_content = filestore.get_service_txt_content(service_id, index) img_txt_section = html.Div( id=section_id, children=[ html.Div(className="row align-items-center", children=[ html.Div(className="col-sm-12", children=[ dcc.Upload(id=upload_id, children=html.Div([ 'Drag and Drop or ', html.A('Select a File'), ]), style={ 'width': '100%', 'height': '100%', 'borderWidth': '1px', 'borderStyle': 'dashed', 'borderRadius': '5px', 'textAlign': 'center', }), ]) ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ html.Img(id=img_id, src=img_src, className="img-fluid"), ]), ]), html.Div(className="row", children=[ html.Div( className="col-sm-12", children=[ dcc.Textarea( id=txt_id, placeholder=_( "Please input picture description"), style={'width': '100%'}, value=txt_content if txt_content else "", className="form-control form-control-lg") ]), ]), html.Hr() ]) return img_txt_section
def generate_carousel(): logger.debug("generate carousel") headline_services = app_controller.get_club_headline_service(CLUB_NAME) if not headline_services: print("no headline") return html.Div() service_count = len(headline_services) logger.debug("generate carouse al") logger.debug("service count " + str(service_count)) carousel = html.Div(**{"data-ride": "carousel"}, id="carouselExampleIndicators", className="carousel slide", children=[ html.Ol(className="carousel-indicators", children=[ html.Li(**{"data-target":"#carouselExampleIndicators", "data-slide-to":str(i)}, className="active" if i ==0 else "") for i in range(service_count) ]), html.Div(className="carousel-inner", children=[ html.Div(className="carousel-item active" if i ==0 else "carousel-item", children=[ html.Div(className="d-flex", children=[ dcc.Link(className="col",href="/service/book/{}".format(service.id), children=[ html.Img(className="img-fluid", src=filestore.get_service_img_link(service.id, MAJOR_IMG), alt="Second slide") ]), dcc.Link(className="col",href="/service/book/{}".format(service.id), children=[ html.Img(className="img-fluid", src=filestore.get_service_img_link_alt(service.id), alt="Second slide") ]) ]) ]) for i, service in enumerate(headline_services) ]), html.A(**{"data-slide":"prev"}, className="carousel-control-prev", href="#carouselExampleIndicators", role="button", children=[ html.Span(**{"aria-hidden":"true"}, className="carousel-control-prev-icon"), html.Span("Previous", className="sr-only") ]), html.A(**{"data-slide":"next"}, className="carousel-control-next", href="#carouselExampleIndicators", role="button", children=[ html.Span(**{"aria-hidden":"true"}, className="carousel-control-next-icon"), html.Span("Next", className="sr-only") ]), ]) logger.debug("return carousel") return carousel
def generate_cards(): logger.debug("generate cards") club_services = app_controller.get_club_service_list(CLUB_NAME) if not club_services: return html.Div("No club service!") logger.debug(club_services) cards = [] for service in club_services: card = html.Div(className="card col-sm-4", children=[ dcc.Link(href="/service/book/{}".format(service.id), children=[ html.Div(service.name, className="card-header"), html.Img(className="card-img-top", src=filestore.get_service_img_link(service.id, MAJOR_IMG), alt=service.name), html.Div(className="card-body", children=[ html.P(service.description, className="card-text") ]), html.Div(className="card-footer", children=[ html.Small(service.last_update_time, className="text-muted") ]) ]) ]) cards.append(card) row_list = [] count = len(cards) logger.debug("number of cards {}".format(count)) idx = 0 while idx < count: r1 = cards[idx] r2 = cards[idx + 1] if (idx + 1) < count else None r3 = cards[idx + 2] if (idx + 2) < count else None row_child = [] if r1: row_child.append(r1) if r2: row_child.append(r2) if r3: row_child.append(r3) row_list.append(html.Div(className="row", children=row_child)) idx += 3 logger.debug("end generate") return html.Div(children=row_list)
def generate_img_txt(service_id, index): section_id, upload_id, img_id, txt_id = generate_id(index) img_src = filestore.get_service_img_link(service_id, index) print(img_src) txt_content = filestore.get_service_txt_content(service_id, index) img_txt_section = html.Div(id = section_id, children=[ html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ html.Img(id=img_id, src=img_src, className="img-fluid"), ]), ]) if img_src else "", html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ html.P(txt_content) ]), ]) if txt_content else "" ]) return img_txt_section
def layout(service_id): service = app_controller.get_club_service(CLUB_NAME, service_id) major_img_link = filestore.get_service_img_link(service_id, MAJOR_IMG) print(major_img_link) return html.Div(children=[ html.Label( # service uuid title=service.id, id="service_detail_uuid", style={"display": 'none'}), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[html.Label(_("Title:"))]), ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ dcc.Input( id="service_detail_title", placeholder=_("Please input title"), value=service.name, className="form-control form-control-lg") ]) ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[html.Label(_("Description:"))]), ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ dcc.Textarea( id="service_detail_description", placeholder=_( "Please input service description"), value=service.description, style={'width': '100%'}, className="form-control form-control-lg") ]) ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[html.Label(_("Price:"))]), ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ dcc.Input( id="service_detail_price", placeholder=_( "Please input service price"), style={'width': '100%'}, type="number", value=service.price, step=1, className="form-control form-control-lg") ]) ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[html.Label(_("discount:"))]), ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ dcc.Input( id="service_detail_discount", placeholder=_( "Please input service price"), style={'width': '100%'}, type="number", value=service.discount, min=0, max=100, step=1, className="form-control form-control-lg") ]) ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[html.Label(_("major picture:"))]), ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ dcc.Upload(id='service_detail_upload_major', children=html.Div([ 'Drag and Drop or ', html.A('Select a File'), ]), style={ 'width': '100%', 'height': '60px', 'lineHeight': '60px', 'borderWidth': '1px', 'borderStyle': 'dashed', 'borderRadius': '5px', 'textAlign': 'center', 'margin': '10px' }), ]) ]), html.Div(className="row", children=[ html.Div(className="col-sm-12", children=[ html.Img(id="service_detail_img_major", src=filestore.get_service_img_link( service_id, MAJOR_IMG), className="img-fluid"), ]), ]), html.Div(className="row", children=[ html.Div( className="col-sm-6", children=[ dcc.Checklist( id="service_detail_checklist_online", options=[ { 'label': 'online', 'value': 'online' }, ], values=['online'] if service.active else []) ]), html.Div( className="col-sm-6", children=[ dcc.Checklist( id="service_detail_checklist_headline", options=[ { 'label': 'headline', 'value': 'headline' }, ], values=['headline'] if service.slide else []) ]), ]), html.Div(id="service_detail_imgs_and_texts", children=[ generate_img_txt(service_id, i) for i in range(MAX_IMG_TXT) ]), html.Hr(), float_button, float_button_del, snack_bar, auto_link, auto_link_update ])
def get_img_link(self, index): return filestore.get_service_img_link(self.id, index)