コード例 #1
0
ファイル: views.py プロジェクト: NAVADMC/ADSM
def population(request):
    """"Creates the formset and filter context for Population View"""
    context = {}
    FarmSet = modelformset_factory(Unit, extra=0, form=UnitFormAbbreviated, can_delete=False)
    if save_formset_succeeded(FarmSet, Unit, context, request):
        return redirect(request.path)
    if Population.objects.filter(id=1, ).exists():
        if not Unit.objects.count(): # #571 no units were imported: error, blank files
            Population.objects.all().delete()
            return population(request)  # delete blank and try again
        sort_type = request.GET.get('sort_by', 'initial_state')
        query_filter = Q()
        params = filtering_params(request)
        for key, value in params.items():  # loops through params and stacks filters in an AND fashion
            query_filter = query_filter & Q(**{key: value})
        initialized_formset = FarmSet(queryset=Unit.objects.filter(query_filter).order_by(sort_type)[:100])
        context['formset'] = initialized_formset
        context['filter_info'] = filter_info(request, params)
        context['deletable'] = '/setup/Population/1/delete/'
        context['editable'] = request.GET.get('readonly', 'editable')
        context['population_file'] = os.path.basename(Population.objects.get().source_file)
        context['Population'] = Unit.objects.count()
        context['Farms'] = Unit.objects.count()
    else:
        context['xml_files'] = file_list([".sqlite3"])
    return render(request, 'ScenarioCreator/Population.html', context)
コード例 #2
0
ファイル: context_processor.py プロジェクト: NAVADMC/ADSM
def adsm_context(request):
    context = {}
    if not request.is_ajax() and request.path and request.path != '/' and '/LoadingScreen/' not in request.path:
        session = SmSession.objects.get()
        version = session.update_available
        context = {'filename': scenario_filename(),  # context in either mode
                   'unsaved_changes': unsaved_changes(),
                   'url': request.path,
                   'active_link': '/'.join(re.split('\W+', request.path)[2:]),
                   'dev_version': __version__,
                   'update_version': version if version and version != 'False' and version != '0' else '',
                   'workspace_path': workspace_path(),
                   'db_files': (file_list(".sqlite3")),
                   'show_help_text': session.show_help_text
        }

    return context
コード例 #3
0
ファイル: views.py プロジェクト: NAVADMC/ADSM
def file_dialog(request):
    context = {'db_files': (file_list(".sqlite3")),
               'title': 'Select a new Scenario to Open'}
    return render(request, 'ScenarioCreator/workspace.html', context)