def timeseries_view(request, model_uuid): """ View the "Timeseries" page Parameters: model_uuid (uuid): required Returns: HttpResponse Example: http://0.0.0.0:8000/<model_uuid>/timeseries/ """ model = Model.by_uuid(model_uuid) can_edit = model.handle_view_access(request.user) files = User_File.objects.filter(model=model, filename__contains=".csv") context = { "timezones": common_timezones, "model": model, "files": files, "can_edit": can_edit, "help_content": Help_Guide.get_safe_html('timeseries'), } return render(request, "timeseries.html", context)
def parameters_view(request, model_uuid, parameter_name): """ View the "Parameters" page Parameters: model_uuid (uuid): required parameter_name (str): required Returns: HttpResponse Example: http://0.0.0.0:8000/<model_uuid>/parameters/resource/ """ model = Model.by_uuid(model_uuid) can_edit = model.handle_view_access(request.user) parameter = Parameter.objects.filter(name=parameter_name).first() context = { "timezones": common_timezones, "model": model, "parameter": parameter, "can_edit": can_edit, "help_content": Help_Guide.get_safe_html('parameters'), } return render(request, "parameters.html", context)
def scenarios_view(request, model_uuid): """ View the "Scenarios" page Parameters: model_uuid (uuid): required Returns: HttpResponse Example: http://0.0.0.0:8000/<model_uuid>/scenarios """ model = Model.by_uuid(model_uuid) try: can_edit = model.handle_view_access(request.user) except Exception: return HttpResponseRedirect(reverse('home')) scenarios = model.scenarios session_scenario_id = request.session.get('scenario_id', None) session_scenario = scenarios.filter(id=session_scenario_id).first() context = { "timezones": common_timezones, "model": model, "scenarios": scenarios, "session_scenario": session_scenario, "mapbox_token": settings.MAPBOX_TOKEN, "can_edit": can_edit, "help_content": Help_Guide.get_safe_html('scenarios'), } return render(request, "scenarios.html", context)
def add_scenarios_view(request, model_uuid): """ View the "Add Scenario" page Parameters: model_uuid (uuid): required Returns: HttpResponse Example: http://0.0.0.0:8000/<model_uuid>/add_scenarios_view """ model = Model.by_uuid(model_uuid) can_edit = model.handle_view_access(request.user) context = { "timezones": common_timezones, "model": model, "scenarios": model.scenarios, "can_edit": can_edit, "help_content": Help_Guide.get_safe_html('add_scenario'), } return render(request, "add_scenario.html", context)
def add_technologies_view(request, model_uuid): """ View the "Add Technology" page Parameters: model_uuid (uuid): required Returns: HttpResponse Example: http://0.0.0.0:8000/<model_uuid>/add_technologies_view """ model = Model.by_uuid(model_uuid) can_edit = model.handle_view_access(request.user) public_model_ids = Model.objects.filter(snapshot_version=None, public=True).values_list('id', flat=True) public_techs = Technology.objects.filter(model_id__in=public_model_ids) context = { "timezones": common_timezones, "model": model, "abstract_techs": Abstract_Tech.objects.all(), "public_techs": public_techs, "my_techs": model.technologies, "can_edit": can_edit, "help_content": Help_Guide.get_safe_html('add_technology'), } return render(request, "add_technology.html", context)
def share_view(request): """ View the "Model Sharing" page Parameters: model_uuid (uuid): required Returns: HttpResponse Example: http://0.0.0.0:8000/share/ """ selected_model_uuid = request.GET.get('model_uuid', None) user_models = Model_User.objects.filter(user=request.user, model__is_uploading=False) users = User.objects.all().exclude(id=request.user.id).order_by( 'last_name', 'first_name') context = { "timezones": common_timezones, "user": request.user, "users": users, "user_models": user_models, "selected_model_uuid": str(selected_model_uuid), "help_content": Help_Guide.get_safe_html('share'), } return render(request, "share.html", context)
def locations_view(request, model_uuid): """ View the "Locations" page Parameters: model_uuid (uuid): required Returns: HttpResponse Example: http://0.0.0.0:8000/<model_uuid>/locations """ model = Model.by_uuid(model_uuid) try: can_edit = model.handle_view_access(request.user) except Exception: return HttpResponseRedirect(reverse('home')) locations = model.locations.values() location_ids = [loc['id'] for loc in locations] lts = Loc_Tech.objects.filter( Q(location_1_id__in=location_ids) | Q(location_2_id__in=location_ids)) lts = lts.values("id", "technology_id", "location_1_id", "location_2_id", "technology__pretty_name", "technology__pretty_tag") loc_techs = {} for lt in lts: l1, l2 = lt["location_1_id"], lt["location_2_id"] if l1 not in loc_techs.keys(): loc_techs[l1] = [lt] else: loc_techs[l1].append(lt) if l2 is not None and l2 not in loc_techs.keys(): loc_techs[l2] = [lt] elif l2 is not None: loc_techs[l2].append(lt) context = { "nrel_api_key": settings.NREL_API_KEY, "timezones": common_timezones, "model": model, "locations": locations, "loc_techs": loc_techs, "mapbox_token": settings.MAPBOX_TOKEN, "can_edit": can_edit, "help_content": Help_Guide.get_safe_html('locations'), } return render(request, "locations.html", context)
def loc_techs_view(request, model_uuid): """ View the "Nodes" page Parameters: model_uuid (uuid): required Returns: HttpResponse Example: http://0.0.0.0:8000/<model_uuid>/loc_techs """ model = Model.by_uuid(model_uuid) try: can_edit = model.handle_view_access(request.user) except Exception: return HttpResponseRedirect(reverse('home')) technologies = model.technologies.values("id", "pretty_name", "pretty_tag", "abstract_tech__icon") session_technology_id = request.GET.get('tech_id', None) session_loc_tech_id = request.GET.get('loc_tech_id', None) if not session_technology_id: session_technology_id = request.session.get('technology_id', None) if session_technology_id: session_technology_id = int(session_technology_id) if session_loc_tech_id: request.session['loc_tech_id'] = int(session_loc_tech_id) context = { "timezones": common_timezones, "model": model, "technologies": list(technologies), "session_technology_id": session_technology_id, "can_edit": can_edit, "mapbox_token": settings.MAPBOX_TOKEN, "help_content": Help_Guide.get_safe_html('nodes'), } return render(request, "loc_techs.html", context)
def model_view(request, model_uuid): """ View the main model "Activity" page Parameters: model_uuid (uuid): required Returns: HttpResponse Example: http://0.0.0.0:8000/<model_uuid>/ """ model = Model.by_uuid(model_uuid) try: can_edit = model.handle_view_access(request.user) except Exception: return HttpResponseRedirect(reverse('home')) if request.user.is_authenticated: # Update last_access model_user = Model_User.objects.filter(user=request.user, model=model) if len(model_user) > 0: mu = model_user.first() mu.notifications = 0 mu.save() comments = Model_Comment.objects.filter(model=model) context = { "timezones": common_timezones, "user": request.user, "model": model, "comments": comments, "can_edit": can_edit, "help_content": Help_Guide.get_safe_html('model'), } return render(request, "activity.html", context)
def home_view(request): """ View the "Home" page Returns: HttpResponse Example: http://0.0.0.0:8000/ """ user_models = Model_User.objects.filter( user=request.user, model__snapshot_version=None, model__public=False).order_by('-last_access') model_ids = user_models.values_list("model_id", flat=True) snapshots = Model.objects.filter(snapshot_base_id__in=model_ids) public_models = Model.objects.filter(snapshot_version=None, public=True) user_models = list(user_models) if len(user_models) > 0: last_model = user_models[0].model elif len(public_models) > 0: last_model = public_models[0] else: last_model = None context = { "timezones": common_timezones, "last_model": last_model, "user_models": user_models, "public_models": public_models, "snapshots": snapshots, "mapbox_token": settings.MAPBOX_TOKEN, "help_content": Help_Guide.get_safe_html('home'), } return render(request, "home.html", context)