Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored develop branch #22

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions assembl/alembic/versions/116f128b0000_locale_as_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,16 @@ def downgrade(pyramid_env):
'locale.id', onupdate='CASCADE', ondelete='CASCADE')))


op.execute('INSERT INTO locale (code, rtl) values '
+ ','.join(["('%s', %s)" % (loc, str(is_rtl(loc)).lower())
for loc in locales]))
op.execute(
(
'INSERT INTO locale (code, rtl) values '
+ ','.join(
"('%s', %s)" % (loc, str(is_rtl(loc)).lower())
for loc in locales
)
)
)

maparent marked this conversation as resolved.
Show resolved Hide resolved

op.execute('''UPDATE locale_label
SET named_locale_id = (SELECT id FROM locale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ def upgrade(pyramid_env):
)
""")
op.create_unique_constraint(config.get('db_schema')+"_"+config.get('db_user')+"_imported_post_UNQC_source_post_id_source_id", "imported_post", ["source_post_id","source_id"])
pass

maparent marked this conversation as resolved.
Show resolved Hide resolved
# Do stuff with the app's models here.
from assembl import models as m
db = m.get_session_maker()()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ def upgrade(pyramid_env):
UPDATE imported_post
SET body_mime_type = 'text/plain'
""")
pass

maparent marked this conversation as resolved.
Show resolved Hide resolved
# Do stuff with the app's models here.
from assembl import models as m
db = m.get_session_maker()()
Expand All @@ -38,4 +36,3 @@ def downgrade(pyramid_env):
with context.begin_transaction():
#ALTER TABLE assembl..imported_post DROP COLUMN body_mime_type
op.drop_column('imported_post', 'body_mime_type')
pass
maparent marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ def upgrade(pyramid_env):
if 'default_permissions' in values:
found = False
for role, permissions in list(values['default_permissions'].items()):
if role not in base_roles:
if P_OVERRIDE_SOCIAL_AUTOLOGIN not in permissions:
permissions.append(P_OVERRIDE_SOCIAL_AUTOLOGIN)
values['default_permissions'][role] = permissions
found = True
if (
role not in base_roles
and P_OVERRIDE_SOCIAL_AUTOLOGIN not in permissions
):
permissions.append(P_OVERRIDE_SOCIAL_AUTOLOGIN)
values['default_permissions'][role] = permissions
found = True
maparent marked this conversation as resolved.
Show resolved Hide resolved
if found:
changes.append({'id': id, 'pref_json': dumps(values)})
if changes:
Expand Down
8 changes: 6 additions & 2 deletions assembl/alembic/versions/30365b67b36d_idea_link_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ def upgrade(pyramid_env):
m.IdeaLink.tombstone_date == None).first()[0] <= 1
bases.sort()
first = bases[0]
db.execute("""UPDATE idea_idea_link
db.execute(
"""UPDATE idea_idea_link
SET base_id = %d,
creation_date = (SELECT creation_date FROM idea_idea_link AS il2 WHERE base_id=%d LIMIT 1)
WHERE base_id IN (%s)
""" % (first, first, ','.join([str(id) for id in bases[1:]])))
"""
% (first, first, ','.join(str(id) for id in bases[1:]))
)

maparent marked this conversation as resolved.
Show resolved Hide resolved
mark_changed()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,13 @@ def upgrade(pyramid_env):
NotificationSubscriptionStatus, NotificationSubscriptionStatus)
schema = config.get('db_schema')+"."+config.get('db_user')
with context.begin_transaction():
#No clean way to address constraints, and I didn't find a way to add JUST the constraint from sqlalchemy data structures
constraintNameOld = "ck_"+config.get('db_schema')+"_"+config.get('db_user')+"_notification_subscription_notification_status"
op.execute("""ALTER TABLE notification_subscription DROP CONSTRAINT """+constraintNameOld)
constraintNameNew = "ck_"+config.get('db_schema')+"_"+config.get('db_user')+"_notification_subscription_notification_subscription_status"
op.execute("""ALTER TABLE notification_subscription ADD CONSTRAINT """+constraintNameNew+"""
#No clean way to address constraints, and I didn't find a way to add JUST the constraint from sqlalchemy data structures
constraintNameOld = "ck_"+config.get('db_schema')+"_"+config.get('db_user')+"_notification_subscription_notification_status"
op.execute("""ALTER TABLE notification_subscription DROP CONSTRAINT """+constraintNameOld)
constraintNameNew = "ck_"+config.get('db_schema')+"_"+config.get('db_user')+"_notification_subscription_notification_subscription_status"
op.execute("""ALTER TABLE notification_subscription ADD CONSTRAINT """+constraintNameNew+"""
CHECK (status IN ('ACTIVE', 'INACTIVE_DFT', 'UNSUBSCRIBED'))""")


if False:
""" WOW, no column rename in virtuoso!
For the record, even the following doesn't work (chicken and the egg on null values)! Darn virtuoso"""
op.add_column('notification_subscription',
sa.Column('status_temp',
NotificationSubscriptionStatus.db_type(),
nullable=True,
index = True,
default = NotificationSubscriptionStatus.ACTIVE),
schema=schema)

op.execute("""UPDATE notification_subscription SET
status_temp = status""")
op.drop_column('notification_subscription', 'status')
op.add_column('notification_subscription',
sa.Column('status',
NotificationSubscriptionStatus.db_type(),
nullable=True,
index = True,
default = NotificationSubscriptionStatus.ACTIVE),
schema=schema)
op.execute("""UPDATE notification_subscription SET
status = status_temp""")
op.execute("""ALTER TABLE notification_subscription
MODIFY status varchar(256) NOT NULL""")
op.drop_column('notification_subscription', 'status_temp')
maparent marked this conversation as resolved.
Show resolved Hide resolved

def downgrade(pyramid_env):
with context.begin_transaction():
pass
4 changes: 2 additions & 2 deletions assembl/alembic/versions/368a596ab4b5_tombstone_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def reconstruct_idea_history(db):
if len(live_id):
live_id = live_id[0] if live_id else l[-1]
non_synth = [id for id in l if id not in synthesis_dates]
if not non_synth[-1] == live_id:
if non_synth[-1] != live_id:
maparent marked this conversation as resolved.
Show resolved Hide resolved
import pdb; pdb.set_trace()
else:
live_id = l[-1]
Expand Down Expand Up @@ -135,7 +135,7 @@ def reconstruct_vote_history(db):
similar_votes.sort(key=lambda v: v.id)
previous = None
assert not similar_votes[-1].is_tombstone
assert all([vote.is_tombstone for vote in similar_votes[:-1]])
assert all(vote.is_tombstone for vote in similar_votes[:-1])
maparent marked this conversation as resolved.
Show resolved Hide resolved
live_vote_id = similar_votes[-1].id
for vote in similar_votes:
vote.base_id = live_vote_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ def upgrade(pyramid_env):
def downgrade(pyramid_env):
from assembl.semantic.virtuoso_mapping import get_session
from assembl.models import Content
assert not ('body' in Content.__table__.c or 'subject' in Content.__table__.c), \
"Comment out the body and subject from Content to run the back migration"
assert (
'body' not in Content.__table__.c
and 'subject' not in Content.__table__.c
), "Comment out the body and subject from Content to run the back migration"

maparent marked this conversation as resolved.
Show resolved Hide resolved
dbsession = get_session()
try:
dbsession.execute("SPARQL drop quad map quadnames:col_pattern_Content_subject")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ def downgrade(pyramid_env):
prov_to_dom = {
id: old_domains[prov]
for (id, prov) in providers.items()}
case_clause = "CASE provider_id %s END" % "\n ".join([
case_clause = "CASE provider_id %s END" % "\n ".join(
"WHEN %d THEN '%s'" % (id, dom)
for (id, dom) in prov_to_dom.items()])
for (id, dom) in prov_to_dom.items()
)

maparent marked this conversation as resolved.
Show resolved Hide resolved
db.execute("""INSERT INTO idprovider_agent_account
(id, provider_id, username, userid, profile_info, picture_url,
domain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def upgrade(pyramid_env):
lang = candidate_langs[0]

def as_lang_string(text):
ls = m.LangString.create(text, lang)
return ls
return m.LangString.create(text, lang)
maparent marked this conversation as resolved.
Show resolved Hide resolved

if title:
announcement.title = as_lang_string(title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def upgrade(pyramid_env):
lang = candidate_langs[0]

def as_lang_string(text):
ls = m.LangString.create(text, lang)
return ls
return m.LangString.create(text, lang)
maparent marked this conversation as resolved.
Show resolved Hide resolved

if subject:
synthesis.subject = as_lang_string(subject)
Expand Down
16 changes: 9 additions & 7 deletions assembl/alembic/versions/f7d61062eccf_multi_extracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def downgrade(pyramid_env):
FROM extract
LEFT OUTER JOIN idea_content_link as icl ON (icl.extract_id = extract.id)
WHERE icl.id IS NULL
""")
""")
maparent marked this conversation as resolved.
Show resolved Hide resolved
connected_extracts = list(db.execute(
"""SELECT id, extract_id from idea_content_link
WHERE extract_id IS NOT NULL"""))
Expand All @@ -95,16 +95,18 @@ def downgrade(pyramid_env):
duplicates = set()
for e, icls in by_extract.items():
if len(icls) > 1:
if e in icls:
keep = e
else:
keep = min(*icls)
keep = e if e in icls else min(*icls)
dups = set(icls)
dups.remove(keep)
duplicates.update(dups)
if duplicates:
db.execute("DELETE FROM idea_content_link WHERE id IN (%s)" % (
",".join([str(x) for x in duplicates])))
db.execute(
(
"DELETE FROM idea_content_link WHERE id IN (%s)"
% ",".join(str(x) for x in duplicates)
)
)

connected_extracts = [(icl, e) for (icl, e) in connected_extracts
if icl not in duplicates]
mismatched = [(icl, e) for (icl, e) in connected_extracts if icl != e]
Expand Down
14 changes: 5 additions & 9 deletions assembl/auth/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ def get_user(request):
user = 0
if user is 0:
logged_in = request.unauthenticated_userid
if logged_in:
request._user = User.get(logged_in)
else:
request._user = None
request._user = User.get(logged_in) if logged_in else None
maparent marked this conversation as resolved.
Show resolved Hide resolved
return request._user


Expand Down Expand Up @@ -181,10 +178,9 @@ def discussion_id_from_request(request):
"""Obtain the discussion_id from the request,
possibly without fetching the discussion"""
from assembl.views.traversal import BaseContext
if request.matchdict:
if 'discussion_id' in request.matchdict:
discussion_id = int(request.matchdict['discussion_id'])
return discussion_id
if request.matchdict and 'discussion_id' in request.matchdict:
discussion_id = int(request.matchdict['discussion_id'])
return discussion_id
maparent marked this conversation as resolved.
Show resolved Hide resolved
if getattr(request, "context", None) and isinstance(
request.context, BaseContext):
discussion_id = request.context.get_discussion_id()
Expand Down Expand Up @@ -647,7 +643,7 @@ def add_multiple_users_csv(
name, email, None, None, True, localrole=with_role,
discussion=discussion_id, change_old_password=False)
status_in_discussion = None
if send_password_change and not (created_user or created_localrole):
if send_password_change and not created_user and not created_localrole:
maparent marked this conversation as resolved.
Show resolved Hide resolved
status_in_discussion = user.get_status_in_discussion(discussion_id)
if send_password_change and (
created_user or created_localrole or (
Expand Down
4 changes: 2 additions & 2 deletions assembl/fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,13 +685,13 @@ def build_virtualenv():
# and that sometimes precludes building python modules.
bcfile = "/usr/local/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/distutils.cfg"
vefile = env.venvpath + "/lib/python3.6/distutils/distutils.cfg"
sec = "build_ext"
if exists(bcfile):
brew_config = SafeConfigParser()
brew_config.read(bcfile)
venv_config = SafeConfigParser()
if exists(vefile):
venv_config.read(vefile)
sec = "build_ext"
maparent marked this conversation as resolved.
Show resolved Hide resolved
if (brew_config.has_section(sec) and
not venv_config.has_section(sec)):
venv_config.add_section(sec)
Expand Down Expand Up @@ -955,14 +955,14 @@ def update_node(force_reinstall=False):
Install node and npm to a known-good version
"""
node_version = '12.18.2'
npm_version = '6.14.5'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function separate_pip_install.update_node refactored with the following changes:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable related to previous variable, refusing.

with settings(warn_only=True), hide('running', 'stdout'):
node_version_cmd_result = venvcmd("node --version")
if force_reinstall or "v"+node_version not in node_version_cmd_result.split():
print(cyan('Upgrading node'))
#Because otherwise node may be busy
circus_process_stop('dev:webpack')
run("rm -rf "+join(env.venvpath, "lib/node_modules"))
npm_version = '6.14.5'
venvcmd(f"nodeenv --node={node_version} --npm={npm_version} --python-virtualenv assembl/static")
with cd(get_node_base_path()):
venvcmd("npm install --no-save reinstall -g", chdir=False)
Expand Down
16 changes: 7 additions & 9 deletions assembl/lib/sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def dispose_sqlengines():
db_schema = None
_metadata = None
Base = None
class_registry = dict()
class_registry = {}
maparent marked this conversation as resolved.
Show resolved Hide resolved
aliased_class_registry = None


Expand Down Expand Up @@ -1583,10 +1583,12 @@ def apply_side_effects_without_json(self, context=None, request=None):
collection = sub_i_ctx.__parent__.collection
parent_instance = sub_i_ctx.__parent__.parent_instance
attr = collection.get_attribute(parent_instance)
if isinstance(attr, list):
if sub_instance not in attr:
collection.on_new_instance(self, sub_instance)
elif attr != sub_instance:
if (
isinstance(attr, list)
and sub_instance not in attr
or not isinstance(attr, list)
and attr != sub_instance
):
maparent marked this conversation as resolved.
Show resolved Hide resolved
collection.on_new_instance(self, sub_instance)
self.db.add(sub_instance)

Expand Down Expand Up @@ -1651,10 +1653,6 @@ def _do_local_update_from_json(
self.__class__.__name__))
setter(self, value)
continue
elif parse_instruction[0] == "'":
if value != parse_instruction[1:]:
raise HTTPBadRequest("%s should be %s'" % (
key, parse_instruction))
maparent marked this conversation as resolved.
Show resolved Hide resolved
else:
key = parse_instruction
accessor = None
Expand Down
5 changes: 1 addition & 4 deletions assembl/lib/text_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ def add_simple_text_search(query, text_columns, keywords, include_rank=True):
filters = [func.to_tsvector(fts_config, column).match(
keywords_j, postgresql_regconfig='simple')
for column in text_columns]
if len(filters) > 1:
filter = or_(*filters)
else:
filter = filters[0]
filter = or_(*filters) if len(filters) > 1 else filters[0]
maparent marked this conversation as resolved.
Show resolved Hide resolved
query = query.filter(filter)
if include_rank:
ranks = [func.ts_rank(
Expand Down
8 changes: 4 additions & 4 deletions assembl/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ def merge(self, other_profile):
other_account.merge(my_account)
other_account.profile = self
session.delete(my_account)
elif (isinstance(other_account, EmailAccount) and
other_account.email.lower() in my_social_emails):
pass
else:
elif (
not isinstance(other_account, EmailAccount)
or other_account.email.lower() not in my_social_emails
):
maparent marked this conversation as resolved.
Show resolved Hide resolved
other_account.profile = self
if other_profile.name and not self.name:
self.name = other_profile.name
Expand Down
6 changes: 0 additions & 6 deletions assembl/models/discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,12 +773,6 @@ def add_facebook_source_id(inst_ctx, ctx):
# post_id = data.get('post_id', None)
# fb_post_id = data.get('facebook_post_id', None)
raise NotImplementedError("TODO")
post_id = source.sink_post_id
cs = ContentSourceIDs(source=source,
post_id=post_id,
message_id_in_source=fb_post_id)
yield InstanceContext(
inst_ctx['pushed_messages'], cs)
Comment on lines -776 to -781
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Discussion.extra_collections.add_facebook_source_id refactored with the following changes:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is indicative of eventual intent. Stet.


return (AllUsersCollection(cls),
AllPubFlowsCollection(cls),
Expand Down
Loading