instruction
stringlengths
0
1k
input
stringlengths
1
1k
output
stringlengths
10
6.51k
import reflex as rx from .components.stats_cards import stats_cards_group
from .views.table import main_table def index() -> rx.Component: return rx.vstack( navbar(), stats_cards_group(), rx.box( main_table(), width="100%", ), width="100%", spacing="6", padding_x=["1.5em", "1.5em", "3em"], ) app = rx...
from .views.navbar import navbar
import reflex as rx from .components.stats_cards import stats_cards_group from .views.navbar import navbar
def index() -> rx.Component: return rx.vstack( navbar(), stats_cards_group(), rx.box( main_table(), width="100%", ), width="100%", spacing="6", padding_x=["1.5em", "1.5em", "3em"], ) app = rx.App( theme=rx.theme( ap...
from .views.table import main_table
from typing import Union import reflex as rx from sqlmodel import String, asc, cast, desc, func, or_, select def _get_percentage_change( value: Union[int, float], prev_value: Union[int, float] ) -> float: percentage_change = ( round(((value - prev_value) / prev_value) * 100, 2) if prev_value...
from datetime import datetime, timedelta
from datetime import datetime, timedelta
import reflex as rx from sqlmodel import String, asc, cast, desc, func, or_, select def _get_percentage_change( value: Union[int, float], prev_value: Union[int, float] ) -> float: percentage_change = ( round(((value - prev_value) / prev_value) * 100, 2) if prev_value != 0 else 0.0 ...
from typing import Union
from datetime import datetime, timedelta from typing import Union
from sqlmodel import String, asc, cast, desc, func, or_, select def _get_percentage_change( value: Union[int, float], prev_value: Union[int, float] ) -> float: percentage_change = ( round(((value - prev_value) / prev_value) * 100, 2) if prev_value != 0 else 0.0 if value == 0 ...
import reflex as rx
from datetime import datetime, timedelta from typing import Union import reflex as rx
def _get_percentage_change( value: Union[int, float], prev_value: Union[int, float] ) -> float: percentage_change = ( round(((value - prev_value) / prev_value) * 100, 2) if prev_value != 0 else 0.0 if value == 0 else float("inf") ) return percentage_change cl...
from sqlmodel import String, asc, cast, desc, func, or_, select
from datetime import datetime, timedelta from typing import Union import reflex as rx from sqlmodel import String, asc, cast, desc, func, or_, select
class Customer(rx.Model, table=True): """The customer model.""" name: str email: str phone: str address: str date: str payments: float status: str class MonthValues(rx.Base): """Values for a month.""" num_customers: int = 0 total_payments: float = 0.0 num_delivers:...
def _get_percentage_change( value: Union[int, float], prev_value: Union[int, float] ) -> float: percentage_change = ( round(((value - prev_value) / prev_value) * 100, 2) if prev_value != 0 else 0.0 if value == 0 else float("inf") ) return percentage_change
from datetime import datetime, timedelta from typing import Union import reflex as rx from sqlmodel import String, asc, cast, desc, func, or_, select def _get_percentage_change( value: Union[int, float], prev_value: Union[int, float] ) -> float:
return percentage_change class Customer(rx.Model, table=True): """The customer model.""" name: str email: str phone: str address: str date: str payments: float status: str class MonthValues(rx.Base): """Values for a month.""" num_customers: int = 0 total_payments: ...
percentage_change = ( round(((value - prev_value) / prev_value) * 100, 2) if prev_value != 0 else 0.0 if value == 0 else float("inf") )
from datetime import datetime, timedelta from typing import Union import reflex as rx from sqlmodel import String, asc, cast, desc, func, or_, select def _get_percentage_change( value: Union[int, float], prev_value: Union[int, float] ) -> float: percentage_change = ( round(((value - prev_value) / pre...
class MonthValues(rx.Base): """Values for a month.""" num_customers: int = 0 total_payments: float = 0.0 num_delivers: int = 0 class State(rx.State): """The app state.""" users: list[Customer] = [] sort_value: str = "" sort_reverse: bool = False search_value: str = "" curr...
class Customer(rx.Model, table=True): """The customer model.""" name: str email: str phone: str address: str date: str payments: float status: str
from datetime import datetime, timedelta from typing import Union import reflex as rx from sqlmodel import String, asc, cast, desc, func, or_, select def _get_percentage_change( value: Union[int, float], prev_value: Union[int, float] ) -> float: percentage_change = ( round(((value - prev_value) / pre...
class State(rx.State): """The app state.""" users: list[Customer] = [] sort_value: str = "" sort_reverse: bool = False search_value: str = "" current_user: Customer = Customer() # Values for current and previous month current_month_values: MonthValues = MonthValues() previous_mon...
class MonthValues(rx.Base): """Values for a month.""" num_customers: int = 0 total_payments: float = 0.0 num_delivers: int = 0
alue - prev_value) / prev_value) * 100, 2) if prev_value != 0 else 0.0 if value == 0 else float("inf") ) return percentage_change class Customer(rx.Model, table=True): """The customer model.""" name: str email: str phone: str address: str date: str ...
if self.search_value: search_value = f"%{str(self.search_value).lower()}%" query = query.where( or_( *[ getattr(Customer, field).ilike(search_value) for field in Customer.get_...
query = select(Customer)
0, 2) if prev_value != 0 else 0.0 if value == 0 else float("inf") ) return percentage_change class Customer(rx.Model, table=True): """The customer model.""" name: str email: str phone: str address: str date: str payments: float status: str cla...
if self.sort_value: sort_column = getattr(Customer, self.sort_value) if self.sort_value == "payments": order = desc(sort_column) if self.sort_reverse else asc(sort_column) else: order = ( desc(f...
if self.search_value: search_value = f"%{str(self.search_value).lower()}%" query = query.where( or_( *[ getattr(Customer, field).ilike(search_value) for field in Customer.get_fields() ...
else 0.0 if value == 0 else float("inf") ) return percentage_change class Customer(rx.Model, table=True): """The customer model.""" name: str email: str phone: str address: str date: str payments: float status: str class MonthValues(rx.Base): """Values...
query = query.where( or_( *[ getattr(Customer, field).ilike(search_value) for field in Customer.get_fields() if field not in ["id", "payments"] ], ...
search_value = f"%{str(self.search_value).lower()}%"
return percentage_change class Customer(rx.Model, table=True): """The customer model.""" name: str email: str phone: str address: str date: str payments: float status: str class MonthValues(rx.Base): """Values for a month.""" num_customers: int = 0 total_payments: floa...
if self.sort_value: sort_column = getattr(Customer, self.sort_value) if self.sort_value == "payments": order = desc(sort_column) if self.sort_reverse else asc(sort_column) else: order = ( desc(f...
query = query.where( or_( *[ getattr(Customer, field).ilike(search_value) for field in Customer.get_fields() if field not in ["id", "payments"] ], ...
ser: Customer = Customer() # Values for current and previous month current_month_values: MonthValues = MonthValues() previous_month_values: MonthValues = MonthValues() def load_entries(self) -> list[Customer]: """Get all users from the database.""" with rx.session() as session: ...
self.users = session.exec(query).all() self.get_current_month_values() self.get_previous_month_values() def get_current_month_values(self): """Calculate current month's values.""" now = datetime.now() start_of_month = datetime(now.year, now.month, 1) ...
if self.sort_value: sort_column = getattr(Customer, self.sort_value) if self.sort_value == "payments": order = desc(sort_column) if self.sort_reverse else asc(sort_column) else: order = ( desc(func.lower(sort...
ues for current and previous month current_month_values: MonthValues = MonthValues() previous_month_values: MonthValues = MonthValues() def load_entries(self) -> list[Customer]: """Get all users from the database.""" with rx.session() as session: query = select(Customer) ...
if self.sort_value == "payments": order = desc(sort_column) if self.sort_reverse else asc(sort_column) else: order = ( desc(func.lower(sort_column)) if self.sort_reverse else ...
sort_column = getattr(Customer, self.sort_value)
hValues = MonthValues() previous_month_values: MonthValues = MonthValues() def load_entries(self) -> list[Customer]: """Get all users from the database.""" with rx.session() as session: query = select(Customer) if self.search_value: search_value = f"%{str...
query = query.order_by(order) self.users = session.exec(query).all() self.get_current_month_values() self.get_previous_month_values() def get_current_month_values(self): """Calculate current month's values.""" now = datetime.now() start_of_mont...
if self.sort_value == "payments": order = desc(sort_column) if self.sort_reverse else asc(sort_column) else: order = ( desc(func.lower(sort_column)) if self.sort_reverse else asc(func.lower(so...
thValues = MonthValues() def load_entries(self) -> list[Customer]: """Get all users from the database.""" with rx.session() as session: query = select(Customer) if self.search_value: search_value = f"%{str(self.search_value).lower()}%" query =...
else: order = ( desc(func.lower(sort_column)) if self.sort_reverse else asc(func.lower(sort_column)) ) query = query.order_by(order) self.users = session.exec(que...
order = desc(sort_column) if self.sort_reverse else asc(sort_column)
ase.""" with rx.session() as session: query = select(Customer) if self.search_value: search_value = f"%{str(self.search_value).lower()}%" query = query.where( or_( *[ getattr(Customer,...
query = query.order_by(order) self.users = session.exec(query).all() self.get_current_month_values() self.get_previous_month_values() def get_current_month_values(self): """Calculate current month's values.""" now = datetime.now() start_of_mont...
order = ( desc(func.lower(sort_column)) if self.sort_reverse else asc(func.lower(sort_column)) )
ry = query.where( or_( *[ getattr(Customer, field).ilike(search_value) for field in Customer.get_fields() if field not in ["id", "payments"] ], ...
self.users = session.exec(query).all() self.get_current_month_values() self.get_previous_month_values() def get_current_month_values(self): """Calculate current month's values.""" now = datetime.now() start_of_month = datetime(now.year, now.month, 1) ...
query = query.order_by(order)
*[ getattr(Customer, field).ilike(search_value) for field in Customer.get_fields() if field not in ["id", "payments"] ], # ensures that payments is cast to a string...
self.get_current_month_values() self.get_previous_month_values() def get_current_month_values(self): """Calculate current month's values.""" now = datetime.now() start_of_month = datetime(now.year, now.month, 1) current_month_users = [ user ...
self.users = session.exec(query).all()
ments"] ], # ensures that payments is cast to a string before applying the ilike operator cast(Customer.payments, String).ilike(search_value), ) ) if self.sort_value: sort_column = ge...
start_of_month = datetime(now.year, now.month, 1) current_month_users = [ user for user in self.users if datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") >= start_of_month ] num_customers = len(current_month_users) total_payments = sum(user....
now = datetime.now()
], # ensures that payments is cast to a string before applying the ilike operator cast(Customer.payments, String).ilike(search_value), ) ) if self.sort_value: sort_column = getattr(Customer, self.sort_val...
current_month_users = [ user for user in self.users if datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") >= start_of_month ] num_customers = len(current_month_users) total_payments = sum(user.payments for user in current_month_users) num_deli...
start_of_month = datetime(now.year, now.month, 1)
st to a string before applying the ilike operator cast(Customer.payments, String).ilike(search_value), ) ) if self.sort_value: sort_column = getattr(Customer, self.sort_value) if self.sort_value == "payments": ...
num_customers = len(current_month_users) total_payments = sum(user.payments for user in current_month_users) num_delivers = len( [user for user in current_month_users if user.status == "Delivered"] ) self.current_month_values = MonthValues( num_customers=...
current_month_users = [ user for user in self.users if datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") >= start_of_month ]
if self.sort_value: sort_column = getattr(Customer, self.sort_value) if self.sort_value == "payments": order = desc(sort_column) if self.sort_reverse else asc(sort_column) else: order = ( desc(func.lower(s...
total_payments = sum(user.payments for user in current_month_users) num_delivers = len( [user for user in current_month_users if user.status == "Delivered"] ) self.current_month_values = MonthValues( num_customers=num_customers, total_payments=total_p...
num_customers = len(current_month_users)
n = getattr(Customer, self.sort_value) if self.sort_value == "payments": order = desc(sort_column) if self.sort_reverse else asc(sort_column) else: order = ( desc(func.lower(sort_column)) if self.sort...
num_delivers = len( [user for user in current_month_users if user.status == "Delivered"] ) self.current_month_values = MonthValues( num_customers=num_customers, total_payments=total_payments, num_delivers=num_delivers, ) def get_previ...
total_payments = sum(user.payments for user in current_month_users)
"payments": order = desc(sort_column) if self.sort_reverse else asc(sort_column) else: order = ( desc(func.lower(sort_column)) if self.sort_reverse else asc(func.lower(sort_column)) ...
self.current_month_values = MonthValues( num_customers=num_customers, total_payments=total_payments, num_delivers=num_delivers, ) def get_previous_month_values(self): """Calculate previous month's values.""" now = datetime.now() first_day...
num_delivers = len( [user for user in current_month_users if user.status == "Delivered"] )
lse: order = ( desc(func.lower(sort_column)) if self.sort_reverse else asc(func.lower(sort_column)) ) query = query.order_by(order) self.users = session.exec(query).all() ...
def get_previous_month_values(self): """Calculate previous month's values.""" now = datetime.now() first_day_of_current_month = datetime(now.year, now.month, 1) last_day_of_last_month = first_day_of_current_month - timedelta(days=1) start_of_last_month = datetime( ...
self.current_month_values = MonthValues( num_customers=num_customers, total_payments=total_payments, num_delivers=num_delivers, )
self.users = session.exec(query).all() self.get_current_month_values() self.get_previous_month_values() def get_current_month_values(self): """Calculate current month's values.""" now = datetime.now() start_of_month = datetime(now.year, now.month, 1) current_month_...
first_day_of_current_month = datetime(now.year, now.month, 1) last_day_of_last_month = first_day_of_current_month - timedelta(days=1) start_of_last_month = datetime( last_day_of_last_month.year, last_day_of_last_month.month, 1 ) previous_month_users = [ ...
now = datetime.now()
ry).all() self.get_current_month_values() self.get_previous_month_values() def get_current_month_values(self): """Calculate current month's values.""" now = datetime.now() start_of_month = datetime(now.year, now.month, 1) current_month_users = [ user ...
last_day_of_last_month = first_day_of_current_month - timedelta(days=1) start_of_last_month = datetime( last_day_of_last_month.year, last_day_of_last_month.month, 1 ) previous_month_users = [ user for user in self.users if start_of_last_m...
first_day_of_current_month = datetime(now.year, now.month, 1)
evious_month_values() def get_current_month_values(self): """Calculate current month's values.""" now = datetime.now() start_of_month = datetime(now.year, now.month, 1) current_month_users = [ user for user in self.users if datetime.strptime(user...
start_of_last_month = datetime( last_day_of_last_month.year, last_day_of_last_month.month, 1 ) previous_month_users = [ user for user in self.users if start_of_last_month <= datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") ...
last_day_of_last_month = first_day_of_current_month - timedelta(days=1)
ate current month's values.""" now = datetime.now() start_of_month = datetime(now.year, now.month, 1) current_month_users = [ user for user in self.users if datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") >= start_of_month ] num_customers = ...
previous_month_users = [ user for user in self.users if start_of_last_month <= datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") <= last_day_of_last_month ] # We add some dummy values to simulate growth/decline. Remove them in product...
start_of_last_month = datetime( last_day_of_last_month.year, last_day_of_last_month.month, 1 )
current_month_users = [ user for user in self.users if datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") >= start_of_month ] num_customers = len(current_month_users) total_payments = sum(user.payments for user in current_month_users) num_delivers = ...
# We add some dummy values to simulate growth/decline. Remove them in production. num_customers = len(previous_month_users) + 3 total_payments = sum(user.payments for user in previous_month_users) + 240 num_delivers = ( len([user for user in previous_month_users if user.stat...
previous_month_users = [ user for user in self.users if start_of_last_month <= datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") <= last_day_of_last_month ]
( [user for user in current_month_users if user.status == "Delivered"] ) self.current_month_values = MonthValues( num_customers=num_customers, total_payments=total_payments, num_delivers=num_delivers, ) def get_previous_month_values(self): ...
total_payments = sum(user.payments for user in previous_month_users) + 240 num_delivers = ( len([user for user in previous_month_users if user.status == "Delivered"]) + 5 ) self.previous_month_values = MonthValues( num_customers=num_customers, ...
num_customers = len(previous_month_users) + 3
user.status == "Delivered"] ) self.current_month_values = MonthValues( num_customers=num_customers, total_payments=total_payments, num_delivers=num_delivers, ) def get_previous_month_values(self): """Calculate previous month's values.""" ...
num_delivers = ( len([user for user in previous_month_users if user.status == "Delivered"]) + 5 ) self.previous_month_values = MonthValues( num_customers=num_customers, total_payments=total_payments, num_delivers=num_delivers, ...
total_payments = sum(user.payments for user in previous_month_users) + 240
ues( num_customers=num_customers, total_payments=total_payments, num_delivers=num_delivers, ) def get_previous_month_values(self): """Calculate previous month's values.""" now = datetime.now() first_day_of_current_month = datetime(now.year, now.mo...
self.previous_month_values = MonthValues( num_customers=num_customers, total_payments=total_payments, num_delivers=num_delivers, ) def sort_values(self, sort_value: str): self.sort_value = sort_value self.load_entries() def toggle_sort(self...
num_delivers = ( len([user for user in previous_month_users if user.status == "Delivered"]) + 5 )
def get_previous_month_values(self): """Calculate previous month's values.""" now = datetime.now() first_day_of_current_month = datetime(now.year, now.month, 1) last_day_of_last_month = first_day_of_current_month - timedelta(days=1) start_of_last_month = datetime( ...
def sort_values(self, sort_value: str): self.sort_value = sort_value self.load_entries() def toggle_sort(self): self.sort_reverse = not self.sort_reverse self.load_entries() def filter_values(self, search_value): self.search_value = search_value self.load_...
self.previous_month_values = MonthValues( num_customers=num_customers, total_payments=total_payments, num_delivers=num_delivers, )
onth, 1) last_day_of_last_month = first_day_of_current_month - timedelta(days=1) start_of_last_month = datetime( last_day_of_last_month.year, last_day_of_last_month.month, 1 ) previous_month_users = [ user for user in self.users if start_o...
def toggle_sort(self): self.sort_reverse = not self.sort_reverse self.load_entries() def filter_values(self, search_value): self.search_value = search_value self.load_entries() def get_user(self, user: Customer): self.current_user = user def add_customer_to_d...
def sort_values(self, sort_value: str): self.sort_value = sort_value self.load_entries()
day_of_current_month - timedelta(days=1) start_of_last_month = datetime( last_day_of_last_month.year, last_day_of_last_month.month, 1 ) previous_month_users = [ user for user in self.users if start_of_last_month <= datetime.strptime(us...
self.load_entries() def toggle_sort(self): self.sort_reverse = not self.sort_reverse self.load_entries() def filter_values(self, search_value): self.search_value = search_value self.load_entries() def get_user(self, user: Customer): self.current_user = use...
self.sort_value = sort_value
_month = datetime( last_day_of_last_month.year, last_day_of_last_month.month, 1 ) previous_month_users = [ user for user in self.users if start_of_last_month <= datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") <= last_day_of_last_...
def filter_values(self, search_value): self.search_value = search_value self.load_entries() def get_user(self, user: Customer): self.current_user = user def add_customer_to_db(self, form_data: dict): with rx.session() as session: if session.exec( ...
def toggle_sort(self): self.sort_reverse = not self.sort_reverse self.load_entries()
last_day_of_last_month.year, last_day_of_last_month.month, 1 ) previous_month_users = [ user for user in self.users if start_of_last_month <= datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") <= last_day_of_last_month ] # We ad...
self.load_entries() def filter_values(self, search_value): self.search_value = search_value self.load_entries() def get_user(self, user: Customer): self.current_user = user def add_customer_to_db(self, form_data: dict): with rx.session() as session: if...
self.sort_reverse = not self.sort_reverse
previous_month_users = [ user for user in self.users if start_of_last_month <= datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") <= last_day_of_last_month ] # We add some dummy values to simulate growth/decline. Remove them in production. ...
def get_user(self, user: Customer): self.current_user = user def add_customer_to_db(self, form_data: dict): with rx.session() as session: if session.exec( select(Customer).where(Customer.email == form_data.get("email")) ).first(): return...
def filter_values(self, search_value): self.search_value = search_value self.load_entries()
for user in self.users if start_of_last_month <= datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") <= last_day_of_last_month ] # We add some dummy values to simulate growth/decline. Remove them in production. num_customers = len(previous_month_user...
self.load_entries() def get_user(self, user: Customer): self.current_user = user def add_customer_to_db(self, form_data: dict): with rx.session() as session: if session.exec( select(Customer).where(Customer.email == form_data.get("email")) ).fir...
self.search_value = search_value
nth <= datetime.strptime(user.date, "%Y-%m-%d %H:%M:%S") <= last_day_of_last_month ] # We add some dummy values to simulate growth/decline. Remove them in production. num_customers = len(previous_month_users) + 3 total_payments = sum(user.payments for user in prev...
def add_customer_to_db(self, form_data: dict): with rx.session() as session: if session.exec( select(Customer).where(Customer.email == form_data.get("email")) ).first(): return rx.window_alert("User with this email already exists") self.c...
def get_user(self, user: Customer): self.current_user = user
te, "%Y-%m-%d %H:%M:%S") <= last_day_of_last_month ] # We add some dummy values to simulate growth/decline. Remove them in production. num_customers = len(previous_month_users) + 3 total_payments = sum(user.payments for user in previous_month_users) + 240 num_delivers...
def add_customer_to_db(self, form_data: dict): with rx.session() as session: if session.exec( select(Customer).where(Customer.email == form_data.get("email")) ).first(): return rx.window_alert("User with this email already exists") self.c...
self.current_user = user
<= last_day_of_last_month ] # We add some dummy values to simulate growth/decline. Remove them in production. num_customers = len(previous_month_users) + 3 total_payments = sum(user.payments for user in previous_month_users) + 240 num_delivers = ( len([user for...
def update_customer_to_db(self, form_data: dict): with rx.session() as session: customer = session.exec( select(Customer).where(Customer.id == self.current_user.id) ).first() form_data.pop("id", None) customer.set(**form_data) ses...
def add_customer_to_db(self, form_data: dict): with rx.session() as session: if session.exec( select(Customer).where(Customer.email == form_data.get("email")) ).first(): return rx.window_alert("User with this email already exists") self.current...
decline. Remove them in production. num_customers = len(previous_month_users) + 3 total_payments = sum(user.payments for user in previous_month_users) + 240 num_delivers = ( len([user for user in previous_month_users if user.status == "Delivered"]) + 5 ) ...
self.current_user = Customer( date=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), **form_data ) session.add(self.current_user) session.commit() session.refresh(self.current_user) self.load_entries() return rx.toast.info( ...
if session.exec( select(Customer).where(Customer.email == form_data.get("email")) ).first(): return rx.window_alert("User with this email already exists")
en([user for user in previous_month_users if user.status == "Delivered"]) + 5 ) self.previous_month_values = MonthValues( num_customers=num_customers, total_payments=total_payments, num_delivers=num_delivers, ) def sort_values(self, sort_valu...
session.add(self.current_user) session.commit() session.refresh(self.current_user) self.load_entries() return rx.toast.info( f"User {self.current_user.name} has been added.", position="bottom-right" ) def update_customer_to_db(self, form_data...
self.current_user = Customer( date=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), **form_data )
f toggle_sort(self): self.sort_reverse = not self.sort_reverse self.load_entries() def filter_values(self, search_value): self.search_value = search_value self.load_entries() def get_user(self, user: Customer): self.current_user = user def add_customer_to_db(self, ...
def delete_customer(self, id: int): """Delete a customer from the database.""" with rx.session() as session: customer = session.exec(select(Customer).where(Customer.id == id)).first() session.delete(customer) session.commit() self.load_entries() ...
def update_customer_to_db(self, form_data: dict): with rx.session() as session: customer = session.exec( select(Customer).where(Customer.id == self.current_user.id) ).first() form_data.pop("id", None) customer.set(**form_data) session.a...
def filter_values(self, search_value): self.search_value = search_value self.load_entries() def get_user(self, user: Customer): self.current_user = user def add_customer_to_db(self, form_data: dict): with rx.session() as session: if session.exec( ...
form_data.pop("id", None) customer.set(**form_data) session.add(customer) session.commit() self.load_entries() return rx.toast.info( f"User {self.current_user.name} has been modified.", position="bottom-right", ) def d...
customer = session.exec( select(Customer).where(Customer.id == self.current_user.id) ).first()
ndow_alert("User with this email already exists") self.current_user = Customer( date=datetime.now().strftime("%Y-%m-%d %H:%M:%S"), **form_data ) session.add(self.current_user) session.commit() session.refresh(self.current_user) self.loa...
@rx.var(cache=True) def payments_change(self) -> float: return _get_percentage_change( self.current_month_values.total_payments, self.previous_month_values.total_payments, ) @rx.var(cache=True) def customers_change(self) -> float: return _get_percentage...
def delete_customer(self, id: int): """Delete a customer from the database.""" with rx.session() as session: customer = session.exec(select(Customer).where(Customer.id == id)).first() session.delete(customer) session.commit() self.load_entries() return...
"%Y-%m-%d %H:%M:%S"), **form_data ) session.add(self.current_user) session.commit() session.refresh(self.current_user) self.load_entries() return rx.toast.info( f"User {self.current_user.name} has been added.", position="bottom-right" )...
session.delete(customer) session.commit() self.load_entries() return rx.toast.info( f"User {customer.name} has been deleted.", position="bottom-right" ) @rx.var(cache=True) def payments_change(self) -> float: return _get_percentage_change( ...
customer = session.exec(select(Customer).where(Customer.id == id)).first()
) def update_customer_to_db(self, form_data: dict): with rx.session() as session: customer = session.exec( select(Customer).where(Customer.id == self.current_user.id) ).first() form_data.pop("id", None) customer.set(**form_data) ...
@rx.var(cache=True) def customers_change(self) -> float: return _get_percentage_change( self.current_month_values.num_customers, self.previous_month_values.num_customers, ) @rx.var(cache=True) def delivers_change(self) -> float: return _get_percentage_c...
def payments_change(self) -> float: return _get_percentage_change( self.current_month_values.total_payments, self.previous_month_values.total_payments, )
.first() form_data.pop("id", None) customer.set(**form_data) session.add(customer) session.commit() self.load_entries() return rx.toast.info( f"User {self.current_user.name} has been modified.", position="bottom-right", ) ...
@rx.var(cache=True) def delivers_change(self) -> float: return _get_percentage_change( self.current_month_values.num_delivers, self.previous_month_values.num_delivers, )
def customers_change(self) -> float: return _get_percentage_change( self.current_month_values.num_customers, self.previous_month_values.num_customers, )
er {self.current_user.name} has been modified.", position="bottom-right", ) def delete_customer(self, id: int): """Delete a customer from the database.""" with rx.session() as session: customer = session.exec(select(Customer).where(Customer.id == id)).first() ...
def delivers_change(self) -> float: return _get_percentage_change( self.current_month_values.num_delivers, self.previous_month_values.num_delivers, )
def form_field( label: str, placeholder: str, type: str, name: str, icon: str, default_value: str = "", ) -> rx.Component: return rx.form.field( rx.flex( rx.hstack( rx.icon(icon, size=16, stroke_width=1.5), rx.form.label(label), ...
import reflex as rx
from reflex.components.radix.themes.base import ( LiteralAccentColor, ) from ..backend.backend import State def _arrow_badge(arrow_icon: str, percentage_change: float, arrow_color: str): return rx.badge( rx.icon( tag=arrow_icon, color=rx.color(arrow_color, 9), ), ...
import reflex as rx
import reflex as rx
from ..backend.backend import State def _arrow_badge(arrow_icon: str, percentage_change: float, arrow_color: str): return rx.badge( rx.icon( tag=arrow_icon, color=rx.color(arrow_color, 9), ), rx.text( f"{percentage_change}%", size="2", ...
from reflex.components.radix.themes.base import ( LiteralAccentColor, )
import reflex as rx from reflex.components.radix.themes.base import ( LiteralAccentColor, )
def _arrow_badge(arrow_icon: str, percentage_change: float, arrow_color: str): return rx.badge( rx.icon( tag=arrow_icon, color=rx.color(arrow_color, 9), ), rx.text( f"{percentage_change}%", size="2", color=rx.color(arrow_color, 9...
from ..backend.backend import State
def _badge(icon: str, text: str, color_scheme: str): return rx.badge( rx.icon(icon, size=16), text, color_scheme=color_scheme, radius="full", variant="soft", size="3", ) def status_badge(status: str): badge_mapping = { "Delivered": ("check", "Deli...
import reflex as rx
def navbar(): return rx.flex( rx.badge( rx.icon(tag="table-2", size=28), rx.heading("Customer Data App", size="6"), color_scheme="green", radius="large", align="center", variant="surface", padding="0.65rem", ), ...
import reflex as rx
from ..backend.backend import Customer, State from ..components.form_field import form_field from ..components.status_badges import status_badge def show_customer(user: Customer): """Show a customer in a table row.""" return rx.table.row( rx.table.cell(user.name), rx.table.cell(user.email), ...
import reflex as rx
import reflex as rx
from ..components.form_field import form_field from ..components.status_badges import status_badge def show_customer(user: Customer): """Show a customer in a table row.""" return rx.table.row( rx.table.cell(user.name), rx.table.cell(user.email), rx.table.cell(user.phone), rx.t...
from ..backend.backend import Customer, State
import reflex as rx from ..backend.backend import Customer, State
from ..components.status_badges import status_badge def show_customer(user: Customer): """Show a customer in a table row.""" return rx.table.row( rx.table.cell(user.name), rx.table.cell(user.email), rx.table.cell(user.phone), rx.table.cell(user.address), rx.table.cell(...
from ..components.form_field import form_field
import reflex as rx from ..backend.backend import Customer, State from ..components.form_field import form_field
def show_customer(user: Customer): """Show a customer in a table row.""" return rx.table.row( rx.table.cell(user.name), rx.table.cell(user.email), rx.table.cell(user.phone), rx.table.cell(user.address), rx.table.cell(f"${user.payments}"), rx.table.cell(user.dat...
from ..components.status_badges import status_badge
import reflex as rx from ..backend.backend import Customer, State from ..components.form_field import form_field from ..components.status_badges import status_badge
def add_customer_button() -> rx.Component: return rx.dialog.root( rx.dialog.trigger( rx.button( rx.icon("plus", size=26), rx.text("Add Customer", size="4", display=["none", "none", "block"]), size="3", ), ), rx.dialog...
def show_customer(user: Customer): """Show a customer in a table row.""" return rx.table.row( rx.table.cell(user.name), rx.table.cell(user.email), rx.table.cell(user.phone), rx.table.cell(user.address), rx.table.cell(f"${user.payments}"), rx.table.cell(user.date),...
"Cancel", variant="soft", color_scheme="gray", ), ), rx.form.submit( rx.dialog.close( rx.button("Update Customer...
def main_table(): return rx.fragment( rx.flex( add_customer_button(), rx.spacer(), rx.cond( State.sort_reverse, rx.icon( "arrow-down-z-a", size=28, stroke_width=1.5, ...
def _header_cell(text: str, icon: str): return rx.table.column_header_cell( rx.hstack( rx.icon(icon, size=18), rx.text(text), align="center", spacing="2", ), )
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os
import reflex as rx _client = None def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client class State(rx.State): """The app state.""" image_url = "" image_processing = False image_made = False ...
import openai
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai
_client = None def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client class State(rx.State): """The app state.""" image_url = "" image_processing = False image_made = False def get_dalle_res...
import reflex as rx
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai import reflex as rx
def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client class State(rx.State): """The app state.""" image_url = "" image_processing = False image_made = False def get_dalle_result(self, form_d...
_client = None
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai import reflex as rx _client = None
class State(rx.State): """The app state.""" image_url = "" image_processing = False image_made = False def get_dalle_result(self, form_data: dict[str, str]): prompt_text: str = form_data["prompt_text"] self.image_made = False self.image_processing = True # Yield ...
def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai import reflex as rx _client = None def get_openai_client(): global _client
return _client class State(rx.State): """The app state.""" image_url = "" image_processing = False image_made = False def get_dalle_result(self, form_data: dict[str, str]): prompt_text: str = form_data["prompt_text"] self.image_made = False self.image_processing = T...
if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai import reflex as rx _client = None def get_openai_client(): global _client if _client is None:
return _client class State(rx.State): """The app state.""" image_url = "" image_processing = False image_made = False def get_dalle_result(self, form_data: dict[str, str]): prompt_text: str = form_data["prompt_text"] self.image_made = False self.image_processing = T...
_client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai import reflex as rx _client = None def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client class State(rx.State...
image_made = False def get_dalle_result(self, form_data: dict[str, str]): prompt_text: str = form_data["prompt_text"] self.image_made = False self.image_processing = True # Yield here so the image_processing take effects and the circular progress is shown. yield ...
image_processing = False
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai import reflex as rx _client = None def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client class State(rx.State...
def get_dalle_result(self, form_data: dict[str, str]): prompt_text: str = form_data["prompt_text"] self.image_made = False self.image_processing = True # Yield here so the image_processing take effects and the circular progress is shown. yield try: respo...
image_made = False
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai import reflex as rx _client = None def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client class State(rx.State...
self.image_processing = True # Yield here so the image_processing take effects and the circular progress is shown. yield try: response = get_openai_client().images.generate( prompt=prompt_text, n=1, size="1024x1024" ) self.image_url = ...
self.image_made = False
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai import reflex as rx _client = None def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client class State(rx.State...
# Yield here so the image_processing take effects and the circular progress is shown. yield try: response = get_openai_client().images.generate( prompt=prompt_text, n=1, size="1024x1024" ) self.image_url = response.data[0].url self...
self.image_processing = True
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai import reflex as rx _client = None def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client class State(rx.State...
self.image_url = response.data[0].url self.image_processing = False self.image_made = True yield except Exception as ex: self.image_processing = False yield rx.window_alert(f"Error with OpenAI Execution. {ex}") def index(): return rx...
response = get_openai_client().images.generate( prompt=prompt_text, n=1, size="1024x1024" )
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai import reflex as rx _client = None def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client class State(rx.State...
self.image_processing = False self.image_made = True yield except Exception as ex: self.image_processing = False yield rx.window_alert(f"Error with OpenAI Execution. {ex}") def index(): return rx.center( rx.vstack( rx.heading...
self.image_url = response.data[0].url
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai import reflex as rx _client = None def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client class State(rx.State...
self.image_made = True yield except Exception as ex: self.image_processing = False yield rx.window_alert(f"Error with OpenAI Execution. {ex}") def index(): return rx.center( rx.vstack( rx.heading("DALL-E", font_size="1.5em"), ...
self.image_processing = False
"""Welcome to Reflex! This file outlines the steps to create a basic app.""" import os import openai import reflex as rx _client = None def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client class State(rx.State...
yield except Exception as ex: self.image_processing = False yield rx.window_alert(f"Error with OpenAI Execution. {ex}") def index(): return rx.center( rx.vstack( rx.heading("DALL-E", font_size="1.5em"), rx.form( rx.vstack...
self.image_made = True
e steps to create a basic app.""" import os import openai import reflex as rx _client = None def get_openai_client(): global _client if _client is None: _client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY")) return _client class State(rx.State): """The app state.""" image_url ...
yield rx.window_alert(f"Error with OpenAI Execution. {ex}") def index(): return rx.center( rx.vstack( rx.heading("DALL-E", font_size="1.5em"), rx.form( rx.vstack( rx.input( id="prompt_text", ...
self.image_processing = False
size="3", ), align="stretch", spacing="2", ), width="100%", on_submit=State.get_dalle_result, ), rx.divider(), rx.cond( State.image_processing, ...
app.add_page(index, title="Reflex:DALL-E")
app = rx.App( theme=rx.theme( appearance="light", has_background=True, radius="medium", accent_color="mint" ), )
"""Welcome to Reflex!.""" # Import all the pages.
from . import styles from .pages import * # Create the app. app = rx.App( style=styles.base_style, stylesheets=styles.base_stylesheets, )
import reflex as rx
"""Welcome to Reflex!.""" # Import all the pages. import reflex as rx
from .pages import * # Create the app. app = rx.App( style=styles.base_style, stylesheets=styles.base_stylesheets, )
from . import styles
"""Welcome to Reflex!.""" # Import all the pages. import reflex as rx from . import styles
# Create the app. app = rx.App( style=styles.base_style, stylesheets=styles.base_stylesheets, )
from .pages import *
"""Styles for the app."""
border_radius = "var(--radius-2)" border = f"1px solid {rx.color('gray', 5)}" text_color = rx.color("gray", 11) gray_color = rx.color("gray", 11) gray_bg_color = rx.color("gray", 3) accent_text_color = rx.color("accent", 10) accent_color = rx.color("accent", 1) accent_bg_color = rx.color("accent", 3) hover_accent_col...
import reflex as rx
"""Styles for the app.""" import reflex as rx
border = f"1px solid {rx.color('gray', 5)}" text_color = rx.color("gray", 11) gray_color = rx.color("gray", 11) gray_bg_color = rx.color("gray", 3) accent_text_color = rx.color("accent", 10) accent_color = rx.color("accent", 1) accent_bg_color = rx.color("accent", 3) hover_accent_color = {"_hover": {"color": accent_te...
border_radius = "var(--radius-2)"
"""Styles for the app.""" import reflex as rx border_radius = "var(--radius-2)"
text_color = rx.color("gray", 11) gray_color = rx.color("gray", 11) gray_bg_color = rx.color("gray", 3) accent_text_color = rx.color("accent", 10) accent_color = rx.color("accent", 1) accent_bg_color = rx.color("accent", 3) hover_accent_color = {"_hover": {"color": accent_text_color}} hover_accent_bg = {"_hover": {"ba...
border = f"1px solid {rx.color('gray', 5)}"
"""Styles for the app.""" import reflex as rx border_radius = "var(--radius-2)" border = f"1px solid {rx.color('gray', 5)}"
gray_color = rx.color("gray", 11) gray_bg_color = rx.color("gray", 3) accent_text_color = rx.color("accent", 10) accent_color = rx.color("accent", 1) accent_bg_color = rx.color("accent", 3) hover_accent_color = {"_hover": {"color": accent_text_color}} hover_accent_bg = {"_hover": {"background_color": accent_color}} co...
text_color = rx.color("gray", 11)
"""Styles for the app.""" import reflex as rx border_radius = "var(--radius-2)" border = f"1px solid {rx.color('gray', 5)}" text_color = rx.color("gray", 11)
gray_bg_color = rx.color("gray", 3) accent_text_color = rx.color("accent", 10) accent_color = rx.color("accent", 1) accent_bg_color = rx.color("accent", 3) hover_accent_color = {"_hover": {"color": accent_text_color}} hover_accent_bg = {"_hover": {"background_color": accent_color}} content_width_vw = "90vw" sidebar_wi...
gray_color = rx.color("gray", 11)
"""Styles for the app.""" import reflex as rx border_radius = "var(--radius-2)" border = f"1px solid {rx.color('gray', 5)}" text_color = rx.color("gray", 11) gray_color = rx.color("gray", 11)
accent_text_color = rx.color("accent", 10) accent_color = rx.color("accent", 1) accent_bg_color = rx.color("accent", 3) hover_accent_color = {"_hover": {"color": accent_text_color}} hover_accent_bg = {"_hover": {"background_color": accent_color}} content_width_vw = "90vw" sidebar_width = "32em" sidebar_content_width =...
gray_bg_color = rx.color("gray", 3)
"""Styles for the app.""" import reflex as rx border_radius = "var(--radius-2)" border = f"1px solid {rx.color('gray', 5)}" text_color = rx.color("gray", 11) gray_color = rx.color("gray", 11) gray_bg_color = rx.color("gray", 3)
accent_color = rx.color("accent", 1) accent_bg_color = rx.color("accent", 3) hover_accent_color = {"_hover": {"color": accent_text_color}} hover_accent_bg = {"_hover": {"background_color": accent_color}} content_width_vw = "90vw" sidebar_width = "32em" sidebar_content_width = "16em" max_width = "1480px" color_box_size...
accent_text_color = rx.color("accent", 10)
"""Styles for the app.""" import reflex as rx border_radius = "var(--radius-2)" border = f"1px solid {rx.color('gray', 5)}" text_color = rx.color("gray", 11) gray_color = rx.color("gray", 11) gray_bg_color = rx.color("gray", 3) accent_text_color = rx.color("accent", 10)
accent_bg_color = rx.color("accent", 3) hover_accent_color = {"_hover": {"color": accent_text_color}} hover_accent_bg = {"_hover": {"background_color": accent_color}} content_width_vw = "90vw" sidebar_width = "32em" sidebar_content_width = "16em" max_width = "1480px" color_box_size = ["2.25rem", "2.25rem", "2.5rem"] ...
accent_color = rx.color("accent", 1)
"""Styles for the app.""" import reflex as rx border_radius = "var(--radius-2)" border = f"1px solid {rx.color('gray', 5)}" text_color = rx.color("gray", 11) gray_color = rx.color("gray", 11) gray_bg_color = rx.color("gray", 3) accent_text_color = rx.color("accent", 10) accent_color = rx.color("accent", 1)
hover_accent_color = {"_hover": {"color": accent_text_color}} hover_accent_bg = {"_hover": {"background_color": accent_color}} content_width_vw = "90vw" sidebar_width = "32em" sidebar_content_width = "16em" max_width = "1480px" color_box_size = ["2.25rem", "2.25rem", "2.5rem"] template_page_style = { "padding_to...
accent_bg_color = rx.color("accent", 3)
"""Styles for the app.""" import reflex as rx border_radius = "var(--radius-2)" border = f"1px solid {rx.color('gray', 5)}" text_color = rx.color("gray", 11) gray_color = rx.color("gray", 11) gray_bg_color = rx.color("gray", 3) accent_text_color = rx.color("accent", 10) accent_color = rx.color("accent", 1) accent_bg_...
hover_accent_bg = {"_hover": {"background_color": accent_color}} content_width_vw = "90vw" sidebar_width = "32em" sidebar_content_width = "16em" max_width = "1480px" color_box_size = ["2.25rem", "2.25rem", "2.5rem"] template_page_style = { "padding_top": ["1em", "1em", "2em"], "padding_x": ["auto", "auto", "...
hover_accent_color = {"_hover": {"color": accent_text_color}}
"""Styles for the app.""" import reflex as rx border_radius = "var(--radius-2)" border = f"1px solid {rx.color('gray', 5)}" text_color = rx.color("gray", 11) gray_color = rx.color("gray", 11) gray_bg_color = rx.color("gray", 3) accent_text_color = rx.color("accent", 10) accent_color = rx.color("accent", 1) accent_bg_...
content_width_vw = "90vw" sidebar_width = "32em" sidebar_content_width = "16em" max_width = "1480px" color_box_size = ["2.25rem", "2.25rem", "2.5rem"] template_page_style = { "padding_top": ["1em", "1em", "2em"], "padding_x": ["auto", "auto", "2em"], } template_content_style = { "padding": "1em", "m...
hover_accent_bg = {"_hover": {"background_color": accent_color}}
"""Styles for the app.""" import reflex as rx border_radius = "var(--radius-2)" border = f"1px solid {rx.color('gray', 5)}" text_color = rx.color("gray", 11) gray_color = rx.color("gray", 11) gray_bg_color = rx.color("gray", 3) accent_text_color = rx.color("accent", 10) accent_color = rx.color("accent", 1) accent_bg_...
sidebar_width = "32em" sidebar_content_width = "16em" max_width = "1480px" color_box_size = ["2.25rem", "2.25rem", "2.5rem"] template_page_style = { "padding_top": ["1em", "1em", "2em"], "padding_x": ["auto", "auto", "2em"], } template_content_style = { "padding": "1em", "margin_bottom": "2em", ...
content_width_vw = "90vw"
"""Styles for the app.""" import reflex as rx border_radius = "var(--radius-2)" border = f"1px solid {rx.color('gray', 5)}" text_color = rx.color("gray", 11) gray_color = rx.color("gray", 11) gray_bg_color = rx.color("gray", 3) accent_text_color = rx.color("accent", 10) accent_color = rx.color("accent", 1) accent_bg_...
sidebar_content_width = "16em" max_width = "1480px" color_box_size = ["2.25rem", "2.25rem", "2.5rem"] template_page_style = { "padding_top": ["1em", "1em", "2em"], "padding_x": ["auto", "auto", "2em"], } template_content_style = { "padding": "1em", "margin_bottom": "2em", "min_height": "90vh", }...
sidebar_width = "32em"
"""Styles for the app.""" import reflex as rx border_radius = "var(--radius-2)" border = f"1px solid {rx.color('gray', 5)}" text_color = rx.color("gray", 11) gray_color = rx.color("gray", 11) gray_bg_color = rx.color("gray", 3) accent_text_color = rx.color("accent", 10) accent_color = rx.color("accent", 1) accent_bg_...
max_width = "1480px" color_box_size = ["2.25rem", "2.25rem", "2.5rem"] template_page_style = { "padding_top": ["1em", "1em", "2em"], "padding_x": ["auto", "auto", "2em"], } template_content_style = { "padding": "1em", "margin_bottom": "2em", "min_height": "90vh", } link_style = { "color": a...
sidebar_content_width = "16em"