function
stringlengths
11
56k
repo_name
stringlengths
5
60
features
sequence
def setup(r): #don't create foo r.Create('/foo3', contents=r.fileText) r.Transient('/foo3')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): # NormalizeInterpreterPaths not the purpose of these tests, # and dealing with it running would make tests needlessly # and uselessly more verbose. del self.NormalizeInterpreterPaths self.Create('libhello.c', contents='''
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): del r.NormalizeInterpreterPaths r.Create('%(essentialbindir)s/bash', mode=0755) r.Create('%(essentialbindir)s/conflict', mode=0755) r.Provides('file', '%(essentialbindir)s/(ba)?sh') if Use.ssl: # turn on this use flag; we use this in the tests for flavor # dependent resolution pass
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): del r.NormalizeInterpreterPaths r.Create('%(essentialbindir)s/conflict', mode=0755) if Use.ssl: # turn on this use flag; we use this in the tests for flavor # dependent resolution pass
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): del r.NormalizeInterpreterPaths r.Create('%(essentialbindir)s/script', mode=0755, contents = '#!/bin/bash')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): del r.NormalizeInterpreterPaths r.Create('%(essentiallibdir)s/empty', mode=0644) r.Requires('bash:runtime', '%(essentiallibdir)s/empty')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('%(sysconfdir)s/gconf/schemas/foo') r.Install('/bin/true', '%(bindir)s/gconftool-2', mode=0755) self.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): self.Run('''
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): self.Create("/etc/foo1", contents = "text1") self.Ownership(self.owner, self.group, '.*') self.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): self.Create("/etc/foo1.1", contents = "text1.1") self.Ownership(self.owner, self.group, '.*') self.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): self.Create("/etc/foo1.2", contents = "text1.2") self.Ownership(self.owner, self.group, '.*') self.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): self.Create("/etc/foo1.3", contents = "text1.3") self.Ownership(self.owner, self.group, '.*') self.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): self.Create("/etc/foo2", contents = "text2") self.Ownership(self.owner, self.group, '.*') self.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): self.Create("/etc/foo2.1", contents = "text2.1") self.Ownership(self.owner, self.group, '.*') self.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Run('''
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Run('''
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Run('''
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Run('''
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Run('''
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Run('''
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Run('''
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('%(tagdescriptiondir)s/foo', contents='''file %(taghandlerdir)s/foo
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create(r.paths[0], contents=r.initialFileText) for path in r.paths[1:]: if r.hard: r.Run("ln %%(destdir)s/%s %%(destdir)s/%s" % (r.paths[0], path)) else: r.Run("ln -s %s %%(destdir)s/%s" % (r.paths[0], path))
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create(r.paths[0], contents=r.initialFileText) r.Run("ln %%(destdir)s/%s %%(destdir)s/%s" % (r.paths[0], r.paths[1])) r.Create(r.paths[2], contents=r.initialFileText) r.Run("ln %%(destdir)s/%s %%(destdir)s/%s" % (r.paths[2], r.paths[3]))
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): for path in r.paths: r.Create(path, contents=r.fileText) r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/usr/bin/test', mode=0755) r.Requires('bar:foo', '/usr/bin/test')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/usr/bin/a', mode=0755)
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/usr/bin/b', mode=0755) r.Requires('a:runtime', '/usr/bin/b')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create("/etc/foo", contents = "text 1") r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create("/etc/foo", contents = "text 2") r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): %(flavor)s r.Create('/usr/bin/test%(num)s',contents='''\
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def createRecipe(num, requires=[], fail=False, content='', packageSpecs=[], subPackages = [], version='1.0', localflags=[], flags=[], header='', fileContents='', tag=None, binary=False): reqList = [] for req in requires: reqList.append("'test%d:runtime'" % req) subs = {} subs['requires'] = ', '.join(reqList) subs['version'] = version subs['num'] = num subs['content'] = content subs['fileContents'] = fileContents subs['header'] = header subs['binary'] = binary subpkgStrs = [] flagStrs = [] flavorStrs = [] if localflags and not isinstance(localflags, (tuple, list)): localflags = [localflags] for flag in localflags: flagStr = 'Flags.%s = True' % flag flavorStr = 'if Flags.%s: pass' % flag flagStrs.append(flagStr) flavorStrs.append(flavorStr) if tag: subs['tagspec'] = "r.TagSpec('%s', '/usr/bin/test1')" % tag else: subs['tagspec'] = ''
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('%(essentialbindir)s/foo', mode=0755, contents = 'some text')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Run("mkdir %(destdir)s%(essentialbindir)s") r.Run("ln -s foo %(destdir)s%(essentialbindir)s/foo")
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): if Use.readline: r.Create("/etc/readline", contents = "text 1") if Use.ssl: r.Create("/etc/ssl", contents = "text 1") if not Use.ssl and not Use.readline: r.Create("/etc/none", contents = "text 1") r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): if Use.readline: r.Create("/etc/readline", contents = "text 1") if Use.ssl: r.Create("/etc/ssl", contents = "text 1") if not Use.ssl and not Use.readline: r.Create("/etc/none", contents = "text 1") r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.addSource('localfile')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.addSource('distcc-2.9.tar.bz2') r.addSource('localfile')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.addSource('multilib-sample.tar.bz2') r.addSource('localfile')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.addSource('multilib-sample.tar.bz2') r.addSource('localfile') r.Create('/foo')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.addSource('distcache-1.4.5.tar.bz2') r.Create('/foo')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.addSource('distcache-1.4.5.tar.bz2', rpm='distcache-1.4.5-2.src.rpm') r.Create('/bar')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/etc/config', contents='test 123') r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/etc/config') r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/etc/config') r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/etc/blah') r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/etc/config', contents='test 123') r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/etc/foo', contents='test 234') r.Symlink('foo', '/etc/config') r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/usr/share/man/man1/bar.1', contents='test 234') r.Symlink('bar.1', '/usr/share/man/man1/foo.1')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/usr/share/man/man1/foo.1', contents='test 123')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/etc/first', 'unchanged') r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/etc/second', 'unchanged') r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create("/lib/1") r.Create("/lib/first") r.Create("/lib/non-utf8" + '\200') r.NonUTF8Filenames(exceptions="/lib/non-utf8" + '\200')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create("/lib/1") r.Create("/lib/2")
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create("/lib/1") r.Create("/lib/2") r.Create("/lib/3")
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create("/lib/1") r.Create("/lib/2") r.Create("/lib/3") r.Create("/lib/4")
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('%(libdir)s/libfoo.so.1') r.Provides('file', '%(libdir)s/libfoo.so.1')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('%(libdir)s/libfoo.so.2') r.Provides('file', '%(libdir)s/libfoo.so.2')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('%(bindir)s/bar', mode=0755) r.Requires('%(libdir)s/libfoo.so.1' %r.macros, '%(bindir)s/bar')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('%(bindir)s/baz', mode=0755) r.Requires('%(libdir)s/libfoo.so.2' %r.macros, '%(bindir)s/baz')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Run('mkdir test; echo -e \#\!/bin/notthere\\nhi > test/foo; chmod 755 test/foo') r.TestSuite('test', autoBuildMakeDependencies=False) r.Create('/etc/foo') r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): self.Requires('other') self.addTrove('test:runtime')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/foo', contents='initialtransientcontents') r.Transient('/foo')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/foo', contents='initialregularcontents')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/foo', contents='initialconfigcontents') r.Config('/foo') r.ComponentSpec('runtime', '/foo')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/foo', contents='initialrecipecontents') r.InitialContents('/foo')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/foo', contents='secondrecipecontents') r.InitialContents('/foo')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/etc/other', contents='secondrecipecontents') r.Requires('test:config', '/etc/other') r.ComponentSpec('runtime', '%(sysconfdir)s/')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): self.addTrove('test1', '1.0')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): self.addTrove('test1', '1.1')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): self.startGroup('group-test2', checkPathConflicts=False, groupName='group-test') self.addTrove('test1', '1.0') self.startGroup('group-test3', groupName='group-test') self.addTrove('test2', '1.0')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.User('%(user)s', %(uid)s)
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.addTrove('synctrove', '1', byDefault=False)
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.addTrove('synctrove', '2', byDefault=False)
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/usr/share/foo1') r.Create('%(debugsrcdir)s/%(name)s-%(version)s/foo1')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/usr/share/foo2') r.Create('%(debugsrcdir)s/%(name)s-%(version)s/foo2')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): if Use.readline: pass r.Create('/usr/share/foo2') r.Create('%(debugsrcdir)s/%(name)s-%(version)s/foo2')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/usr/share/foo2')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/usr/share/foo2') r.addSource('newsource') r.Install('newsource', '/usr/share/foo3')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.Create('/foo', contents='simple')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(self): self.add("test", "@rpl:linux") self.createGroup('group-second') self.createGroup('group-third') self.add("test", "@rpl:linux", groupName = ['group-second', 'group-third']) # add group-second to group-first self.addNewGroup('group-second')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): r.addSource('distcc-2.9.tar.bz2')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def setup(r): if Use.ffff: r.Create('/foo', contents='simple') else: r.Create('/bar', contents='simple')
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def getRecipeClass(self): class Subclass(PackageRecipe): internalAbstractBaseClass = True name = "subclass" version = "1.0" return Subclass
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def getRecipeClass(self): clearBuildRequires() f = self.openSourceFile('VERSION') readVersion = f.read()[:-1] f.close() class RealRecipe(PackageRecipe): name = self.packageName version = readVersion def setup(r): if False: # make sure FactoryException is available raise FactoryException r.Create("/foo", contents = readVersion + "\\n") return RealRecipe
sassoftware/conary
[ 47, 9, 47, 4, 1396904066 ]
def initial(self, request, *args, **kwargs): if not can_access_editor(request): raise PermissionDenied return super().initial(request, *args, **kwargs)
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def wrapper(func): func = api_etag(**outkwargs)(func) @wraps(func) def wrapped_func(self, request, *args, **kwargs): try: changeset = request.changeset except AttributeError: changeset = ChangeSet.get_for_request(request) request.changeset = changeset update_cache_key = request.changeset.raw_cache_key_without_changes update_cache_key_match = request.GET.get('update_cache_key') == update_cache_key return func(self, request, *args, update_cache_key=update_cache_key, update_cache_key_match=update_cache_key_match, **kwargs) return wrapped_func
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def _get_level_geometries(level): buildings = level.buildings.all() buildings_geom = cascaded_union([building.geometry for building in buildings]) spaces = {space.pk: space for space in level.spaces.all()} holes_geom = [] for space in spaces.values(): if space.outside: space.geometry = space.geometry.difference(buildings_geom) columns = [column.geometry for column in space.columns.all()] if columns: columns_geom = cascaded_union([column.geometry for column in space.columns.all()]) space.geometry = space.geometry.difference(columns_geom) holes = [hole.geometry for hole in space.holes.all()] if holes: space_holes_geom = cascaded_union(holes) holes_geom.append(space_holes_geom.intersection(space.geometry)) space.geometry = space.geometry.difference(space_holes_geom) for building in buildings: building.original_geometry = building.geometry if holes_geom: holes_geom = cascaded_union(holes_geom) holes_geom_prep = prepared.prep(holes_geom) for obj in buildings: if holes_geom_prep.intersects(obj.geometry): obj.geometry = obj.geometry.difference(holes_geom) results = [] results.extend(buildings) for door in level.doors.all(): results.append(door) results.extend(spaces.values()) return results
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def _get_levels_pk(request, level): # noinspection PyPep8Naming Level = request.changeset.wrap_model('Level') levels_under = () levels_on_top = () lower_level = level.lower(Level).first() primary_levels = (level,) + ((lower_level,) if lower_level else ()) secondary_levels = Level.objects.filter(on_top_of__in=primary_levels).values_list('pk', 'on_top_of') if lower_level: levels_under = tuple(pk for pk, on_top_of in secondary_levels if on_top_of == lower_level.pk) if True: levels_on_top = tuple(pk for pk, on_top_of in secondary_levels if on_top_of == level.pk) levels = chain([level.pk], levels_under, levels_on_top) return levels, levels_on_top, levels_under
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def area_sorting_func(area): groups = tuple(area.groups.all()) if not groups: return (0, 0, 0) return (1, groups[0].category.priority, groups[0].hierarchy, groups[0].priority)
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def geometries(self, request, update_cache_key, update_cache_key_match, *args, **kwargs): Level = request.changeset.wrap_model('Level') Space = request.changeset.wrap_model('Space') Column = request.changeset.wrap_model('Column') Hole = request.changeset.wrap_model('Hole') AltitudeMarker = request.changeset.wrap_model('AltitudeMarker') Building = request.changeset.wrap_model('Building') Door = request.changeset.wrap_model('Door') LocationGroup = request.changeset.wrap_model('LocationGroup') WifiMeasurement = request.changeset.wrap_model('WifiMeasurement') level = request.GET.get('level') space = request.GET.get('space') if level is not None: if space is not None: raise ValidationError('Only level or space can be specified.') level = get_object_or_404(Level.objects.filter(Level.q_for_request(request)), pk=level) edit_utils = LevelChildEditUtils(level, request) if not edit_utils.can_access_child_base_mapdata: raise PermissionDenied levels, levels_on_top, levels_under = self._get_levels_pk(request, level) # don't prefetch groups for now as changesets do not yet work with m2m-prefetches levels = Level.objects.filter(pk__in=levels).filter(Level.q_for_request(request)) # graphnodes_qs = request.changeset.wrap_model('GraphNode').objects.all() levels = levels.prefetch_related( Prefetch('spaces', Space.objects.filter(Space.q_for_request(request)).only( 'geometry', 'level', 'outside' )), Prefetch('doors', Door.objects.filter(Door.q_for_request(request)).only('geometry', 'level')), Prefetch('spaces__columns', Column.objects.filter( Q(access_restriction__isnull=True) | ~Column.q_for_request(request) ).only('geometry', 'space')), Prefetch('spaces__groups', LocationGroup.objects.only( 'color', 'category', 'priority', 'hierarchy', 'category__priority', 'category__allow_spaces' )), Prefetch('buildings', Building.objects.only('geometry', 'level')), Prefetch('spaces__holes', Hole.objects.only('geometry', 'space')), Prefetch('spaces__altitudemarkers', AltitudeMarker.objects.only('geometry', 'space')), Prefetch('spaces__wifi_measurements', WifiMeasurement.objects.only('geometry', 'space')), # Prefetch('spaces__graphnodes', graphnodes_qs) ) levels = {s.pk: s for s in levels} level = levels[level.pk] levels_under = [levels[pk] for pk in levels_under] levels_on_top = [levels[pk] for pk in levels_on_top] # todo: permissions # graphnodes = tuple(chain(*(space.graphnodes.all() # for space in chain(*(level.spaces.all() for level in levels.values()))))) # graphnodes_lookup = {node.pk: node for node in graphnodes} # graphedges = request.changeset.wrap_model('GraphEdge').objects.all() # graphedges = graphedges.filter(Q(from_node__in=graphnodes) | Q(to_node__in=graphnodes)) # graphedges = graphedges.select_related('waytype') # this is faster because we only deserialize graphnode geometries once # missing_graphnodes = graphnodes_qs.filter(pk__in=set(chain(*((edge.from_node_id, edge.to_node_id) # for edge in graphedges)))) # graphnodes_lookup.update({node.pk: node for node in missing_graphnodes}) # for edge in graphedges: # edge._from_node_cache = graphnodes_lookup[edge.from_node_id] # edge._to_node_cache = graphnodes_lookup[edge.to_node_id] # graphedges = [edge for edge in graphedges if edge.from_node.space_id != edge.to_node.space_id] results = chain( *(self._get_level_geometries(l) for l in levels_under), self._get_level_geometries(level), *(self._get_level_geometries(l) for l in levels_on_top), *(space.altitudemarkers.all() for space in level.spaces.all()), *(space.wifi_measurements.all() for space in level.spaces.all()) # graphedges, # graphnodes, ) elif space is not None: space_q_for_request = Space.q_for_request(request) qs = Space.objects.filter(space_q_for_request) space = get_object_or_404(qs.select_related('level', 'level__on_top_of'), pk=space) level = space.level edit_utils = SpaceChildEditUtils(space, request) if not edit_utils.can_access_child_base_mapdata: raise PermissionDenied if request.user_permissions.can_access_base_mapdata: doors = [door for door in level.doors.filter(Door.q_for_request(request)).all() if door.geometry.intersects(space.geometry)] doors_space_geom = cascaded_union([door.geometry for door in doors]+[space.geometry]) levels, levels_on_top, levels_under = self._get_levels_pk(request, level.primary_level) if level.on_top_of_id is not None: levels = chain([level.pk], levels_on_top) other_spaces = Space.objects.filter(space_q_for_request, level__pk__in=levels).only( 'geometry', 'level' ).prefetch_related( Prefetch('groups', LocationGroup.objects.only( 'color', 'category', 'priority', 'hierarchy', 'category__priority', 'category__allow_spaces' ).filter(color__isnull=False)) ) space = next(s for s in other_spaces if s.pk == space.pk) other_spaces = [s for s in other_spaces if s.geometry.intersects(doors_space_geom) and s.pk != space.pk] all_other_spaces = other_spaces if level.on_top_of_id is None: other_spaces_lower = [s for s in other_spaces if s.level_id in levels_under] other_spaces_upper = [s for s in other_spaces if s.level_id in levels_on_top] else: other_spaces_lower = [s for s in other_spaces if s.level_id == level.on_top_of_id] other_spaces_upper = [] other_spaces = [s for s in other_spaces if s.level_id == level.pk] space.bounds = True # deactivated for performance reasons buildings = level.buildings.all() # buildings_geom = cascaded_union([building.geometry for building in buildings]) # for other_space in other_spaces: # if other_space.outside: # other_space.geometry = other_space.geometry.difference(buildings_geom) for other_space in chain(other_spaces, other_spaces_lower, other_spaces_upper): other_space.opacity = 0.4 other_space.color = '#ffffff' for building in buildings: building.opacity = 0.5 else: buildings = [] doors = [] other_spaces = [] other_spaces_lower = [] other_spaces_upper = [] all_other_spaces = [] # todo: permissions if request.user_permissions.can_access_base_mapdata: graphnodes = request.changeset.wrap_model('GraphNode').objects.all() graphnodes = graphnodes.filter((Q(space__in=all_other_spaces)) | Q(space__pk=space.pk)) space_graphnodes = tuple(node for node in graphnodes if node.space_id == space.pk) graphedges = request.changeset.wrap_model('GraphEdge').objects.all() space_graphnodes_ids = tuple(node.pk for node in space_graphnodes) graphedges = graphedges.filter(Q(from_node__pk__in=space_graphnodes_ids) | Q(to_node__pk__in=space_graphnodes_ids)) graphedges = graphedges.select_related('from_node', 'to_node', 'waytype').only( 'from_node__geometry', 'to_node__geometry', 'waytype__color' ) else: graphnodes = [] graphedges = [] areas = space.areas.filter(Area.q_for_request(request)).only( 'geometry', 'space' ).prefetch_related( Prefetch('groups', LocationGroup.objects.order_by( '-category__priority', '-hierarchy', '-priority' ).only( 'color', 'category', 'priority', 'hierarchy', 'category__priority', 'category__allow_areas' )) ) for area in areas: area.opacity = 0.5 areas = sorted(areas, key=self.area_sorting_func) results = chain( buildings, other_spaces_lower, doors, other_spaces, [space], areas, space.holes.all().only('geometry', 'space'), space.stairs.all().only('geometry', 'space'), space.ramps.all().only('geometry', 'space'), space.obstacles.all().only('geometry', 'space', 'color'), space.lineobstacles.all().only('geometry', 'width', 'space', 'color'), space.columns.all().only('geometry', 'space'), space.altitudemarkers.all().only('geometry', 'space'), space.wifi_measurements.all().only('geometry', 'space'), space.pois.filter(POI.q_for_request(request)).only('geometry', 'space').prefetch_related( Prefetch('groups', LocationGroup.objects.only( 'color', 'category', 'priority', 'hierarchy', 'category__priority', 'category__allow_pois' ).filter(color__isnull=False)) ), other_spaces_upper, graphedges, graphnodes ) else: raise ValidationError('No level or space specified.') return Response(list(chain( [('update_cache_key', update_cache_key)], (self.conditional_geojson(obj, update_cache_key_match) for obj in results) )))
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def geometrystyles(self, request, *args, **kwargs): return Response({ 'building': '#aaaaaa', 'space': '#eeeeee', 'hole': 'rgba(255, 0, 0, 0.3)', 'door': '#ffffff', 'area': '#55aaff', 'stair': '#a000a0', 'ramp': 'rgba(160, 0, 160, 0.2)', 'obstacle': '#999999', 'lineobstacle': '#999999', 'column': 'rgba(0, 0, 50, 0.3)', 'poi': '#4488cc', 'shadow': '#000000', 'graphnode': '#009900', 'graphedge': '#00CC00', 'altitudemarker': '#0000FF', 'wifimeasurement': '#DDDD00', })
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def bounds(self, request, *args, **kwargs): return Response({ 'bounds': Source.max_bounds(), })
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def post_or_delete(self, request, *args, **kwargs): # django-rest-framework doesn't automatically do this for logged out requests SessionAuthentication().enforce_csrf(request) return self.retrieve(request, *args, **kwargs)
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def resolved(self): resolved = None path = self.kwargs.get('path', '') if path: try: resolved = resolve('/editor/'+path+'/') except Resolver404: pass if not resolved: try: resolved = resolve('/editor/'+path) except Resolver404: pass self.request.sub_resolver_match = resolved return resolved
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def get_queryset(self): return ChangeSet.qs_for_request(self.request).select_related('last_update', 'last_state_update', 'last_change')
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def list(self, request, *args, **kwargs): return self._list(request, self.get_queryset())
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def user(self, request, *args, **kwargs): return self._list(request, self.get_queryset().filter(author=request.user))
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def reviewing(self, request, *args, **kwargs): return self._list(request, self.get_queryset().filter( assigned_to=request.user, state='review' ))
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]
def pending_review(self, request, *args, **kwargs): return self._list(request, self.get_queryset().filter( state__in=('proposed', 'reproposed'), ))
c3nav/c3nav
[ 137, 31, 137, 17, 1461327231 ]