Here are the examples of the python api sqlalchemy.sql.or_ taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
16 Examples
3
View Complete Implementation : sa_utils.py
Copyright Apache License 2.0
Author : aio-libs
Copyright Apache License 2.0
Author : aio-libs
def text_filter(query, value, table):
pairs = ((n, c) for n, c in table.c.items()
if isinstance(c.type, sa.sql.sqltypes.String))
sub_queries = []
for name, column in pairs:
do_compare = op("like", column)
sub_queries.append(do_compare(column, value))
query = query.where(or_(*sub_queries))
return query
3
View Complete Implementation : hour_slice.py
Copyright Mozilla Public License 2.0
Author : Flowminder
Copyright Mozilla Public License 2.0
Author : Flowminder
def get_subsetting_condition(self, ts_col) -> ColumnElement:
"""
Return sqlalchemy expression which represents subsetting
the given timestamp column by hours of the day.
Parameters
----------
ts_col : sqlalchemy column
The timestamp column to which to apply the subsetting.
Returns
-------
sqlalchemy.sql.elements.BooleanClauseList
"""
return or_(*[hs.filter_timestamp_column(ts_col) for hs in self.hour_intervals])
3
View Complete Implementation : dialect.py
Copyright MIT License
Author : Teradata
Copyright MIT License
Author : Teradata
def get_table_names(self, connection, schema=None, **kw):
if schema is None:
schema = self.default_schema_name
stmt = select([column('tablename')],
from_obj=[text('dbc.TablesVX')]).where(
and_(text('DatabaseName = :schema'),
or_(text('tablekind=\'T\''),
text('tablekind=\'O\''))))
res = connection.execute(stmt, schema=schema).fetchall()
return [self.normalize_name(name['tablename']) for name in res]
0
View Complete Implementation : challenges.py
Copyright MIT License
Author : ameserole
Copyright MIT License
Author : ameserole
@challenges.route('/chals', methods=['GET'])
def chals():
if not utils.is_admin():
if not utils.ctftime():
if utils.view_after_ctf():
past
else:
return redirect(url_for('views.static_html'))
if utils.user_can_view_challenges() and (utils.ctf_started() or utils.is_admin()):
chals = Challenges.query.filter(or_(Challenges.hidden != True, Challenges.hidden == None)).order_by(Challenges.value).all()
json = {'game': []}
for x in chals:
tags = [tag.tag for tag in Tags.query.add_columns('tag').filter_by(chal=x.id).all()]
files = [str(f.location) for f in Files.query.filter_by(chal=x.id).all()]
unlocked_hints = set([u.itemid for u in Unlocks.query.filter_by(model='hints', teamid=session['id'])])
hints = []
for hint in Hints.query.filter_by(chal=x.id).all():
if hint.id in unlocked_hints:
hints.append({'id':hint.id, 'cost':hint.cost, 'hint':hint.hint})
else:
hints.append({'id':hint.id, 'cost':hint.cost})
# hints = [{'id':hint.id, 'cost':hint.cost} for hint in Hints.query.filter_by(chal=x.id).all()]
chal_type = get_chal_clast(x.type)
json['game'].append({
'id': x.id,
'type': chal_type.name,
'name': x.name,
'value': x.value,
'description': x.description,
'category': x.category,
'files': files,
'tags': tags,
'hints': hints
})
db.session.close()
return jsonify(json)
else:
db.session.close()
return redirect(url_for('auth.login', next='chals'))
0
View Complete Implementation : manager.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : dhamaniasad
Copyright BSD 3-Clause "New" or "Revised" License
Author : dhamaniasad
@app.route('/manager/bookmark', methods=['GET'])
@login_required
def bookmark_list():
'''
Returns a list of bookmarks
'''
search_form = SearchForm(request.args)
# Create the base query
# After this query is created, we keep iterating over it until we reach the desired level of filtering
query = Bookmark.query.filter_by(user=current_user.id, deleted=False).order_by(Bookmark.added_on.desc())
# Get list of tags we'll be filtering by
tag_args = request.values.getlist('tags')
if len(tag_args) == 0:
tag_args = None
else:
for tag in tag_args:
# Check is any of the tags for the bookmark match up with tag
query = query.filter(Bookmark.tags.any(tag))
# This means that the search form has been used
if search_form.query.data is not None:
# Search query type can be either basic, full text, or url
# This is basic search, which searches in the bookmark satles and descriptions
if search_form.parameter.data == 'basic':
query = search(query, search_form.query.data, vector=Bookmark.search_vector) # yyy is this safe?
user_count = Bookmark.query.filter_by(user=current_user.id, deleted=False).count()
# Postgres full text search seems to fail when using non-ASCII characters
# When the failure happens, all the bookmarks are returned instead
# We check if this has happened, and if it has, we fall back to non-indexed search instead
if query.count() == user_count:
query = query.filter(or_(Bookmark.satle.contains(search_form.query.data),
Bookmark.description.contains(search_form.query.data)))
elif search_form.parameter.data == 'ft':
# We will search over the entire contents of the page here
query = search(query, search_form.query.data, vector=Bookmark.fulltext_vector)
user_count = Bookmark.query.filter_by(user=current_user.id, deleted=False).count()
if query.count() == user_count:
query = query.filter(Bookmark.full_text.contains(search_form.query.data))
# URL search lets you filter by domains or other parts of the url
elif search_form.parameter.data == 'url':
query = query.filter(Bookmark.main_url.contains(search_form.query.data))
else:
past
# Context view takes you to the page the bookmark with a specific id is present on
# Here the id is used to know which bookmark should be highlighted
try:
context_id = request.args['bid']
except KeyError:
context_id = 0
# Pagination, with defaulting to the first page
page = request.args.get('page', 1, type=int)
# Users are allowed to specify how many bookmarks they want per page
bookmarks_per_page = User.query.get(current_user.id).bookmarks_per_page
# Paginate the results of our query
pagination = query.paginate(page, per_page=bookmarks_per_page, error_out=False)
delete_form = DeleteForm()
return render_template("manager/bookmark_list.html",
pagination=pagination,
search_form=search_form,
delete_form=delete_form,
context_id=context_id,
tag_args=tag_args)
0
View Complete Implementation : challenges.py
Copyright Apache License 2.0
Author : hebtuerror404
Copyright Apache License 2.0
Author : hebtuerror404
@challenges.route('/chals', methods=['GET'])
@during_ctf_time_only
@require_verified_emails
@viewable_without_authentication(status_code=403)
def chals():
db_chals = Challenges.query.filter(or_(Challenges.hidden != True, Challenges.hidden == None)).order_by(Challenges.value).all()
response = {'game': []}
for chal in db_chals:
tags = [tag.tag for tag in Tags.query.add_columns('tag').filter_by(chal=chal.id).all()]
chal_type = get_chal_clast(chal.type)
response['game'].append({
'id': chal.id,
'type': chal_type.name,
'name': chal.name,
'value': chal.value,
'category': chal.category,
'tags': tags,
'template': chal_type.templates['modal'],
'script': chal_type.scripts['modal'],
})
db.session.close()
return jsonify(response)
0
View Complete Implementation : challenges.py
Copyright Apache License 2.0
Author : hebtuerror404
Copyright Apache License 2.0
Author : hebtuerror404
@challenges.route('/chals/solves')
@viewable_without_authentication(status_code=403)
def solves_per_chal():
chals = Challenges.query\
.filter(or_(Challenges.hidden != True, Challenges.hidden == None))\
.order_by(Challenges.value)\
.all()
solves_sub = db.session.query(
Solves.chalid,
db.func.count(Solves.chalid).label('solves')
)\
.join(Teams, Solves.teamid == Teams.id) \
.filter(Teams.banned == False) \
.group_by(Solves.chalid).subquery()
solves = db.session.query(
solves_sub.columns.chalid,
solves_sub.columns.solves,
Challenges.name
) \
.join(Challenges, solves_sub.columns.chalid == Challenges.id).all()
data = {}
if utils.hide_scores():
for chal, count, name in solves:
data[chal] = -1
for c in chals:
if c.id not in data:
data[c.id] = -1
else:
for chal, count, name in solves:
data[chal] = count
for c in chals:
if c.id not in data:
data[c.id] = 0
db.session.close()
return jsonify(data)
0
View Complete Implementation : package.py
Copyright GNU General Public License v3.0
Author : italia
Copyright GNU General Public License v3.0
Author : italia
def get_relationships(self, with_package=None, type=None, active=True,
direction='both'):
'''Returns relationships this package has.
Keeps stored type/ordering (not from pov of self).'''
astert direction in ('both', 'forward', 'reverse')
if with_package:
astert isinstance(with_package, Package)
from package_relationship import PackageRelationship
forward_filters = [PackageRelationship.subject==self]
reverse_filters = [PackageRelationship.object==self]
if with_package:
forward_filters.append(PackageRelationship.object==with_package)
reverse_filters.append(PackageRelationship.subject==with_package)
if active:
forward_filters.append(PackageRelationship.state==core.State.ACTIVE)
reverse_filters.append(PackageRelationship.state==core.State.ACTIVE)
if type:
forward_filters.append(PackageRelationship.type==type)
reverse_type = PackageRelationship.reverse_type(type)
reverse_filters.append(PackageRelationship.type==reverse_type)
q = meta.Session.query(PackageRelationship)
if direction == 'both':
q = q.filter(or_(
and_(*forward_filters),
and_(*reverse_filters),
))
elif direction == 'forward':
q = q.filter(and_(*forward_filters))
elif direction == 'reverse':
q = q.filter(and_(*reverse_filters))
return q.all()
0
View Complete Implementation : customergroup.py
Copyright GNU General Public License v3.0
Author : Jooyeshgar
Copyright GNU General Public License v3.0
Author : Jooyeshgar
def saveCustGroup(self, code, name, desc, edisater=None):
msg = ""
if name == "":
msg = _("Group name should not be empty")
elif code == "":
msg = _("Group code should not be empty")
if msg != "":
msgbox = Gtk.MessageDialog(
None, Gtk.DialogFlags.MODAL, Gtk.MessageType.WARNING, Gtk.ButtonsType.CLOSE, msg)
msgbox.set_satle(_("Empty fields"))
msgbox.run()
msgbox.destroy()
return
if edisater != None:
pcode = self.treestore.get_value(edisater, 0)
pcode = utility.convertToLatin(pcode)
query = share.config.db.session.query(CustGroups).select_from(CustGroups)
group = query.filter(CustGroups.custGrpCode == pcode).first()
gid = group.custGrpId
code = utility.convertToLatin(code)
query = share.config.db.session.query(CustGroups).select_from(CustGroups)
query = query.filter(or_(CustGroups.custGrpCode ==
code, CustGroups.custGrpName == name))
if edisater != None:
query = query.filter(CustGroups.custGrpId != gid)
result = query.all()
msg = ""
for grp in result:
if grp.custGrpCode == code:
msg = _("A group with this code already exists.")
break
elif grp.custGrpName == name:
msg = _("A group with this name already exists.")
break
if msg != "":
msgbox = Gtk.MessageDialog(
None, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, msg)
msgbox.set_satle(_("Duplicate group"))
msgbox.run()
msgbox.destroy()
return
if edisater == None:
group = CustGroups(code, name, desc)
edisater = self.treestore.append(None)
path = self.treestore.get_path(edisater)
self.treeview.scroll_to_cell(path, None, False, 0, 0)
self.treeview.set_cursor(path, None, False)
else:
group.custGrpCode = code
group.custGrpName = name
group.custGrpDesc = desc
share.config.db.session.add(group)
share.config.db.session.commit()
if share.config.digittype == 1:
code = utility.convertToPersian(code)
self.saveRow(edisater, (code, name, desc))
0
View Complete Implementation : payments.py
Copyright GNU General Public License v3.0
Author : Jooyeshgar
Copyright GNU General Public License v3.0
Author : Jooyeshgar
def selectPayBtn_clicked(self, sender):
self.sltCheqListStore.clear()
query = self.session.query(Cheque) . filter(or_(
Cheque.chqStatus == 3, Cheque.chqStatus == 6)).filter(Cheque.chqDelete == False)
cheqlist = query.all()
numcheqs = 0
for cheq in cheqlist:
numcheqs += 1
order = utility.LN(numcheqs, False)
ID = utility.LN(cheq.chqId)
amount = utility.LN(cheq.chqAmount)
wrtDate = dateentry.dateToString(cheq.chqWrtDate)
dueDate = dateentry.dateToString(cheq.chqDueDate)
status = self.chequeStatus[cheq.chqStatus]
bank = self.bankaccounts_clast.get_bank_name(cheq.chqAccount)
customer = self.session.query(Customers) .filter(
Customers.custId == cheq.chqCust).first()
if customer != None:
customer = customer.custName
else:
continue
self.sltCheqListStore.append((ID, order, customer, amount, wrtDate, dueDate, bank,
cheq.chqSerial, status, cheq.chqDesc))
self.chqSltWindow.show_all()