py3 filter->list(filter

This commit is contained in:
j 2017-02-16 14:24:51 +01:00
parent 2eafeff5f2
commit 12f3901c9a
17 changed files with 48 additions and 48 deletions

View file

@ -31,7 +31,7 @@ class Command(BaseCommand):
username, public_id, layer_id, filename = args username, public_id, layer_id, filename = args
user = User.objects.get(username=username) user = User.objects.get(username=username)
item = Item.objects.get(public_id=public_id) item = Item.objects.get(public_id=public_id)
layer = filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers'])[0] layer = list(filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers']))[0]
if filename.endswith('.vtt'): if filename.endswith('.vtt'):
annotations = ox.vtt.load(filename) annotations = ox.vtt.load(filename)
@ -53,7 +53,7 @@ class Command(BaseCommand):
value=a['value']) value=a['value'])
annotation.save() annotation.save()
#update facets if needed #update facets if needed
if filter(lambda f: f['id'] == layer_id, settings.CONFIG['filters']): if list(filter(lambda f: f['id'] == layer_id, settings.CONFIG['filters'])):
item.update_layer_facet(layer_id) item.update_layer_facet(layer_id)
Item.objects.filter(id=item.id).update(modified=annotation.modified) Item.objects.filter(id=item.id).update(modified=annotation.modified)
annotation.item.modified = annotation.modified annotation.item.modified = annotation.modified

View file

@ -36,7 +36,7 @@ def get_super_matches(obj, model):
def get_matches(obj, model, layer_type, qs=None): def get_matches(obj, model, layer_type, qs=None):
super_matches = obj.get_super_matches() super_matches = obj.get_super_matches()
exact = [l['id'] for l in filter(lambda l: l['type'] == layer_type, settings.CONFIG['layers'])] exact = [l['id'] for l in list(filter(lambda l: l['type'] == layer_type, settings.CONFIG['layers']))]
if exact: if exact:
q = Q(value__iexact=obj.name) q = Q(value__iexact=obj.name)
for name in obj.alternativeNames: for name in obj.alternativeNames:
@ -46,7 +46,7 @@ def get_matches(obj, model, layer_type, qs=None):
f = None f = None
has_type = 'has%ss' % layer_type.capitalize() has_type = 'has%ss' % layer_type.capitalize()
contains = [l['id'] for l in filter(lambda l: l.get(has_type), settings.CONFIG['layers'])] contains = [l['id'] for l in list(filter(lambda l: l.get(has_type), settings.CONFIG['layers']))]
if contains: if contains:
name = ox.decode_html(obj.name) name = ox.decode_html(obj.name)
name = unicodedata.normalize('NFKD', name).lower() name = unicodedata.normalize('NFKD', name).lower()

View file

@ -18,7 +18,7 @@ def add_annotations(data):
from user.models import User from user.models import User
item = Item.objects.get(public_id=data['item']) item = Item.objects.get(public_id=data['item'])
layer_id = data['layer'] layer_id = data['layer']
layer = filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers']) layer = list(filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers']))
if not layer: if not layer:
return False return False
else: else:
@ -61,7 +61,7 @@ def update_item(id, force=False):
Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete() Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete()
#update facets if needed #update facets if needed
with transaction.atomic(): with transaction.atomic():
if filter(lambda f: f['id'] == a.layer and f.get('filter'), settings.CONFIG['itemKeys']): if list(filter(lambda f: f['id'] == a.layer and f.get('filter'), settings.CONFIG['itemKeys'])):
a.item.update_layer_facet(a.layer) a.item.update_layer_facet(a.layer)
Item.objects.filter(id=a.item.id).update(modified=a.modified) Item.objects.filter(id=a.item.id).update(modified=a.modified)
a.item.modified = a.modified a.item.modified = a.modified

View file

@ -106,7 +106,7 @@ def update(request, data):
file__available=False, file__available=False,
file__wanted=True)] file__wanted=True)]
if filter(lambda l: l['id'] == 'subtitles', settings.CONFIG['layers']): if list(filter(lambda l: l['id'] == 'subtitles', settings.CONFIG['layers'])):
qs = files.filter( qs = files.filter(
file__is_subtitle=True, file__is_subtitle=True,
file__available=False file__available=False

View file

@ -135,7 +135,7 @@ class ClipManager(Manager):
layer_ids = [k['id'] for k in settings.CONFIG['layers']] layer_ids = [k['id'] for k in settings.CONFIG['layers']]
keys = layer_ids + ['annotations', 'text', '*'] keys = layer_ids + ['annotations', 'text', '*']
conditions = data.get('query', {}).get('conditions', []) conditions = data.get('query', {}).get('conditions', [])
conditions = filter(lambda c: c['key'] in keys, conditions) conditions = list(filter(lambda c: c['key'] in keys, conditions))
operator = data.get('query', {}).get('operator', '&') operator = data.get('query', {}).get('operator', '&')
def parse(condition): def parse(condition):
@ -194,7 +194,7 @@ class ClipManager(Manager):
if 'keys' in data: if 'keys' in data:
layer_ids = [k['id'] for k in settings.CONFIG['layers']] layer_ids = [k['id'] for k in settings.CONFIG['layers']]
for l in filter(lambda k: k in layer_ids, data['keys']): for l in list(filter(lambda k: k in layer_ids, data['keys'])):
qs = qs.filter(**{l: True}) qs = qs.filter(**{l: True})
#anonymous can only see public clips #anonymous can only see public clips
if not user or user.is_anonymous(): if not user or user.is_anonymous():

View file

@ -102,8 +102,8 @@ def findClips(request, data):
entity_layer_ids = [k['id'] for k in layers if k['type'] == 'entity'] entity_layer_ids = [k['id'] for k in layers if k['type'] == 'entity']
subtitles = utils.get_by_key(layers, 'isSubtitles', True) subtitles = utils.get_by_key(layers, 'isSubtitles', True)
layer_ids = [k['id'] for k in layers] layer_ids = [k['id'] for k in layers]
keys = filter(lambda k: k not in layer_ids + ['annotations'], data['keys']) keys = list(filter(lambda k: k not in layer_ids + ['annotations'], data['keys']))
if filter(lambda k: k not in models.Clip.clip_keys, keys): if list(filter(lambda k: k not in models.Clip.clip_keys, keys)):
qs = qs.select_related('item__sort') qs = qs.select_related('item__sort')
clips = {} clips = {}
@ -151,7 +151,7 @@ def findClips(request, data):
clip__in=clips) clip__in=clips)
add_annotations('annotations', aqs, True) add_annotations('annotations', aqs, True)
for layer in filter(lambda l: l in keys, layer_ids): for layer in list(filter(lambda l: l in keys, layer_ids)):
aqs = Annotation.objects.filter(layer=layer, clip__in=clips) aqs = Annotation.objects.filter(layer=layer, clip__in=clips)
add_annotations(layer, aqs) add_annotations(layer, aqs)
elif 'position' in query: elif 'position' in query:

View file

@ -104,7 +104,7 @@ class Document(models.Model):
def update_facet_values(self, key, current_values): def update_facet_values(self, key, current_values):
current_sortvalues = set([value.lower() for value in current_values]) current_sortvalues = set([value.lower() for value in current_values])
saved_values = [i.value.lower() for i in Facet.objects.filter(document=self, key=key)] saved_values = [i.value.lower() for i in Facet.objects.filter(document=self, key=key)]
removed_values = filter(lambda i: i not in current_sortvalues, saved_values) removed_values = list(filter(lambda i: i not in current_sortvalues, saved_values))
if removed_values: if removed_values:
q = Q() q = Q()
@ -208,7 +208,7 @@ class Document(models.Model):
value = len(value.split(' ')) if value else 0 value = len(value.split(' ')) if value else 0
return value return value
for key in filter(lambda k: k.get('sort', False), settings.CONFIG['documentKeys']): for key in list(filter(lambda k: k.get('sort', False), settings.CONFIG['documentKeys'])):
name = key['id'] name = key['id']
if name not in self.base_keys: if name not in self.base_keys:
source = name source = name
@ -737,7 +737,7 @@ attrs = {
'document': models.OneToOneField('Document', related_name='sort', primary_key=True), 'document': models.OneToOneField('Document', related_name='sort', primary_key=True),
'created': models.DateTimeField(null=True, blank=True, db_index=True), 'created': models.DateTimeField(null=True, blank=True, db_index=True),
} }
for key in filter(lambda k: k.get('sort', False) or k['type'] in ('integer', 'time', 'float', 'date', 'enum'), settings.CONFIG['documentKeys']): for key in list(filter(lambda k: k.get('sort', False) or k['type'] in ('integer', 'time', 'float', 'date', 'enum'), settings.CONFIG['documentKeys'])):
name = key['id'] name = key['id']
sort_type = key.get('sortType', key['type']) sort_type = key.get('sortType', key['type'])
if isinstance(sort_type, list): if isinstance(sort_type, list):

View file

@ -231,8 +231,8 @@ def getEvents(request, data):
see: getPlaces see: getPlaces
''' '''
response = json_response({}) response = json_response({})
layers = [l['id'] for l in filter(lambda l: l['type'] == 'event', layers = [l['id'] for l in list(filter(lambda l: l['type'] == 'event',
settings.CONFIG['layers'])] settings.CONFIG['layers']))]
items = models.Annotation.objects.filter(layer__in=layers, items = models.Annotation.objects.filter(layer__in=layers,
events__id=None).order_by('value') events__id=None).order_by('value')
items = items.values('value').annotate(Count('value')) items = items.values('value').annotate(Count('value'))

View file

@ -81,7 +81,7 @@ def get_item(info, user=None):
'director': info.get('director', []), 'director': info.get('director', []),
} }
if filter(lambda k: k['id'] == 'year', settings.CONFIG['itemKeys']): if list(filter(lambda k: k['id'] == 'year', settings.CONFIG['itemKeys'])):
item_data['year'] = info.get('year', '') or '' item_data['year'] = info.get('year', '') or ''
# add additional item metadata parsed from path # add additional item metadata parsed from path
@ -245,16 +245,16 @@ class Item(models.Model):
if 'groups' in data: if 'groups' in data:
groups = data.pop('groups') groups = data.pop('groups')
if isinstance(groups, list): if isinstance(groups, list):
groups = filter(lambda g: g.strip(), groups) groups = list(filter(lambda g: g.strip(), groups))
groups = [ox.escape_html(g) for g in groups] groups = [ox.escape_html(g) for g in groups]
for g in self.groups.exclude(name__in=groups): for g in self.groups.exclude(name__in=groups):
self.groups.remove(g) self.groups.remove(g)
current_groups = [g.name for g in self.groups.all()] current_groups = [g.name for g in self.groups.all()]
for g in filter(lambda g: g not in current_groups, groups): for g in list(filter(lambda g: g not in current_groups, groups)):
group, created = Group.objects.get_or_create(name=g) group, created = Group.objects.get_or_create(name=g)
self.groups.add(group) self.groups.add(group)
keys = [k['id'] for k in keys = [k['id'] for k in
filter(lambda i: i.get('description'), settings.CONFIG['itemKeys'])] list(filter(lambda i: i.get('description'), settings.CONFIG['itemKeys']))]
for k in keys: for k in keys:
key = '%sdescription' % k key = '%sdescription' % k
if key in data: if key in data:
@ -299,7 +299,7 @@ class Item(models.Model):
else: else:
self.data[key] = ox.escape_html(data[key]) self.data[key] = ox.escape_html(data[key])
p = self.save() p = self.save()
if not settings.USE_IMDB and filter(lambda k: k in self.poster_keys, data): if not settings.USE_IMDB and list(filter(lambda k: k in self.poster_keys, data)):
p = tasks.update_poster.delay(self.public_id) p = tasks.update_poster.delay(self.public_id)
return p return p
@ -332,7 +332,7 @@ class Item(models.Model):
if i['id'] in known: if i['id'] in known:
i['item'] = i['id'] i['item'] = i['id']
i['title'] = known[i['id']] i['title'] = known[i['id']]
c[t] = filter(lambda x: x['title'], c[t]) c[t] = list(filter(lambda x: x['title'], c[t]))
if not c[t]: if not c[t]:
del c[t] del c[t]
return c return c
@ -409,7 +409,7 @@ class Item(models.Model):
# update defaults # update defaults
if settings.USE_IMDB: if settings.USE_IMDB:
defaults = filter(lambda k: 'default' in k, settings.CONFIG['itemKeys']) defaults = list(filter(lambda k: 'default' in k, settings.CONFIG['itemKeys']))
for k in defaults: for k in defaults:
if len(self.public_id) == 7: if len(self.public_id) == 7:
if k['id'] in self.data and self.data[k['id']] == k['default']: if k['id'] in self.data and self.data[k['id']] == k['default']:
@ -657,16 +657,16 @@ class Item(models.Model):
i['posterFrame'] = self.poster_frame i['posterFrame'] = self.poster_frame
dkeys = [k['id'] for k in dkeys = [k['id'] for k in
filter(lambda i: i.get('description'), settings.CONFIG['itemKeys'])] list(filter(lambda i: i.get('description'), settings.CONFIG['itemKeys']))]
if keys: if keys:
dkeys = filter(lambda k: k in keys, dkeys) dkeys = list(filter(lambda k: k in keys, dkeys))
for key in dkeys: for key in dkeys:
k = list(filter(lambda i: i['id'] == key, settings.CONFIG['itemKeys'])) k = list(filter(lambda i: i['id'] == key, settings.CONFIG['itemKeys']))
if isinstance((k and k[0].get('type') or ''), list): if isinstance((k and k[0].get('type') or ''), list):
i['%sdescription' % key] = {} i['%sdescription' % key] = {}
if key == 'name': if key == 'name':
values = [] values = []
for ikey in filter(lambda i: i.get('sortType') == 'person', settings.CONFIG['itemKeys']): for ikey in list(filter(lambda i: i.get('sortType') == 'person', settings.CONFIG['itemKeys'])):
values += i.get(ikey['id'], []) values += i.get(ikey['id'], [])
values = list(set(values)) values = list(set(values))
else: else:
@ -822,8 +822,8 @@ class Item(models.Model):
elif key == 'character': elif key == 'character':
values = self.get('cast', '') values = self.get('cast', '')
if values: if values:
values = filter(lambda x: x.strip(), values = list(filter(lambda x: x.strip(),
[f['character'] for f in values]) [f['character'] for f in values]))
values = list(set(values)) values = list(set(values))
elif key == 'name': elif key == 'name':
values = [] values = []
@ -976,7 +976,7 @@ class Item(models.Model):
s.timesaccessed = 0 s.timesaccessed = 0
s.accessed = self.accessed.aggregate(Max('access'))['access__max'] s.accessed = self.accessed.aggregate(Max('access'))['access__max']
for key in filter(lambda k: k.get('sort', False), settings.CONFIG['itemKeys']): for key in list(filter(lambda k: k.get('sort', False), settings.CONFIG['itemKeys'])):
name = key['id'] name = key['id']
source = name source = name
sort_type = key.get('sortType', key['type']) sort_type = key.get('sortType', key['type'])
@ -1042,8 +1042,8 @@ class Item(models.Model):
if at: if at:
current_values += [a[0] for a in at] current_values += [a[0] for a in at]
elif key == 'character': elif key == 'character':
current_values = filter(lambda x: x.strip(), current_values = list(filter(lambda x: x.strip(),
[f['character'] for f in self.get('cast', [])]) [f['character'] for f in self.get('cast', [])]))
current_values = [item for sublist in [x.split(' / ') for x in current_values] current_values = [item for sublist in [x.split(' / ') for x in current_values]
for item in sublist] for item in sublist]
elif key == 'name': elif key == 'name':
@ -1089,7 +1089,7 @@ class Item(models.Model):
def update_facet_values(self, key, current_values): def update_facet_values(self, key, current_values):
current_sortvalues = set([value.lower() for value in current_values]) current_sortvalues = set([value.lower() for value in current_values])
saved_values = [i.value.lower() for i in Facet.objects.filter(item=self, key=key)] saved_values = [i.value.lower() for i in Facet.objects.filter(item=self, key=key)]
removed_values = filter(lambda i: i not in current_sortvalues, saved_values) removed_values = list(filter(lambda i: i not in current_sortvalues, saved_values))
if removed_values: if removed_values:
q = Q() q = Q()
@ -1736,7 +1736,7 @@ attrs = {
'height': models.BigIntegerField(null=True, blank=True, db_index=True), 'height': models.BigIntegerField(null=True, blank=True, db_index=True),
'created': models.DateTimeField(null=True, blank=True, db_index=True), 'created': models.DateTimeField(null=True, blank=True, db_index=True),
} }
for key in filter(lambda k: k.get('sort', False) or k['type'] in ('integer', 'time', 'float', 'date', 'enum'), settings.CONFIG['itemKeys']): for key in list(filter(lambda k: k.get('sort', False) or k['type'] in ('integer', 'time', 'float', 'date', 'enum'), settings.CONFIG['itemKeys'])):
name = key['id'] name = key['id']
name = {'id': 'public_id'}.get(name, name) name = {'id': 'public_id'}.get(name, name)
sort_type = key.get('sortType', key['type']) sort_type = key.get('sortType', key['type'])

View file

@ -26,7 +26,7 @@ def cronjob(**kwargs):
def update_random_sort(): def update_random_sort():
from . import models from . import models
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']): if list(filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys'])):
random.seed() random.seed()
ids = [f['item'] for f in models.ItemSort.objects.values('item')] ids = [f['item'] for f in models.ItemSort.objects.values('item')]
random.shuffle(ids) random.shuffle(ids)
@ -36,7 +36,7 @@ def update_random_sort():
n += 1 n += 1
def update_random_clip_sort(): def update_random_clip_sort():
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']): if list(filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys'])):
with transaction.atomic(): with transaction.atomic():
cursor = connection.cursor() cursor = connection.cursor()
for row in ( for row in (

View file

@ -116,7 +116,7 @@ def join_tiles(source_paths, durations, target_path):
offset = 0 offset = 0
for i, path in enumerate(source_paths): for i, path in enumerate(source_paths):
file_info = map(get_file_info, os.listdir(path)) file_info = map(get_file_info, os.listdir(path))
file_info = filter(lambda x: x is not None, file_info) file_info = list(filter(lambda x: x is not None, file_info))
files = {} files = {}
for info in sorted(file_info, key=lambda x: x['index']): for info in sorted(file_info, key=lambda x: x['index']):
mode = info['mode'] mode = info['mode']
@ -218,7 +218,7 @@ def split_tiles(path, paths, durations):
def is_timeline_file(file_name): def is_timeline_file(file_name):
return file_name.startswith('timeline') and file_name.endswith('.png') return file_name.startswith('timeline') and file_name.endswith('.png')
file_names = filter(is_timeline_file, os.listdir(path)) file_names = list(filter(is_timeline_file, os.listdir(path)))
tiles = {} tiles = {}
for file_name in file_names: for file_name in file_names:
mode = re.split('\d+', file_name[8:])[0] mode = re.split('\d+', file_name[8:])[0]

View file

@ -729,7 +729,7 @@ def lookup(request, data):
i = None i = None
if 'id' in data: if 'id' in data:
i = models.Item.objects.get(public_id=data['id']) i = models.Item.objects.get(public_id=data['id'])
elif not filter(None, [d not in ('title', 'year', 'director') for d in data.keys()]): elif not list(filter(None, [d not in ('title', 'year', 'director') for d in data.keys()])):
qs = models.Item.objects.find({'query': { qs = models.Item.objects.find({'query': {
'conditions': [ 'conditions': [
{'key': key, 'value': data[key], 'operator': '=='} for key in data {'key': key, 'value': data[key], 'operator': '=='} for key in data

View file

@ -108,7 +108,7 @@ class ApiActions(dict):
else: else:
f = self[name] f = self[name]
if name != 'api' and hasattr(f, 'func_closure') and f.func_closure: if name != 'api' and hasattr(f, 'func_closure') and f.func_closure:
fc = filter(lambda c: hasattr(c.cell_contents, '__call__'), f.func_closure) fc = list(filter(lambda c: hasattr(c.cell_contents, '__call__'), f.func_closure))
f = fc[len(fc)-1].cell_contents f = fc[len(fc)-1].cell_contents
if PY2: if PY2:
info = f.func_code.co_filename[len(settings.PROJECT_ROOT)+1:] info = f.func_code.co_filename[len(settings.PROJECT_ROOT)+1:]

View file

@ -121,7 +121,7 @@ def editPlace(request, data):
names = [names] names = [names]
names = [ox.escape_html(n) for n in names] names = [ox.escape_html(n) for n in names]
alternative_names = [ox.escape_html(n) for n in data.get('alternativeNames', [])] alternative_names = [ox.escape_html(n) for n in data.get('alternativeNames', [])]
alternative_names = filter(lambda n: n.strip(), alternative_names) alternative_names = list(filter(lambda n: n.strip(), alternative_names))
if place.editable(request.user): if place.editable(request.user):
conflict = False conflict = False
conflict_names = [] conflict_names = []
@ -284,8 +284,8 @@ def getPlaces(request, data):
see: getEvents see: getEvents
''' '''
response = json_response({}) response = json_response({})
layers = [l['id'] for l in filter(lambda l: l['type'] == 'place', layers = [l['id'] for l in list(filter(lambda l: l['type'] == 'place',
settings.CONFIG['layers'])] settings.CONFIG['layers']))]
items = models.Annotation.objects.filter(layer__in=layers, items = models.Annotation.objects.filter(layer__in=layers,
places__id=None).order_by('value') places__id=None).order_by('value')
items = items.values('value').annotate(Count('value')) items = items.values('value').annotate(Count('value'))

View file

@ -60,7 +60,7 @@ def get_sequences(path, position=0):
sequences[mode] = [] sequences[mode] = []
position_start = position position_start = position
fps = 25 fps = 25
file_names = filter(lambda x: 'timelinedata8p' in x, os.listdir(path)) file_names = list(filter(lambda x: 'timelinedata8p' in x, os.listdir(path)))
file_names = sorted(file_names, key=lambda x: int(x[14:-4])) file_names = sorted(file_names, key=lambda x: int(x[14:-4]))
file_names = list(map(lambda x: path + x, file_names)) file_names = list(map(lambda x: path + x, file_names))
for file_name in file_names: for file_name in file_names:
@ -84,7 +84,7 @@ class DataTimeline():
fps = 25 fps = 25
def __init__(self, path): def __init__(self, path):
file_names = filter(lambda x: 'timelinedata8p' in x, os.listdir(path)) file_names = list(filter(lambda x: 'timelinedata8p' in x, os.listdir(path)))
file_names = sorted(file_names, key=lambda x: int(x[14:-4])) file_names = sorted(file_names, key=lambda x: int(x[14:-4]))
file_names = list(map(lambda x: path + x, file_names)) file_names = list(map(lambda x: path + x, file_names))
self.file_names = file_names self.file_names = file_names

View file

@ -28,7 +28,7 @@ def update_statistics():
for i in models.SessionData.objects.filter(level__gte=0).values('session_key')] for i in models.SessionData.objects.filter(level__gte=0).values('session_key')]
for chunk in chunker(ids, 100, None): for chunk in chunker(ids, 100, None):
chunk = filter(None, chunk) chunk = list(filter(None, chunk))
for u in models.SessionData.objects.filter(pk__in=chunk): for u in models.SessionData.objects.filter(pk__in=chunk):
stats.add(u.json()) stats.add(u.json())
Settings.set('statistics', stats) Settings.set('statistics', stats)

View file

@ -370,12 +370,12 @@ def editUser(request, data):
if 'groups' in data: if 'groups' in data:
groups = data['groups'] groups = data['groups']
if isinstance(groups, list): if isinstance(groups, list):
groups = filter(lambda g: g.strip(), groups) groups = list(filter(lambda g: g.strip(), groups))
groups = [ox.escape_html(g) for g in groups] groups = [ox.escape_html(g) for g in groups]
for g in user.groups.exclude(name__in=groups): for g in user.groups.exclude(name__in=groups):
user.groups.remove(g) user.groups.remove(g)
current_groups = [g.name for g in user.groups.all()] current_groups = [g.name for g in user.groups.all()]
for g in filter(lambda g: g not in current_groups, groups): for g in list(filter(lambda g: g not in current_groups, groups)):
group, created = Group.objects.get_or_create(name=g) group, created = Group.objects.get_or_create(name=g)
user.groups.add(group) user.groups.add(group)
if 'username' in data: if 'username' in data: