Started using htmx for dynmical fileds, now need to implment it sitewide, or make an formular for address only let's see
parent
81b21bc69b
commit
a3858ff048
@ -0,0 +1,79 @@
|
|||||||
|
from flask import render_template, url_for, flash, redirect, request, Blueprint
|
||||||
|
from flask_login import login_required, current_user
|
||||||
|
from minibase.app import db
|
||||||
|
import minibase.theme as theme
|
||||||
|
from minibase.blueprints.company.models import Companies
|
||||||
|
import minibase.blueprints.database.utils as dbUtils
|
||||||
|
import minibase.blueprints.main.utils as mainUtils
|
||||||
|
import minibase.blueprints.geography.utils as geoUtils
|
||||||
|
import minibase.blueprints.company.utils as companyUtils
|
||||||
|
from minibase.blueprints.company.forms import updateCompanyForm
|
||||||
|
from minibase.blueprints.user.utils import save_picture
|
||||||
|
from flask_wtf import FlaskForm
|
||||||
|
|
||||||
|
|
||||||
|
# Declaring a blueprint
|
||||||
|
company = Blueprint('company', __name__, template_folder='templates')
|
||||||
|
|
||||||
|
@company.route("/list", methods=['GET', 'POST'])
|
||||||
|
def list():
|
||||||
|
page=request.args.get('page', 1, type=int)
|
||||||
|
table=dbUtils.table_printable_paginate(Companies, page, 20, 'edit/', 'id')
|
||||||
|
return(render_template('view.html', theme=theme, table=table, title="Companies"))
|
||||||
|
|
||||||
|
|
||||||
|
@company.route("/edit/<int:companyId>", methods=['GET', 'POST'])
|
||||||
|
@login_required
|
||||||
|
def edit_company(companyId):
|
||||||
|
if id:
|
||||||
|
form = updateCompanyForm()
|
||||||
|
company = companyUtils.queryById(companyId)
|
||||||
|
form.city.choices = [(row.id, row.name) for row in geoUtils.queryCiytNamesOfStateWithDefId(company.city_id, company.state_id)]
|
||||||
|
form.state.choices = [(row.id, row.name) for row in geoUtils.queryStateNamesOfCuntryWithDefId(company.state_id, company.country_id)]
|
||||||
|
form.country.choices = [(row.id, row.name) for row in geoUtils.queryCountryNamesWithDefault(company.country_id)]
|
||||||
|
form.industry.choices = [(row.id, row.name) for row in mainUtils.queryIndustryNamesWithDefault(company.industry_id)]
|
||||||
|
form.legal_entity.choices = [(row.id, row.name) for row in companyUtils.queryLegalEntityNames()]
|
||||||
|
form.type.choices = [(row.id, row.name) for row in companyUtils.queryTypeNames()]
|
||||||
|
form.relation.choices = [(row.id, row.name) for row in companyUtils.queryRelationNames()]
|
||||||
|
form.status.choices = [(row.id, row.name) for row in companyUtils.queryStatusNames()]
|
||||||
|
|
||||||
|
if form.validate_on_submit():
|
||||||
|
comp = Companies(
|
||||||
|
name = form.name.data,
|
||||||
|
street = form.street.data,
|
||||||
|
website = form.website.data,
|
||||||
|
street_no = form.street_no.data,
|
||||||
|
post_code = form.post_code.data,
|
||||||
|
city_id = form.city.data,
|
||||||
|
state_id = form.state.data,
|
||||||
|
country_id = form.country.data,
|
||||||
|
industry_id = form.industry.data,
|
||||||
|
legal_entity_id = form.legal_entity.data,
|
||||||
|
type_id = form.type.data,
|
||||||
|
relation_id = form.relation.data,
|
||||||
|
status_id = form.status.data,
|
||||||
|
comment = form.comment.data)
|
||||||
|
flash('Company Has been successfully updated', 'success')
|
||||||
|
return redirect(url_for('company.edit', companyId))
|
||||||
|
elif request.method == 'GET':
|
||||||
|
form.name.data = company.name
|
||||||
|
form.website.data = company.website
|
||||||
|
form.street.data = company.street
|
||||||
|
form.street_no.data = company.street_no
|
||||||
|
form.post_code.data = company.post_code
|
||||||
|
|
||||||
|
form.comment.data = company.comment
|
||||||
|
# This could be very interesting but neds more time to think !
|
||||||
|
#for field in form:
|
||||||
|
# if field.name != 'csrf_token' and hasattr(company, field.name):
|
||||||
|
# attr = getattr(company, field.name)
|
||||||
|
# field.data = attr
|
||||||
|
image_file = url_for('static', filename='pics/' + companyUtils.queryImageById(companyId))
|
||||||
|
|
||||||
|
return render_template('company/account.html',
|
||||||
|
theme=theme,
|
||||||
|
image_file=image_file,
|
||||||
|
form=form)
|
||||||
|
else:
|
||||||
|
flash('You need to select a company id', 'alarm')
|
||||||
|
return redirect(url_for('company.list'))
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,11 @@
|
|||||||
|
from flask_wtf import FlaskForm
|
||||||
|
from flask_wtf.file import FileField, FileAllowed
|
||||||
|
from wtforms import StringField, SubmitField, URLField, IntegerField, SelectField
|
||||||
|
from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError
|
||||||
|
import minibase.blueprints.company.utils as companyUtils
|
||||||
|
|
||||||
|
|
||||||
|
class LocationForm(FlaskForm):
|
||||||
|
country = SelectField('Country', validators=[DataRequired()])
|
||||||
|
city = SelectField('City', validators=[DataRequired()])
|
||||||
|
submit = SubmitField('Update')
|
@ -0,0 +1,52 @@
|
|||||||
|
from flask import render_template, url_for, flash, redirect, request, Blueprint
|
||||||
|
from minibase.app import db
|
||||||
|
import minibase.theme as theme
|
||||||
|
import minibase.blueprints.database.utils as dbUtils
|
||||||
|
import minibase.blueprints.main.utils as mainUtils
|
||||||
|
import minibase.blueprints.geography.utils as geoUtils
|
||||||
|
from minibase.blueprints.geography.models import City, State
|
||||||
|
from minibase.blueprints.geography.forms import LocationForm
|
||||||
|
from flask_wtf import FlaskForm
|
||||||
|
|
||||||
|
|
||||||
|
# Declaring a blueprint
|
||||||
|
geography = Blueprint('geography', __name__, template_folder='templates')
|
||||||
|
|
||||||
|
@geography.route('/test', methods=["GET", "POST"])
|
||||||
|
def test():
|
||||||
|
print("hello")
|
||||||
|
form = LocationForm()
|
||||||
|
form.country.choices = [(row.id, row.name) for row in geoUtils.queryCountryNamesWithDefault(-1)]
|
||||||
|
|
||||||
|
if form.country.data:
|
||||||
|
form.city.choices = [(row.id, row.name) for row in geoUtils.queryCiytNamesOfStateWithDefId(form.country.data.id)]
|
||||||
|
else:
|
||||||
|
form.city.choices = [(row.id, row.name) for row in City.query.filter(None).all()]
|
||||||
|
|
||||||
|
if form.validate_on_submit():
|
||||||
|
print(form.country.data.name)
|
||||||
|
print(form.city.data.name)
|
||||||
|
|
||||||
|
return render_template("geography/index.html",
|
||||||
|
form=form,
|
||||||
|
theme=theme)
|
||||||
|
|
||||||
|
|
||||||
|
@geography.route("/get_cities", methods=['GET', 'POST'])
|
||||||
|
def get_cities():
|
||||||
|
country_id = request.args.get("country", type=int)
|
||||||
|
cities = City.query.filter_by(country_id=country_id).all()
|
||||||
|
print(len(cities))
|
||||||
|
if len(cities) == 0:
|
||||||
|
cities = 'Non Awailable'
|
||||||
|
return render_template("geography/city_options.html", cities=cities)
|
||||||
|
|
||||||
|
|
||||||
|
@geography.route("/get_states", methods=['GET', 'POST'])
|
||||||
|
def get_states():
|
||||||
|
country_id = request.args.get("country", type=int)
|
||||||
|
cities = State.query.filter_by(country_id=country_id).all()
|
||||||
|
print(len(cities))
|
||||||
|
if len(cities) == 0:
|
||||||
|
cities = 'Non Awailable'
|
||||||
|
return render_template("geography/city_options.html", cities=cities)
|
@ -0,0 +1,3 @@
|
|||||||
|
{% for city in cities %}
|
||||||
|
<option value="{{ city.id }}">{{ city.name }}</option>
|
||||||
|
{% endfor %}
|
@ -0,0 +1,12 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block content %}
|
||||||
|
<form method="POST" action="" enctype="multipart/form-data">>
|
||||||
|
<fieldset class="form-group">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
{{ form.country(**{"hx-get": "get_cities", "hx-target": "#city"}) }}
|
||||||
|
{{ form.city }}
|
||||||
|
<button>Submit</button>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
{% endblock content %}
|
||||||
|
|
@ -0,0 +1,17 @@
|
|||||||
|
{% if item.type in ['FileField'] %}
|
||||||
|
{{ item.label(class=theme.form.file_label_class, style=theme.form.file_label_style) }}
|
||||||
|
<br>
|
||||||
|
{% endif %}
|
||||||
|
{% if item.errors %}
|
||||||
|
{{ item(class=theme.form.input_error_class) }}
|
||||||
|
<div class="{{ theme.form.div_error_class }}">
|
||||||
|
{% for error in item.errors %}
|
||||||
|
<span>{{ error }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
{% if item.type in ['FileField'] %}
|
||||||
|
{{ item(class=theme.form.file_class, type=theme.form.file_type, style=theme.form.file_style) }}
|
||||||
|
<br>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
@ -0,0 +1,15 @@
|
|||||||
|
{% if item.type in ['URLField'] %}
|
||||||
|
{{ item.label(class=theme.form.url_label_class, style=theme.form.url_label_style) }}
|
||||||
|
{% endif %}
|
||||||
|
{% if item.errors %}
|
||||||
|
{{ item(class=theme.form.url_error_class) }}
|
||||||
|
<div class="{{ theme.form.div_error_class }}">
|
||||||
|
{% for error in item.errors %}
|
||||||
|
<span>{{ error }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
{% if item.type in ['URLField'] %}
|
||||||
|
{{ item(class=theme.form.url_class, type=theme.form.url_type, style=theme.form.url_style) }}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
Loading…
Reference in new issue