Skip to content

Instantly share code, notes, and snippets.

@crodjer
Created April 5, 2011 06:37
Show Gist options
  • Save crodjer/903129 to your computer and use it in GitHub Desktop.
Save crodjer/903129 to your computer and use it in GitHub Desktop.
Empty checks for empty list should not be done by comparing lengths and in the teamvideo model a part of code ( a for loop at https://github.com/8planes/mirosubs/blob/master/apps/teams/models.py#L356) seem to be placed at wrong indent.
diff --git a/apps/teams/models.py b/apps/teams/models.py
index 014b7e1..c3d185d 100644
--- a/apps/teams/models.py
+++ b/apps/teams/models.py
@@ -293,7 +293,7 @@ class TeamVideo(models.Model):
team_video=self,
subtitle_language_0__language=lang0,
language_1=lang1)
- tvlp = None if len(tvlps) == 0 else tvlps[0]
+ tvlp = None if not tvlps else tvlps[0]
if not tvlp and percent_complete != -1:
tvlp = TeamVideoLanguagePair(
team_video=self,
@@ -314,9 +314,7 @@ class TeamVideo(models.Model):
def _update_tvlp_for_languages(self, lang0, lang1, langs):
sl0_list = langs.get(lang0, [])
- sl1_list = langs.get(lang1, [])
- if len(sl1_list) == 0:
- sl1_list = [None]
+ sl1_list = langs.get(lang1, [None])
for sl0 in sl0_list:
for sl1 in sl1_list:
self._update_team_video_language_pair(lang0, sl0, lang1, sl1)
@@ -350,11 +348,9 @@ class TeamVideo(models.Model):
langs = self.video.subtitle_language_dict()
for lang in lang_code_list:
- sl1_list = langs.get(lang, [])
- if len(sl1_list) == 0:
- sl1_list = [None]
- for sl1 in sl1_list:
- self._update_team_video_language_pair(sl.language, sl, lang, sl1)
+ sl1_list = langs.get(lang, [None])
+ for sl1 in sl1_list:
+ self._update_team_video_language_pair(sl.language, sl, lang, sl1)
for sl0 in self.video.subtitlelanguage_set.all():
self._update_team_video_language_pair(sl0.language, sl0, sl.language, sl)
diff --git a/apps/widget/base_rpc.py b/apps/widget/base_rpc.py
index e5ff654..94879fb 100644
--- a/apps/widget/base_rpc.py
+++ b/apps/widget/base_rpc.py
@@ -79,7 +79,7 @@ class BaseRpc:
updated = packet['updated']
inserted = packet['inserted']
- if len(deleted) == 0 and len(inserted) == 0 and len(updated) == 0:
+ if not (deleted or inserted or updated):
return
for d in deleted:
subtitle_set.remove(subtitle_set.get(subtitle_id=d['subtitle_id']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment