def viewParameterInSimulation(request, species_wid, wid): #get associated simulation property qs = Parameter.objects.filter(species__wid = species_wid, wid=wid) if not qs[0].state is None: sim_class_name = 'edu.stanford.covert.cell.sim.state.%s' % qs[0].state.wid.replace('State_', '') verbose_class_name = '%s: %s' % (wid, qs[0].state.name) else: sim_class_name = 'edu.stanford.covert.cell.sim.process.%s' % qs[0].process.wid.replace('Process_', '') verbose_class_name = '%s: %s' % (wid, qs[0].process.name) sim_property_name = qs[0].name verbose_property_name = qs[0].name #highlight code for simulation class pathParts = sim_class_name.split('.') codePath = "%s/src/+%s/%s.m" % (MODEL_CODE_BASE_DIR, '/+'.join(pathParts[0:-1]), pathParts[-1]) if not os.path.isfile(codePath): codePath = "%s/src/+%s/@%s/%s.m" % (MODEL_CODE_BASE_DIR, '/+'.join(pathParts[0:-1]), pathParts[-1], pathParts[-1]) if os.path.isfile(codePath): with open (codePath, "r") as codeFile: code = codeFile.read() lexer = MatlabLexer() lexer.add_filter(PropertyDefinitionFilter(property_names = [sim_property_name], tokentype=Token.Name.Variable)) tokens = lexer.get_tokens(code) object = { 'class_name': sim_class_name, 'property_names': [sim_property_name], 'code': pygments.format(tokens, PygmentsFormatter(linenos='inline', linenostep=1, style=PygmentsStyle, noclasses=True)), } else: raise Http404 #render response return render_queryset_to_response( species_wid = species_wid, request = request, models = [Parameter], queryset = qs, templateFile = 'public/viewPropertyInSimulation.html', data = { 'object_list': [object], 'verbose_class_name': verbose_class_name, 'verbose_property_name': verbose_property_name, })
def viewParametersInSimulation(request, species_wid, wid): obj = getEntry(species_wid = species_wid, wid = wid) if obj is None: raise Http404 model = obj.__class__ verbose_class_name = model._meta.verbose_name verbose_property_name = '%s parameters' % obj.name #get associated simulation property qs = EmptyQuerySet() for field in model._meta.get_all_related_objects() + model._meta.get_all_related_many_to_many_objects(): accessor_name = field.get_accessor_name() if accessor_name == '+': continue if isinstance(field, ForeignKey) and issubclass(field.rel.to, Parameter): qs._result_cache.append(getattr(obj, accessor_name)) if (isinstance(field, ManyToManyField) and issubclass(field.rel.to, Parameter)) or \ (isinstance(field, RelatedObject) and issubclass(field.model, Parameter)): qs2 = getattr(obj, accessor_name).all() if len(qs2) > 0: qs._result_cache.extend(qs2._result_cache) classes = {} for o in qs: if not o.state is None: sim_class_name = 'edu.stanford.covert.cell.sim.state.%s' % o.state.wid.replace('State_', '') else: sim_class_name = 'edu.stanford.covert.cell.sim.process.%s' % o.process.wid.replace('Process_', '') if not classes.has_key(sim_class_name): classes[sim_class_name] = [] classes[sim_class_name].append(o.name) #highlight code for simulation class objects = [] for sim_class_name in classes: sim_property_names = classes[sim_class_name] sim_property_names.sort() pathParts = sim_class_name.split('.') codePath = "%s/src/+%s/%s.m" % (MODEL_CODE_BASE_DIR, '/+'.join(pathParts[0:-1]), pathParts[-1]) if not os.path.isfile(codePath): codePath = "%s/src/+%s/@%s/%s.m" % (MODEL_CODE_BASE_DIR, '/+'.join(pathParts[0:-1]), pathParts[-1], pathParts[-1]) if not os.path.isfile(codePath): continue with open (codePath, "r") as codeFile: code = codeFile.read() lexer = MatlabLexer() lexer.add_filter(PropertyDefinitionFilter(property_names = sim_property_names, tokentype=Token.Name.Variable)) tokens = lexer.get_tokens(code) objects.append({ 'class_name': sim_class_name, 'property_names': sim_property_names, 'code': pygments.format(tokens, PygmentsFormatter(linenos='inline', linenostep=1, style=PygmentsStyle, noclasses=True)), }) #render response return render_queryset_to_response( species_wid = species_wid, request = request, models = [Parameter], queryset = qs, templateFile = 'public/viewPropertyInSimulation.html', data = { 'object_list': objects, 'verbose_class_name': verbose_class_name, 'verbose_property_name': verbose_property_name, })
def viewPropertyInSimulation(request, species_wid, class_name, property_name): #get model model = getModel(class_name) #get verbose class name verbose_class_name = model._meta.verbose_name #get verbose property name verbose_property_name = property_name for fieldset in model._meta.fieldsets: for field in fieldset[1]['fields']: if isinstance(field, (str, unicode)) and field == property_name: tmp = model._meta.get_field_by_name(property_name) if len(tmp) > 0: verbose_property_name = tmp[0].verbose_name if isinstance(field, dict) and field['name'] == property_name: verbose_property_name = field['verbose_name'] #get associated simulation code properties qs = ModelProperty.objects.get( species__wid = species_wid, class_name = class_name, property_name = property_name ).simulation_properties.all().order_by('class_name', 'property_name') #organize simulation code properties by class classes = {} for object in qs: if not classes.has_key(object.class_name): classes[object.class_name] = [] classes[object.class_name].append(object.property_name) #highlight code for each simulation class object_list = [] for sim_class_name in classes: sim_property_names = classes[sim_class_name] sim_property_names.sort() pathParts = sim_class_name.split('.') codePath = "%s/src/+%s/%s.m" % (MODEL_CODE_BASE_DIR, '/+'.join(pathParts[0:-1]), pathParts[-1]) if not os.path.isfile(codePath): codePath = "%s/src/+%s/@%s/%s.m" % (MODEL_CODE_BASE_DIR, '/+'.join(pathParts[0:-1]), pathParts[-1], pathParts[-1]) if not os.path.isfile(codePath): continue with open (codePath, "r") as codeFile: code = codeFile.read() lexer = MatlabLexer() lexer.add_filter(PropertyDefinitionFilter(property_names = sim_property_names, tokentype=Token.Name.Variable)) tokens = lexer.get_tokens(code) object_list.append({ 'class_name': sim_class_name, 'property_names': sim_property_names, 'code': pygments.format(tokens, PygmentsFormatter(linenos='inline', linenostep=1, style=PygmentsStyle, noclasses=True)), }) #render response return render_queryset_to_response( species_wid = species_wid, request = request, models = [SimulationProperty], queryset = qs, templateFile = 'public/viewPropertyInSimulation.html', data = { 'object_list': object_list, 'verbose_class_name': verbose_class_name, 'verbose_property_name': verbose_property_name, })