コード例 #1
0
ファイル: views.py プロジェクト: sophsoph321/xgds_planner2
def plan_tests(request, plan_id, editable=True):
    templates = get_handlebars_templates(settings.XGDS_PLANNER2_HANDLEBARS_DIRS, 'XGDS_PLANNER2_HANDLEBARS_DIRS')

    plan = PLAN_MODEL.get().objects.get(pk=plan_id)
    plan_json = plan.jsonPlan
    if not plan_json.serverId:
        plan_json.serverId = plan.pk
    if "None" in plan_json.url:
        plan_json.url = plan.get_absolute_url()

    planSchema = models.getPlanSchema(plan_json.platform.name)
    
    return render(request,
                  'xgds_planner2/planner_tests.html',
                  {'templates': templates,
                   'plan_schema_json': planSchema.getJsonSchema(),  # xpjson.dumpDocumentToString(planSchema.getSchema()),
                   'plan_library_json': planSchema.getJsonLibrary(),  # xpjson.dumpDocumentToString(planSchema.getLibrary()),
                   'plan_json': json.dumps(plan_json),
                   'plan_name': plan.name,
                   'plan_index_json': json.dumps(plan_index_json()),
                   'editable': editable,
                   'simulatorUrl': planSchema.simulatorUrl,
                   'simulator': planSchema.simulator,
                   'placemark_circle_url': request.build_absolute_uri(staticfiles_storage.url('xgds_planner2/images/placemark_circle.png')),
                   'placemark_circle_highlighted_url': request.build_absolute_uri(staticfiles_storage.url('xgds_planner2/images/placemark_circle_highlighted.png')),
                   'plan_links_json': json.dumps(plan.getLinks()),
                   'plan_namedURLs_json': json.dumps(plan.namedURLs),
                   })
コード例 #2
0
ファイル: views.py プロジェクト: xgds/xgds_image
def editImage(request, imageSetID):
    imageSet = IMAGE_SET_MODEL.get().objects.get(pk=imageSetID)
    if request.POST:
        form = ImageSetForm(request.POST, instance=imageSet)
        if form.is_valid():
            form.save()
            if form.errors:
                for key, msg in form.errors.items():
                    if key == "warning":
                        messages.warning(request, msg)
                    elif key == "error":
                        messages.error(request, msg)
            else:
                messages.success(request, settings.XGDS_IMAGE_IMAGE_SET_MONIKER + " successfully updated.")
            return HttpResponseRedirect(
                reverse("search_map_single_object", kwargs={"modelPK": imageSetID, "modelName": "Photo"})
            )
        else:
            messages.error(request, "The form is not valid")
            return render_to_response("xgds_image/imageEdit.html", RequestContext(request, {"form": form}))
    elif request.method == "GET":
        form = ImageSetForm(instance=imageSet)
        return render_to_response(
            "xgds_image/imageEdit.html",
            RequestContext(
                request,
                {
                    "form": form,
                    "templates": get_handlebars_templates(
                        list(settings.XGDS_MAP_SERVER_HANDLEBARS_DIRS), "XGDS_MAP_SERVER_HANDLEBARS_DIRS"
                    ),
                },
            ),
        )
コード例 #3
0
ファイル: views.py プロジェクト: xgds/xgds_planner2
def plan_tests(request, plan_id, editable=True):
    templates = get_handlebars_templates(settings.XGDS_PLANNER2_HANDLEBARS_DIRS, 'XGDS_PLANNER2_HANDLEBARS_DIRS')

    plan = PLAN_MODEL.get().objects.get(pk=plan_id)
    plan_json = plan.jsonPlan
    if not plan_json.serverId:
        plan_json.serverId = plan.pk
    if "None" in plan_json.url:
        plan_json.url = plan.get_absolute_url()

    planSchema = models.getPlanSchema(plan_json.platform.name)
#     print planSchema.getJsonSchema();
    return render_to_response(
        'xgds_planner2/planner_tests.html',
        RequestContext(request, {
            'templates': templates,
            'plan_schema_json': planSchema.getJsonSchema(),  # xpjson.dumpDocumentToString(planSchema.getSchema()),
            'plan_library_json': planSchema.getJsonLibrary(),  # xpjson.dumpDocumentToString(planSchema.getLibrary()),
            'plan_json': json.dumps(plan_json),
            'plan_name': plan.name,
            'plan_index_json': json.dumps(plan_index_json()),
            'editable': editable,
            'simulatorUrl': planSchema.simulatorUrl,
            'simulator': planSchema.simulator,
            'placemark_circle_url': request.build_absolute_uri(
                staticfiles_storage.url('xgds_planner2/images/placemark_circle.png')
            ),
            'placemark_circle_highlighted_url': request.build_absolute_uri(
                staticfiles_storage.url('xgds_planner2/images/placemark_circle_highlighted.png')
            ),
            'plan_links_json': json.dumps(plan.getLinks()),
            'plan_namedURLs_json': json.dumps(plan.namedURLs),
        }),
        # context_instance=RequestContext
    )
コード例 #4
0
ファイル: views.py プロジェクト: xgds/xgds_planner2
def plan_editor_app(request, plan_id=None, editable=True):
    templates = get_handlebars_templates(settings.XGDS_PLANNER2_HANDLEBARS_DIRS, 'XGDS_PLANNER2_HANDLEBARS_DIRS')

    plan = PLAN_MODEL.get().objects.get(pk=plan_id)
    dirty = False
    if not plan.jsonPlan.serverId:
        plan.jsonPlan.serverId = plan.pk
        dirty = True
    if "None" in plan.jsonPlan.url:
        plan.jsonPlan.url = plan.get_absolute_url()
        dirty = True
        
    if dirty:
        plan.save()

    planSchema = models.getPlanSchema(plan.jsonPlan.platform.name)
    pe = None
    try:
        if plan.executions and plan.executions.count() > 0:
            pe = json.dumps(plan.executions.all()[0].toSimpleDict(), cls=DatetimeJsonEncoder)
    except:
        pass

    context = {
            'templates': templates,
            'app': 'xgds_planner2/js/plannerApp.js',
            'saveSearchForm': MapSearchForm(),
            'searchForms': getSearchForms(),
            'flight_names': json.dumps(getAllFlightNames()),
            'plan_schema_json': planSchema.getJsonSchema(),  # xpjson.dumpDocumentToString(planSchema.getSchema()),
            'plan_library_json': planSchema.getJsonLibrary(),  # xpjson.dumpDocumentToString(planSchema.getLibrary()),
            'plan_json': json.dumps(plan.jsonPlan),
            'plan_name': plan.name,
            'plan_execution': pe,
            'plan_index_json': json.dumps(plan_index_json()),
            'editable': editable and not plan.readOnly,
            'simulatorUrl': planSchema.simulatorUrl,
            'simulator': planSchema.simulator,
            'placemark_circle_url': request.build_absolute_uri(
                staticfiles_storage.url('xgds_planner2/images/placemark_circle.png')
            ),
            'placemark_circle_highlighted_url': request.build_absolute_uri(
                staticfiles_storage.url('xgds_planner2/images/placemark_circle_highlighted.png')
            ),
            'placemark_directional_url': request.build_absolute_uri(
                staticfiles_storage.url('xgds_planner2/images/placemark_directional.png')
            ),
            'placemark_selected_directional_url': request.build_absolute_uri(
                staticfiles_storage.url('xgds_planner2/images/placemark_directional_highlighted.png')
            ),
            'plan_links_json': json.dumps(plan.getLinks())
        }

    return render_to_response(
        'xgds_planner2/planner_app.html',
        RequestContext(request, getClassByName(settings.XGDS_PLANNER2_EDITOR_CONTEXT_METHOD)(context)),
    )
コード例 #5
0
ファイル: views.py プロジェクト: sophsoph321/xgds_planner2
def plan_editor_app(request, plan_id=None, editable=True):
    templates = get_handlebars_templates(settings.XGDS_PLANNER2_HANDLEBARS_DIRS, 'XGDS_PLANNER2_HANDLEBARS_DIRS')

    plan = PLAN_MODEL.get().objects.get(pk=plan_id)
    dirty = False
    if not plan.jsonPlan.serverId:
        plan.jsonPlan.serverId = plan.pk
        dirty = True
    if "None" in plan.jsonPlan.url:
        plan.jsonPlan.url = plan.get_absolute_url()
        dirty = True
        
    if dirty:
        plan.save()

    planSchema = models.getPlanSchema(plan.jsonPlan.platform.name)
    pe = None
    try:
        if plan.executions and plan.executions.count() > 0:
            pe = json.dumps(plan.executions.all()[0].toSimpleDict(), cls=DatetimeJsonEncoder)
    except:
        pass

    context = {
            'templates': templates,
            'app': 'xgds_planner2/js/plannerApp.js',
            'saveSearchForm': MapSearchForm(),
            'searchForms': getSearchForms(),
            'flight_names': json.dumps(getAllFlightNames()),
            'plan_schema_json': planSchema.getJsonSchema(),  # xpjson.dumpDocumentToString(planSchema.getSchema()),
            'plan_library_json': planSchema.getJsonLibrary(),  # xpjson.dumpDocumentToString(planSchema.getLibrary()),
            'plan_json': json.dumps(plan.jsonPlan),
            'plan_name': plan.name,
            'plan_execution': pe,
            'plan_index_json': json.dumps(plan_index_json()),
            'editable': editable and not plan.readOnly,
            'simulatorUrl': planSchema.simulatorUrl,
            'simulator': planSchema.simulator,
            'placemark_circle_url': request.build_absolute_uri(
                staticfiles_storage.url('xgds_planner2/images/placemark_circle.png')
            ),
            'placemark_circle_highlighted_url': request.build_absolute_uri(
                staticfiles_storage.url('xgds_planner2/images/placemark_circle_highlighted.png')
            ),
            'placemark_directional_url': request.build_absolute_uri(
                staticfiles_storage.url('xgds_planner2/images/placemark_directional.png')
            ),
            'placemark_selected_directional_url': request.build_absolute_uri(
                staticfiles_storage.url('xgds_planner2/images/placemark_directional_highlighted.png')
            ),
            'plan_links_json': json.dumps(plan.getLinks())
        }

    return render(request,
                  'xgds_planner2/planner_app.html',
                  getClassByName(settings.XGDS_PLANNER2_EDITOR_CONTEXT_METHOD)(context))
コード例 #6
0
ファイル: views.py プロジェクト: xgds/xgds_video
def displayLiveVideo(request, sourceShortName=None):
    """ Directly display RTSP feeds for the active episode.  
    This will either include all sources or be for a single source if it is passed in..
    """
    GET_ACTIVE_EPISODE_METHOD = getClassByName(settings.XGDS_VIDEO_GET_ACTIVE_EPISODE)
    episode = GET_ACTIVE_EPISODE_METHOD()
    if not episode:
        messages.add_message(request, messages.ERROR, 'There is no live video.')
        return redirect(reverse('error'))
    
    sources = []
    noteForms = []
    if sourceShortName:
        try:
            source = SOURCE_MODEL.get().objects.get(shortName=str(sourceShortName))
            sources.append(source)
            noteForms.append(buildNoteForm([episode], source, request, {'index':0}))
        except:
            pass
    else:
        # get sources and get feeds
        sources = SOURCE_MODEL.get().objects.filter(videosegment__episode = episode).distinct()
        for index,source in enumerate(sources):
            noteForms.append(buildNoteForm([episode], source, request, {'index':index}))
    
    noteModelName = str(NOTE_MODEL.get().cls_type())
    noteForm = getClassByName(settings.XGDS_NOTES_BUILD_NOTES_FORM)({'vehicle__name':sourceShortName,
                                                                     'flight__group_name':episode.shortName})
   
    ctx = {
        'episode': episode,
        'isLive': True,
        'zipped': zip(sources, noteForms),
        'SSE': settings.XGDS_SSE,
        'modelName': noteModelName,
        'flightName': episode.shortName,
        'flightTZ': settings.TIME_ZONE,
        'searchModelDict': {noteModelName:settings.XGDS_MAP_SERVER_JS_MAP[noteModelName]},
        'searchForms': {noteModelName: [noteForm,settings.XGDS_MAP_SERVER_JS_MAP[noteModelName]] },
        'app': 'xgds_map_server/js/search/mapViewerSearchApp.js',
        'templates': get_handlebars_templates(list(settings.XGDS_MAP_SERVER_HANDLEBARS_DIRS), 'XGDS_MAP_SERVER_HANDLEBARS_DIRS'),
    }

    if settings.XGDS_VIDEO_EXTRA_VIDEO_CONTEXT:
        extraVideoContextFn = getClassByName(settings.XGDS_VIDEO_EXTRA_VIDEO_CONTEXT)
        extraVideoContextFn(ctx)

    theTemplate = 'xgds_video/map_live_playbacks.html'

    return render_to_response(theTemplate,
                              ctx,
                              context_instance=RequestContext(request))
コード例 #7
0
def getImageImportPage(request):
    # map plus image templates for now
    templates = get_handlebars_templates(XGDS_IMAGE_TEMPLATE_LIST,
                                         'XGDS_IMAGE_TEMPLATE_LIST')
    data = {
        'imageSetsJson': [],
        'templates': templates,
        'form': UploadFileForm(),
        'imageSetForm': ImageSetForm()
    }
    return render(
        request,
        "xgds_image/imageImport.html",
        data,
    )
コード例 #8
0
def getImageImportPage(request):
    # map plus image templates for now
    templates = get_handlebars_templates(XGDS_IMAGE_TEMPLATE_LIST,
                                         'XGDS_IMAGE_TEMPLATE_LIST')
    data = {
        'imageSetsJson': [],
        'templates': templates,
        'form': UploadFileForm(),
        'imageSetForm': ImageSetForm(),
        'title': 'Import ' + settings.XGDS_IMAGE_IMAGE_SET_MONIKER,
        'help_content_path': 'xgds_image/help/import.rst'
    }
    return render(
        request,
        "xgds_image/imageImport.html",
        data,
    )
コード例 #9
0
ファイル: views.py プロジェクト: xgds/xgds_sample
def saveSampleInfo(request):
    getSampleInfoUrl = reverse('xgds_sample_get_info')
    sampleMapDict = None
    if request.method == "POST":
        data = request.POST.dict()
        fieldsEnabledFlag = 1  # input fields can be edited.
        pk = data['pk']
        if pk:
            try:
                sample = SAMPLE_MODEL.get().objects.get(pk=int(pk))
            except:
                sample = None
        else: 
            # create a new sample.
            labelNum = int(data['hidden_labelNum'])
            label, created = LABEL_MODEL.get().objects.get_or_create(number=labelNum)
            sample = SAMPLE_MODEL.get().objects.create(label = label)
        if sample:            
            form = SampleForm(request.POST, instance=sample)
            try:
                if form.is_valid():
                    form.save()
                    fieldsEnabledFlag = 0  # disable fields if successfuly saved.
                    messages.success(request, 'Sample %s successfully updated.' % sample.name)  
            except:
                messages.error(request, 'Sample %s could not be saved.' % sample.name)  
            if form.errors:
                for key, msg in form.errors.items():
                    if key == 'warning':
                        messages.warning(request, msg)
                    elif key == 'error':
                        messages.error(request, msg)
            mapDict = sample.toMapDict()
            sampleMapDict = json.dumps([mapDict], indent=4, cls=DatetimeJsonEncoder)
            form = SampleForm(request.POST)
        return render_to_response('xgds_sample/sampleEdit.html',
                          RequestContext(request, {'form': form,
                                                   'users': getUserNames(),
                                                   'modelName': settings.XGDS_SAMPLE_SAMPLE_KEY,
                                                   'templates': get_handlebars_templates(list(settings.XGDS_MAP_SERVER_HANDLEBARS_DIRS), 'XGDS_MAP_SERVER_HANDLEBARS_DIRS'),
                                                   'sampleMapDict': sampleMapDict,
                                                   'getSampleInfoUrl': getSampleInfoUrl,
                                                   'fieldsEnabledFlag': fieldsEnabledFlag})
                                                   )      
コード例 #10
0
ファイル: views.py プロジェクト: xgds/xgds_sample
def getSampleEditPage(request, samplePK = None):
    fieldsEnabledFlag = 0  # initially, sample info fields are disabled until user presses enter to submit label number or name
    getSampleInfoUrl = reverse('xgds_sample_get_info')
    sample = None
    sampleMapDict = None
    if samplePK:
        sample = SAMPLE_MODEL.get().objects.get(pk=samplePK)
        fieldsEnabledFlag = 1  # if we get to this page from sample view, enable the fields.
        mapDict = sample.toMapDict()
        sampleMapDict = json.dumps([mapDict], indent=4, cls=DatetimeJsonEncoder)
    form = SampleForm(instance=sample)
    return render_to_response('xgds_sample/sampleEdit.html',
                              RequestContext(request, {'form': form,
                                                       'users': getUserNames(),
                                                       'modelName': settings.XGDS_SAMPLE_SAMPLE_KEY,
                                                       'templates': get_handlebars_templates(list(settings.XGDS_MAP_SERVER_HANDLEBARS_DIRS), 'XGDS_MAP_SERVER_HANDLEBARS_DIRS'),
                                                       'sampleMapDict': sampleMapDict,
                                                       'getSampleInfoUrl': getSampleInfoUrl,
                                                       'fieldsEnabledFlag': fieldsEnabledFlag})
                              )      
コード例 #11
0
def editImage(request, imageSetID):
    imageSet = IMAGE_SET_MODEL.get().objects.get(pk=imageSetID)
    if request.POST:
        form = ImageSetForm(request.POST, instance=imageSet)
        if form.is_valid():
            form.save()
            if form.errors:
                for key, msg in form.errors.items():
                    if key == 'warning':
                        messages.warning(request, msg)
                    elif key == 'error':
                        messages.error(request, msg)
            else:
                messages.success(
                    request, settings.XGDS_IMAGE_IMAGE_SET_MONIKER +
                    ' successfully updated.')
            return HttpResponseRedirect(
                reverse('search_map_single_object',
                        kwargs={
                            'modelPK': imageSetID,
                            'modelName': settings.XGDS_IMAGE_IMAGE_MODEL_NAME
                        }))
        else:
            messages.error(request, 'The form is not valid')
            return render(request, 'xgds_image/imageEdit.html', {'form': form})
    elif request.method == "GET":
        form = ImageSetForm(instance=imageSet)
        return render(
            request, 'xgds_image/imageEdit.html', {
                'form':
                form,
                'templates':
                get_handlebars_templates(
                    list(settings.XGDS_MAP_SERVER_HANDLEBARS_DIRS),
                    'XGDS_MAP_SERVER_HANDLEBARS_DIRS')
            })
コード例 #12
0
ファイル: views.py プロジェクト: sophsoph321/xgds_planner2
def aggregate_handlebars_templates(request):
    """
    Return a JSON object containing all the Handlebars templates in the
    appropriate templates directory, indexed by name.
    """
    return HttpResponse(json.dumps(get_handlebars_templates(settings.XGDS_PLANNER2_HANDLEBARS_DIRS), 'XGDS_PLANNER2_HANDLEBARS_DIRS'), content_type='application/json')
コード例 #13
0
def getVideoContext(request, flightName=None, sourceShortName=None, time=None):
    requestedTime = ""
    active = False
    episode = {}
    if time is not None:
        # TODO: this is a duplicate path for playing back video at a certain time, it is legacy from PLRP
        # and was not fully working there; merge these 2 ways of playing back from a time.
        # time is passed as string (yy-mm-dd hh:mm:ss)
        try:
            requestedTime = datetime.datetime.strptime(time,
                                                       "%Y-%m-%d %H:%M:%S")
        except:
            try:
                requestedTime = datetime.datetime.strptime(
                    time, "%Y-%m-%d %H:%M:%S+00:00")
            except:
                requestedTime = dateparse.parse_datetime(time)

    GET_ACTIVE_EPISODE_METHOD = getClassByName(
        settings.XGDS_VIDEO_GET_ACTIVE_EPISODE)
    activeepisode = GET_ACTIVE_EPISODE_METHOD()

    # this happens when user clicks on a flight name to view video
    if flightName:
        try:
            GET_EPISODE_FROM_NAME_METHOD = getClassByName(
                settings.XGDS_VIDEO_GET_EPISODE_FROM_NAME)
            episode = GET_EPISODE_FROM_NAME_METHOD(flightName)
            if not episode:
                raise Exception('no episode')

            if episode and episode == activeepisode:
                active = True
        except:
            return {}

    # this happens when user looks for live recorded
    if not episode:
        episode = activeepisode
        active = True
    if not episode:
        message = 'Video not found'
        if flightName:
            message += ' for ' + flightName
        else:
            message += ': no live video'
        messages.add_message(request, messages.ERROR, message)
        return redirect(reverse('error'))

    if episode:
        if not flightName:
            flightName = episode.shortName

    # get the segments
    segments = episode.videosegment_set.all()
    if not segments:
        msg = 'Video segments not found '
        if flightName:
            msg = msg + flightName
            return recordedVideoError(request, msg)

    sourceShortName = str(sourceShortName)
    if sourceShortName == 'None':
        sourceShortName = None
    if sourceShortName:
        try:
            source = SOURCE_MODEL.get().objects.get(shortName=sourceShortName)
            segments = segments.filter(source=source)
        except:
            pass

    sources = []
    segmentsDict = {}  # dictionary of segments (in JSON) within given episode
    sourceVehicle = {}
    index = 0
    distinctSources = segments.values('source').distinct()
    for sourceDict in distinctSources:
        source = SOURCE_MODEL.get().objects.get(pk=sourceDict['source'])
        sources.append(source)
        sourceVehicle[source.shortName] = source.vehicleName
        sourceSegments = segments.filter(source=source)
        segmentsDict[source.shortName] = [
            seg.getDict() for seg in sourceSegments
        ]
        form = buildNoteForm([episode], source, request, {'index': index})
        source.form = form
        index = index + 1

    if flightName:
        if flightName.find('_') == -1:
            fullFlightName = flightName + "_" + sources[0].shortName
        else:
            fullFlightName = flightName
        GET_TIMEZONE_FROM_NAME_METHOD = getClassByName(
            settings.XGDS_VIDEO_GET_TIMEZONE_FROM_NAME)
        flightTimezone = GET_TIMEZONE_FROM_NAME_METHOD(str(fullFlightName))
    else:
        flightTimezone = GET_TIMEZONE_FROM_NAME_METHOD(None)

    if not segmentsDict:
        return recordedVideoError(request,
                                  "No video segments found " + flightName)
    segmentsJson = json.dumps(segmentsDict,
                              sort_keys=True,
                              indent=4,
                              cls=DatetimeJsonEncoder)
    episodeJson = json.dumps(episode.getDict(), cls=DatetimeJsonEncoder)

    noteModelName = str(NOTE_MODEL.get().cls_type())
    noteForm = getClassByName(settings.XGDS_NOTES_BUILD_NOTES_FORM)(
        {
            'vehicle__name': sourceShortName,
            'flight__group_name': episode.shortName
        }
    )  #TODO this assumes the episode short name and group flight name are the same

    ctx = {
        'segmentsJson':
        segmentsJson,
        'isLive':
        active,
        'episode':
        episode,
        'episodeJson':
        episodeJson,
        'noteTimeStamp':
        requestedTime,  # in string format yy-mm-dd hh:mm:ss (in utc. converted to local time in js)
        'sources':
        sources,
        'flightName':
        flightName,
        'flightTZ':
        flightTimezone,
        'sourceVehicle':
        json.dumps(sourceVehicle),
        'SSE':
        settings.XGDS_SSE,
        'modelName':
        noteModelName,
        'searchModelDict': {
            noteModelName: settings.XGDS_MAP_SERVER_JS_MAP[noteModelName]
        },
        'searchForms': {
            noteModelName:
            [noteForm, settings.XGDS_MAP_SERVER_JS_MAP[noteModelName]]
        },
        'app':
        'xgds_video/js/mapVideoApp.js',
        'templates':
        get_handlebars_templates(
            list(settings.XGDS_MAP_SERVER_HANDLEBARS_DIRS),
            'XGDS_MAP_SERVER_HANDLEBARS_DIRS'),
    }

    if settings.XGDS_VIDEO_EXTRA_VIDEO_CONTEXT:
        extraVideoContextFn = getClassByName(
            settings.XGDS_VIDEO_EXTRA_VIDEO_CONTEXT)
        extraVideoContextFn(ctx)

    return ctx
コード例 #14
0
ファイル: views.py プロジェクト: xgds/xgds_video
def displayRecordedVideo(request, flightName=None, sourceShortName=None, time=None):
    """ TODO flightName is actually groupName """
    """
    Returns first segment of all sources that are part of a given episode.
    Used for both playing back videos from active episode and also
    for playing videos associated with each note.
    """
    requestedTime = ""
    active = False
    episode = {}
    if time is not None:
        # TODO: this is a duplicate path for playing back video at a certain time, it is legacy from PLRP
        # and was not fully working there; merge these 2 ways of playing back from a time.
        # time is passed as string (yy-mm-dd hh:mm:ss)
        try:
            requestedTime = datetime.datetime.strptime(time, "%Y-%m-%d %H:%M:%S")
        except:
            requestedTime = dateparse.parse_datetime(time)
        requestedTime = util.pythonDatetimeToJSON(requestedTime)  # util.convertUtcToLocal(requestedTime))

    GET_ACTIVE_EPISODE_METHOD = getClassByName(settings.XGDS_VIDEO_GET_ACTIVE_EPISODE)
    activeepisode = GET_ACTIVE_EPISODE_METHOD()

    # this happens when user clicks on a flight name to view video
    if flightName:
        GET_EPISODE_FROM_NAME_METHOD = getClassByName(settings.XGDS_VIDEO_GET_EPISODE_FROM_NAME)
        episode = GET_EPISODE_FROM_NAME_METHOD(flightName)
        if (episode != None and episode == activeepisode):
            active = True

    # this happens when user looks for live recorded
    if not episode:
        episode = activeepisode
        active = True
    if not episode:
        message = 'Video not found'
        if flightName:
            message += ' for ' + flightName
        else:
            message += ': no live video'
        messages.add_message(request, messages.ERROR, message)
        return redirect(reverse('error'))

    if episode:
        if not flightName:
            flightName = episode.shortName

    # get the segments
    segments = episode.videosegment_set.all()
    if not segments:
        msg = 'Video segments not found '
        if flightName:
            msg = msg + flightName
            return recordedVideoError(request, msg)

    sourceShortName = str(sourceShortName)
    if sourceShortName == 'None':
        sourceShortName = None
    if sourceShortName:
        try:
            source = SOURCE_MODEL.get().objects.get(shortName=sourceShortName)
            segments = segments.filter(source=source)
        except:
            pass

    sources = []
    segmentsDict = {}  # dictionary of segments (in JSON) within given episode
    sourceVehicle = {}
    index = 0
    distinctSources = segments.values('source').distinct()
    for sourceDict in distinctSources:
        source = SOURCE_MODEL.get().objects.get(pk=sourceDict['source'])
        sources.append(source)
        sourceVehicle[source.shortName] = source.vehicleName
        sourceSegments = segments.filter(source=source)
        segmentsDict[source.shortName] = [seg.getDict() for seg in sourceSegments]
        form = buildNoteForm([episode], source, request, {'index':index})
        source.form = form
        index = index + 1

    if flightName:
        if flightName.find('_') == -1:
            fullFlightName = flightName + "_" + sources[0].shortName
        else:
            fullFlightName = flightName
        GET_TIMEZONE_FROM_NAME_METHOD = getClassByName(settings.XGDS_VIDEO_GET_TIMEZONE_FROM_NAME)
        flightTimezone = GET_TIMEZONE_FROM_NAME_METHOD(str(fullFlightName))
    else:
        flightTimezone = GET_TIMEZONE_FROM_NAME_METHOD(None)

    if not segmentsDict:
        return recordedVideoError(request, "No video segments found " + flightName)
    segmentsJson = json.dumps(segmentsDict, sort_keys=True, indent=4, cls=DatetimeJsonEncoder)
    episodeJson = json.dumps(episode.getDict())

    theTemplate = 'xgds_video/map_recorded_playbacks.html'
    if active:
        theTemplate = 'xgds_video/map_active_playbacks.html'

    noteModelName = str(NOTE_MODEL.get().cls_type())
    noteForm = getClassByName(settings.XGDS_NOTES_BUILD_NOTES_FORM)({'vehicle__name':sourceShortName,
                                                                     'flight__group_name':flightName})
    ctx = {
        'segmentsJson': segmentsJson,
        'episode': episode,
        'isLive': active,
        'episodeJson': episodeJson,
        'noteTimeStamp': requestedTime,  # in string format yy-mm-dd hh:mm:ss (in utc. converted to local time in js)
        'sources': sources,
        'flightName': flightName,
        'flightTZ': flightTimezone,
        'sourceVehicle': json.dumps(sourceVehicle),
        'SSE': settings.XGDS_SSE,
        'modelName': noteModelName,
        'searchModelDict': {noteModelName:settings.XGDS_MAP_SERVER_JS_MAP[noteModelName]},
        'searchForms': {noteModelName: [noteForm,settings.XGDS_MAP_SERVER_JS_MAP[noteModelName]] },
        'app': 'xgds_map_server/js/search/mapViewerSearchApp.js',
        'templates': get_handlebars_templates(list(settings.XGDS_MAP_SERVER_HANDLEBARS_DIRS), 'XGDS_MAP_SERVER_HANDLEBARS_DIRS'),
    }

    if settings.XGDS_VIDEO_EXTRA_VIDEO_CONTEXT:
        extraVideoContextFn = getClassByName(settings.XGDS_VIDEO_EXTRA_VIDEO_CONTEXT)
        extraVideoContextFn(ctx)

    return render_to_response(theTemplate,
                              ctx,
                              context_instance=RequestContext(request))
コード例 #15
0
def displayLiveVideo(request, sourceShortName=None):
    """ Directly display RTSP feeds for the active episode.  
    This will either include all sources or be for a single source if it is passed in..
    """
    GET_ACTIVE_EPISODE_METHOD = getClassByName(
        settings.XGDS_VIDEO_GET_ACTIVE_EPISODE)
    episode = GET_ACTIVE_EPISODE_METHOD()
    if not episode:
        messages.add_message(request, messages.ERROR,
                             'There is no live video.')
        return redirect(reverse('error'))

    sources = []
    noteForms = []
    if sourceShortName:
        try:
            source = SOURCE_MODEL.get().objects.get(
                shortName=str(sourceShortName))
            sources.append(source)
            noteForms.append(
                buildNoteForm([episode], source, request, {'index': 0}))
        except:
            pass
    else:
        # get sources and get feeds
        sources = SOURCE_MODEL.get().objects.filter(
            videosegment__episode=episode).distinct()
        for index, source in enumerate(sources):
            noteForms.append(
                buildNoteForm([episode], source, request, {'index': index}))

    noteModelName = str(NOTE_MODEL.get().cls_type())
    #     noteForm = getClassByName(settings.XGDS_NOTES_BUILD_NOTES_FORM)({'vehicle__name':sourceShortName,
    #                                                                      'flight__group_name':episode.shortName})

    theFilter = {}
    if settings.XGDS_VIDEO_NOTE_FILTER_FUNCTION:
        noteFilterFn = getClassByName(settings.XGDS_VIDEO_NOTE_FILTER_FUNCTION)
        theFilter = noteFilterFn(episode, sourceShortName)

    searchForms = getSearchForms(noteModelName, theFilter)

    ctx = {
        'episode':
        episode,
        'isLive':
        True,
        'zipped':
        zip(sources, noteForms),
        'SSE':
        settings.XGDS_SSE,
        'modelName':
        noteModelName,
        'flightName':
        episode.shortName,
        'flightTZ':
        settings.TIME_ZONE,
        'searchModelDict': {
            noteModelName: settings.XGDS_MAP_SERVER_JS_MAP[noteModelName]
        },
        'searchForms':
        searchForms,
        #         'searchForms': {noteModelName: [noteForm,settings.XGDS_MAP_SERVER_JS_MAP[noteModelName]] },
        'app':
        'xgds_video/js/mapVideoApp.js',
        'templates':
        get_handlebars_templates(
            list(settings.XGDS_MAP_SERVER_HANDLEBARS_DIRS),
            'XGDS_MAP_SERVER_HANDLEBARS_DIRS'),
    }

    if settings.XGDS_VIDEO_EXTRA_VIDEO_CONTEXT:
        extraVideoContextFn = getClassByName(
            settings.XGDS_VIDEO_EXTRA_VIDEO_CONTEXT)
        extraVideoContextFn(ctx)

    theTemplate = 'xgds_video/map_live_playbacks.html'

    return render(request, theTemplate, ctx)
コード例 #16
0
ファイル: views.py プロジェクト: xgds/xgds_planner2
def aggregate_handlebars_templates(request):
    """
    Return a JSON object containing all the Handlebars templates in the
    appropriate templates directory, indexed by name.
    """
    return HttpResponse(json.dumps(get_handlebars_templates(settings.XGDS_PLANNER2_HANDLEBARS_DIRS), 'XGDS_PLANNER2_HANDLEBARS_DIRS'), content_type='application/json')
コード例 #17
0
ファイル: views.py プロジェクト: xgds/xgds_image
def getImageImportPage(request):
    # map plus image templates for now
    templates = get_handlebars_templates(XGDS_IMAGE_TEMPLATE_LIST, "XGDS_IMAGE_TEMPLATE_LIST")
    data = {"imageSetsJson": [], "templates": templates, "form": UploadFileForm(), "imageSetForm": ImageSetForm()}
    return render_to_response("xgds_image/imageImport.html", data, context_instance=RequestContext(request))