Skip to content

Commit

Permalink
Issue #1071: PyCharm syntax fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
susanodd committed Jan 23, 2024
1 parent 5ad97c1 commit d06e29f
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 129 deletions.
2 changes: 1 addition & 1 deletion signbank/dictionary/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ def get_search_results(self, request, queryset, search_term):
else:
queryset = super(LemmaIdglossTranslationAdmin, self).get_queryset(request)
new_queryset = queryset.filter(Q(text__iregex=search_term))
return (new_queryset, use_distinct)
return new_queryset, use_distinct

def has_add_permission(self, request):
return False
Expand Down
26 changes: 13 additions & 13 deletions signbank/dictionary/adminviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,26 @@ def order_queryset_by_tuple_list(qs, sOrder, sListName, bReversed):
# Get a list of tuples for this sort-order
tpList = list(FieldChoice.objects.filter(field=sListName).values_list('machine_value', 'name'))
# Determine sort order: ascending is default
if (sOrder[0:1] == '-'):
if sOrder[0:1] == '-':
# A starting '-' sign means: descending order
sOrder = sOrder[1:]
def lambda_sort_tuple(x, bReversed):
# Order by the string-values in the tuple list
getattr_sOrder = getattr(x, sOrder)
if getattr_sOrder is None:
# if the field is not set, use the machine value 0 choice
return (True, dict(tpList)[0])
return True, dict(tpList)[0]
elif getattr_sOrder.machine_value in [0,1]:
return (True, dict(tpList)[getattr_sOrder.machine_value])
return True, dict(tpList)[getattr_sOrder.machine_value]
else:
return (bReversed, dict(tpList)[getattr(x, sOrder).machine_value])
return bReversed, dict(tpList)[getattr(x, sOrder).machine_value]

return sorted(qs, key=lambda x: lambda_sort_tuple(x, bReversed), reverse=bReversed)

def order_queryset_by_annotationidglosstranslation(qs, sOrder):
language_code_2char = sOrder[-2:]
sOrderAsc = sOrder
if (sOrder[0:1] == '-'):
if sOrder[0:1] == '-':
# A starting '-' sign means: descending order
sOrderAsc = sOrder[1:]
annotationidglosstranslation = AnnotationIdglossTranslation.objects.filter(gloss=OuterRef('pk')).filter(language__language_code_2char__iexact=language_code_2char).distinct()
Expand All @@ -114,7 +114,7 @@ def order_queryset_by_annotationidglosstranslation(qs, sOrder):
def order_queryset_by_lemmaidglosstranslation(qs, sOrder):
language_code_2char = sOrder[-2:]
sOrderAsc = sOrder
if (sOrder[0:1] == '-'):
if sOrder[0:1] == '-':
# A starting '-' sign means: descending order
sOrderAsc = sOrder[1:]
lemmaidglosstranslation = LemmaIdglossTranslation.objects.filter(lemma=OuterRef('lemma'), language__language_code_2char__iexact=language_code_2char)
Expand All @@ -124,7 +124,7 @@ def order_queryset_by_lemmaidglosstranslation(qs, sOrder):
def order_queryset_by_translation(qs, sOrder):
language_code_2char = sOrder[-2:]
sOrderAsc = sOrder
if (sOrder[0:1] == '-'):
if sOrder[0:1] == '-':
# A starting '-' sign means: descending order
sOrderAsc = sOrder[1:]
translations = Translation.objects.filter(sensetranslation__sense__glosssense__gloss=OuterRef('pk')).filter(language__language_code_2char__iexact=language_code_2char)
Expand Down Expand Up @@ -1670,7 +1670,7 @@ def get_context_data(self, **kwargs):
for language in gl.dataset.translation_languages.all().order_by('id'):
try:
annotation_text = gl.annotationidglosstranslation_set.get(language=language).text
except (ObjectDoesNotExist):
except ObjectDoesNotExist:
annotation_text = gloss_default_annotationidglosstranslation
context['annotation_idgloss'][language] = annotation_text

Expand Down Expand Up @@ -2989,7 +2989,7 @@ def get_context_data(self, **kwargs):
for language in gl.dataset.translation_languages.all():
try:
annotation_translation = gl.annotationidglosstranslation_set.get(language=language).text
except (ValueError):
except ValueError:
annotation_translation = gloss_default_annotationidglosstranslation
context['annotation_idgloss'][language] = annotation_translation

Expand Down Expand Up @@ -4266,7 +4266,7 @@ def get_context_data(self, **kwargs):
change_dataset_permission = get_objects_for_user(self.request.user, 'change_dataset', Dataset)
for dataset in selected_datasets:
if dataset in change_dataset_permission:
dataset_excluded_choices = dataset.exclude_choices.all();
dataset_excluded_choices = dataset.exclude_choices.all()
list_of_excluded_ids = []
for ec in dataset_excluded_choices:
list_of_excluded_ids.append(ec.pk)
Expand Down Expand Up @@ -5143,7 +5143,7 @@ def gloss_ajax_complete(request, prefix):
except ObjectDoesNotExist:
annotationidglosstranslation = g.annotationidglosstranslation_set.get(language=default_language)
default_annotationidglosstranslation = annotationidglosstranslation.text
result.append({'annotation_idgloss': default_annotationidglosstranslation, 'idgloss': g.idgloss, 'sn': g.sn, 'pk': "%s" % (g.id)})
result.append({'annotation_idgloss': default_annotationidglosstranslation, 'idgloss': g.idgloss, 'sn': g.sn, 'pk': "%s" % g.id})

sorted_result = sorted(result, key=lambda x : (x['annotation_idgloss'], len(x['annotation_idgloss'])))

Expand Down Expand Up @@ -5182,7 +5182,7 @@ def morph_ajax_complete(request, prefix):
# if there are results, just grab the first one
default_annotationidglosstranslation = annotationidglosstranslations.first().text
result.append({'annotation_idgloss': default_annotationidglosstranslation, 'idgloss': g.idgloss,
'pk': "%s" % (g.id)})
'pk': "%s" % g.id})

return JsonResponse(result, safe=False)

Expand Down Expand Up @@ -6318,7 +6318,7 @@ def get_queryset(self):

if 'tags[]' in get:
vals = get.getlist('tags[]')
if vals != []:
if vals:
query_parameters['tags[]'] = vals
glosses_with_tag = list(
TaggedItem.objects.filter(tag__name__in=vals).values_list('object_id', flat=True))
Expand Down
2 changes: 1 addition & 1 deletion signbank/dictionary/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ def save(self, commit=True):
# this exception refuses to be put into messages after being caught in LemmaUpdateView
# gives a runtime error
# therefore the exception is caught byt a different message is displayed
raise Exception("Lemma with id %s must have at least one translation."% (self.instance.pk))
raise Exception("Lemma with id %s must have at least one translation." % self.instance.pk)
else:
lemmaidglosstranslation.text = lemma_idgloss_text
lemmaidglosstranslation.save()
Expand Down
8 changes: 4 additions & 4 deletions signbank/dictionary/frequency_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def collect_speaker_age_data(speakers_summary, age_range):
# only show labels for ages that have speakers of that age
speaker_age_data.append(0)

return (speaker_age_data, age_range)
return speaker_age_data, age_range


def collect_variants_data(variants):
Expand All @@ -35,7 +35,7 @@ def collect_variants_data(variants):
# variants data quick access: dictionary mapping variant annotation to speaker data for variant
# sorted variants with keys: sorted list of pairs ( variant annotation, variant object )
if not variants:
return ({}, [])
return {}, []
variants_with_keys = []
if len(variants) > 1:
for v in variants:
Expand All @@ -52,7 +52,7 @@ def collect_variants_data(variants):
for (og_idgloss, variant_of_gloss) in sorted_variants_with_keys:
variants_speaker_data = variant_of_gloss.speaker_data()
variants_data_quick_access[og_idgloss] = variants_speaker_data
return (variants_data_quick_access, sorted_variants_with_keys)
return variants_data_quick_access, sorted_variants_with_keys


def collect_variants_age_range_data(sorted_variants_with_keys, age_range):
Expand All @@ -70,7 +70,7 @@ def collect_variants_age_range_data(sorted_variants_with_keys, age_range):
speaker_age_data_v.append(0)
variants_age_range_distribution_data[variant_idgloss] = speaker_age_data_v

return (variants_age_range_distribution_data, age_range)
return variants_age_range_distribution_data, age_range


def collect_variants_age_sex_raw_percentage(sorted_variants_with_keys, variants_data_quick_access):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def handle(self, *args, **options):
for translation in gloss.translation_set.filter(language=dataset_language).order_by('translation__index'):
if translation.translation != "":
translations.append(translation.translation.text.strip())
translations = (', ').join(sorted(translations))
translations = ', '.join(sorted(translations))
if translations != '':
vals[str(dataset_language)] = translations

Expand Down
Binary file not shown.
42 changes: 21 additions & 21 deletions signbank/dictionary/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def add_video(self, user, videofile, recorded):


def __str__(self):
return (" | ").join(self.get_examplestc_translations())
return " | ".join(self.get_examplestc_translations())


class ExampleSentenceTranslation(models.Model):
Expand Down Expand Up @@ -793,7 +793,7 @@ def get_sense_translations(self):
return [k+": "+v for k, v in sense_translations.items()]

def has_examplesentence_with_video(self):
"Return true if any of the example sentences has a video"
"""Return true if any of the example sentences has a video"""
for examplesentence in self.exampleSentences.all():
if examplesentence.has_video():
return True
Expand Down Expand Up @@ -828,11 +828,11 @@ def get_senses_with_similar_sensetranslations_dict(self, gloss_detail_view):
return sorted(similar_senses, key=lambda d: d['inglosses'])

def ordered_examplesentences(self):
"Return a properly ordered set of examplesentences"
"""Return a properly ordered set of examplesentences"""
return self.exampleSentences.order_by('senseexamplesentence')

def reorder_examplesentences(self):
"when an examplesentence is deleted, they should be reordered"
"""when an examplesentence is deleted, they should be reordered"""
for sentence_i, sentence in enumerate(self.ordered_examplesentences().all()):
sensesentence = SenseExamplesentence.objects.all().get(sense=self, examplesentence=sentence)
sensesentence.order = sentence_i+1
Expand Down Expand Up @@ -1086,14 +1086,14 @@ def get_field(cls, field):
)

def has_sense_with_examplesentence_with_video(self):
"Return true if the sense has any examplesentences that also have a video"
"""Return true if the sense has any examplesentences that also have a video"""
for sense in self.senses.all():
if sense.has_examplesentence_with_video():
return True
return False

def ordered_senses(self):
"Return a properly ordered set of senses"
"""Return a properly ordered set of senses"""
return self.senses.all().order_by('glosssense__order')

sn = models.IntegerField(_("Sign Number"),
Expand Down Expand Up @@ -1496,7 +1496,7 @@ def data_datasets(self):
try:
frequency_regions = self.lemma.dataset.frequency_regions()
except (ObjectDoesNotExist, AttributeError):
return (total_occurrences, data_datasets)
return total_occurrences, data_datasets

frequency_objects = self.glossfrequency_set.all()

Expand Down Expand Up @@ -1532,7 +1532,7 @@ def data_datasets(self):
k_value = len(speakers_per_region[r])
dataset_dict['data'].append(k_value)
data_datasets.append(dataset_dict)
return (total_occurrences, data_datasets)
return total_occurrences, data_datasets

def has_frequency_data(self):

Expand Down Expand Up @@ -1789,7 +1789,7 @@ def gloss_relations(self):
other_relations = self.relation_sources.filter(role__in=['homonym', 'synonyn', 'antonym',
'hyponym', 'hypernym', 'seealso', 'paradigm'])

return (other_relations, variant_relations)
return other_relations, variant_relations

def phonology_matrix_homonymns(self, use_machine_value=False):
# this method uses string representations for Boolean values
Expand Down Expand Up @@ -1881,7 +1881,7 @@ def minimalpairs_objects(self):

empty_handedness = [ str(fc.id) for fc in FieldChoice.objects.filter(field='Handedness', name__in=['-','N/A']) ]

if (handedness_of_this_gloss in empty_handedness or handedness_of_this_gloss == handedness_X):
if handedness_of_this_gloss in empty_handedness or handedness_of_this_gloss == handedness_X:
# ignore gloss with empty or X handedness
return minimalpairs_objects_list

Expand Down Expand Up @@ -2037,7 +2037,7 @@ def homonym_objects(self):

empty_handedness = [ str(fc.id) for fc in FieldChoice.objects.filter(field='Handedness', name__in=['-','N/A']) ]

if (handedness_of_this_gloss in empty_handedness or handedness_of_this_gloss == handedness_X):
if handedness_of_this_gloss in empty_handedness or handedness_of_this_gloss == handedness_X:
# ignore gloss with empty or X handedness
return homonym_objects_list

Expand Down Expand Up @@ -2068,11 +2068,11 @@ def homonym_objects(self):
q_or |= Q(**{comparison2: '0'})
q_or |= Q(**{comparison3: False})
q.add(q_or, q.AND)
elif (value_of_this_field == 'Neutral'):
elif value_of_this_field == 'Neutral':
# Can only match Null, not True or False
comparison = field + '__isnull'
q.add(Q(**{comparison: True}), q.AND)
elif (value_of_this_field == 'True'):
elif value_of_this_field == 'True':
comparison = field + '__exact'
q.add(Q(**{comparison: True}), q.AND)
else:
Expand All @@ -2099,7 +2099,7 @@ def homonyms(self):

if not self.lemma or not self.lemma.dataset:
# take care of glosses without a dataset
return ([], [], [])
return [], [], []

gloss_homonym_relations = self.relation_sources.filter(role='homonym')

Expand All @@ -2119,35 +2119,35 @@ def homonyms(self):

except ObjectDoesNotExist:
print('homonyms: Handedness X is not defined')
return ([], [], [])
return [], [], []

empty_handedness = [ str(fc.id) for fc in FieldChoice.objects.filter(field='Handedness', name__in=['-','N/A']) ]

if handedness_of_this_gloss in empty_handedness or handedness_of_this_gloss == handedness_X:
# ignore gloss with empty or X handedness
return ([], [], [])
return [], [], []

handshape_of_this_gloss = phonology_for_gloss['domhndsh']

empty_handshape = [str(fc.machine_value) for fc in
Handshape.objects.filter(name__in=['-', 'N/A'])]

if handshape_of_this_gloss in empty_handshape:
return ([], [], [])
return [], [], []

homonyms_of_this_gloss = [g for g in self.homonym_objects()]

homonyms_not_saved = []
saved_but_not_homonyms = []

for r in list_of_homonym_relations:
if (not r.target in homonyms_of_this_gloss):
if not r.target in homonyms_of_this_gloss:
saved_but_not_homonyms += [r.target]
for h in homonyms_of_this_gloss:
if (not h in targets_of_homonyms_of_this_gloss):
if not h in targets_of_homonyms_of_this_gloss:
homonyms_not_saved += [h]

return (homonyms_of_this_gloss, homonyms_not_saved, saved_but_not_homonyms)
return homonyms_of_this_gloss, homonyms_not_saved, saved_but_not_homonyms

def get_image_path(self, check_existence=True):
"""Returns the path within the writable and static folder"""
Expand Down Expand Up @@ -2484,7 +2484,7 @@ class DeletedGlossOrMedia(models.Model):
('paradigm', 'Handshape Paradigm')
)

VARIANT_ROLE_CHOICES = (('variant', 'Variant'))
VARIANT_ROLE_CHOICES = ('variant', 'Variant')


# this can be used for phonology and handshape fields
Expand Down
2 changes: 1 addition & 1 deletion signbank/dictionary/templatetags/stylesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def value(value):
"""
Return value unless it's None in which case we return 'No Value Set'
"""
if value == None or value == '':
if value is None or value == '':
return '-'
else:
return value
Expand Down
2 changes: 1 addition & 1 deletion signbank/dictionary/translate_choice_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def choicelist_queryset_to_colors(queryset,ordered=True,id_prefix='_',shortlist=
empty_or_NA[human_value] = choice
continue

if choices_to_exclude == None or choice not in choices_to_exclude:
if choices_to_exclude is None or choice not in choices_to_exclude:
machine_values_seen.append(choice.machine_value)
field_color = getattr(choice, 'field_color')
# this should not happen, but it could be a legacy value that has a #
Expand Down
2 changes: 1 addition & 1 deletion signbank/dictionary/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3115,7 +3115,7 @@ def update_dataset(request, datasetid):
original_value = getattr(dataset,field)

#This is because you cannot concat none to a string in py3
if original_value == None:
if original_value is None:
original_value = ''

# The machine_value (value) representation is also returned to accommodate Hyperlinks to Handshapes in gloss_edit.js
Expand Down
4 changes: 2 additions & 2 deletions signbank/dictionary/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def try_code(request, pk):
for language in gloss.dataset.translation_languages.all():
try:
annotation_text = gloss.annotationidglosstranslation_set.get(language=language).text
except (ObjectDoesNotExist):
except ObjectDoesNotExist:
annotation_text = gloss_default_annotationidglosstranslation
context['annotation_idgloss'][language] = annotation_text

Expand Down Expand Up @@ -806,7 +806,7 @@ def import_csv_create(request):
# check annotation translations
for language in translation_languages:
language_name = getattr(language, settings.DEFAULT_LANGUAGE_HEADER_COLUMN['English'])
annotationidglosstranslation_text = value_dict["Annotation ID Gloss (%s)" % (language_name) ]
annotationidglosstranslation_text = value_dict["Annotation ID Gloss (%s)" % language_name]
annotationidglosstranslations[language] = annotationidglosstranslation_text

annotationtranslation_for_this_text_language = AnnotationIdglossTranslation.objects.filter(gloss__lemma__dataset=dataset,
Expand Down
4 changes: 2 additions & 2 deletions signbank/feedback/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def generalfeedback(request):
if 'comment' in form.cleaned_data:
feedback.comment = form.cleaned_data['comment']

if 'video' in form.cleaned_data and form.cleaned_data['video'] != None:
if 'video' in form.cleaned_data and form.cleaned_data['video'] is not None:
feedback.video = form.cleaned_data['video']

feedback.save()
Expand Down Expand Up @@ -110,7 +110,7 @@ def missingsign(request):
# the form yields a sign language object
fb.signlanguage = form.cleaned_data['signlanguage']

if 'video' in form.cleaned_data and form.cleaned_data['video'] != None:
if 'video' in form.cleaned_data and form.cleaned_data['video'] is not None:
fb.video = form.cleaned_data['video']

# these last two are required either way (video or not)
Expand Down
Loading

0 comments on commit d06e29f

Please sign in to comment.