Exemple #1
0
def employer(request):
    """Employer application view"""

    encoded_user_id = basic_encode(request.user.id)
    client = ApisvcClient(request.session.session_key)
    current_user_json = client.user(user_id=encoded_user_id)

    app_js = 'js/apps/employer/apps/employer/src/main.js'
    app_url = static(app_js)
    app_md5_ext = ""

    #if app_url contains an md5 extension, extract it and
    #pass it to the template for use with requirejs
    md5_regex = re.compile(r".*(?P<md5_ext>\.[0-9a-f]{12})\..*")
    md5_match = md5_regex.match(app_url)
    if md5_match:
        app_md5_ext = md5_match.groupdict().get("md5_ext")

    context = {
        "current_user_json": json.dumps(current_user_json),
        "app_md5_ext": app_md5_ext
    }

    return render_to_response('employer/employer.html',
                              context,
                              context_instance=RequestContext(request))
Exemple #2
0
def create(request):
    """Create chat session"""

    topic_json = "[]"

    if request.method == 'POST':
        form = forms.TopicForm(request, data=request.POST)
        if form.is_valid():
            created_models_list = form.save(commit=True)
            root_topic = created_models_list[
                0]  # Root topic is expected to be 1st in list
            return HttpResponseRedirect(
                reverse("topic.views.details",
                        args=[basic_encode(root_topic.id)]))
        else:
            topic_json = form.data.get("topics")

    else:
        form = forms.TopicForm(request)

    context = {"form": form, "topic_json": topic_json}

    return render_to_response('topic/create.html',
                              context,
                              context_instance=RequestContext(request))
Exemple #3
0
 def to_python(self, value):
     result = value
     if isinstance(value, int):
         result = basic_encode(value)
     elif not isinstance(value, basestring):
         result = str(value)
     return result
Exemple #4
0
 def to_python(self, value):
     result = value
     if isinstance(value, int):
         result = basic_encode(value)
     elif not isinstance(value, basestring):
         result = str(value)
     return result
Exemple #5
0
def requisition(request):
    """Requisition application view"""

    encoded_user_id = basic_encode(request.user.id)
    client = ApisvcClient(request.session.session_key)
    current_user_json = client.user(user_id=encoded_user_id)

    context = {
        "current_user_json": json.dumps(current_user_json)
    }

    return render_to_response('requisition/requisition.html', context, context_instance=RequestContext(request))
Exemple #6
0
def create(request):
    """Create chat session"""
    
    topic_json = "[]"

    if request.method == 'POST':
        form = forms.TopicForm(request, data=request.POST)
        if form.is_valid():
            created_models_list = form.save(commit=True)
            root_topic = created_models_list[0] # Root topic is expected to be 1st in list
            return HttpResponseRedirect(reverse("topic.views.details", args=[basic_encode(root_topic.id)]))
        else:
            topic_json = form.data.get("topics")

    else:
        form = forms.TopicForm(request)
    
    context = {
            "form": form,
            "topic_json": topic_json
            }
    
    return render_to_response('topic/create.html', context,  context_instance=RequestContext(request))
Exemple #7
0
def developer(request):
    """Developer application view"""

    encoded_user_id = basic_encode(request.user.id)
    client = ApisvcClient(request.session.session_key)
    current_user_json = client.user(user_id=encoded_user_id)
    
    app_js = 'js/apps/developer/apps/developer/src/main.js'
    app_url = static(app_js)
    app_md5_ext = ""
    
    #if app_url contains an md5 extension, extract it and
    #pass it to the template for use with requirejs
    md5_regex = re.compile(r".*(?P<md5_ext>\.[0-9a-f]{12})\..*")
    md5_match = md5_regex.match(app_url)
    if md5_match:
        app_md5_ext = md5_match.groupdict().get("md5_ext")
    
    context = {
        "current_user_json": json.dumps(current_user_json),
        "app_md5_ext": app_md5_ext
    }
    
    return render_to_response('developer/developer.html', context, context_instance=RequestContext(request))
Exemple #8
0
 def encoded_tenant_id(self):
     return basic_encode(self.tenant_id)
Exemple #9
0
 def encoded_id(self):
     return basic_encode(self.id)
Exemple #10
0
 def test_encoding(self):
     self.assertEquals(basic_encode(8), '4fti4g')
     self.assertEquals(basic_decode('4fti4g'), 8)
Exemple #11
0
    def process(self, database_job):
        """Worker thread process method.

        Args:
            database_job: DatabaseJob object wrapping a ChatArchiveJob
                model in a convenient context manager.

        This method will be invoked by each worker thread when
        a new work item (chat_id) is put on the queue.
        """
        try:
            job = None
            with database_job as job:
                chat_id = job.chat_id
                encoded_chat_id = basic_encode(chat_id)
                chat_session = json.loads(job.data)
                output_filename = "archive/%s" % encoded_chat_id
                if self.timestamp_filenames:
                    output_filename += "-%s" % time.time()

                self.log.info("Creating archive for chat_id=%s (%s)" \
                        % (chat_id, encoded_chat_id))
                
                #fetch archive streams
                archive_manifest = self._fetch_archives(
                        chat_id=chat_id,
                        chat_session=chat_session,
                        output_filename=output_filename)
                if archive_manifest is None \
                        or not archive_manifest.archive_streams:
                    self.log.info("No archives for chat_id=%s" \
                            % chat_id)
                    return
    
                #stitch streams
                stitched_archive_streams = self._stitch_archives(
                        chat_id=chat_id,
                        archive_manifest=archive_manifest,
                        output_filename=output_filename)
                
                #generate waveform
                stitched_archive_streams = self._generate_waveform(
                        chat_id=chat_id,
                        archive_streams=stitched_archive_streams,
                        output_filename=output_filename)
                
                #persist streams
                self._persist_archives(
                        chat_id=chat_id,
                        archive_manifest=archive_manifest,
                        stitched_archive_streams=stitched_archive_streams)
                
                #delete fetcher streams
                self._delete_fetcher_streams(chat_id, chat_session)

                self.log.info("Done with archive for chat_id=%s (%s)" \
                        % (chat_id, encoded_chat_id))

        except JobOwned:
            self.log.info("Job for chat_id=%s already owned." \
                    % (job.chat_id))
        except Exception as error:
            if job:
                self.log.error("Job for chat_id=%s failed." \
                        % (job.chat_id))
                self.log.exception(error)
                self._retry_job(job)
            else:
                self.log.error("Job failed but is empty ...")
                self.log.exception(error)
Exemple #12
0
    def process(self, database_job):
        """Worker thread process method.

        Args:
            database_job: DatabaseJob object wrapping a ChatArchiveJob
                model in a convenient context manager.

        This method will be invoked by each worker thread when
        a new work item (chat_id) is put on the queue.
        """
        try:
            job = None
            with database_job as job:
                chat_id = job.chat_id
                encoded_chat_id = basic_encode(chat_id)
                chat_session = json.loads(job.data)
                output_filename = "archive/%s" % encoded_chat_id
                if self.timestamp_filenames:
                    output_filename += "-%s" % time.time()

                self.log.info("Creating archive for chat_id=%s (%s)" \
                        % (chat_id, encoded_chat_id))

                #fetch archive streams
                archive_manifest = self._fetch_archives(
                    chat_id=chat_id,
                    chat_session=chat_session,
                    output_filename=output_filename)
                if archive_manifest is None \
                        or not archive_manifest.archive_streams:
                    self.log.info("No archives for chat_id=%s" \
                            % chat_id)
                    return

                #stitch streams
                stitched_archive_streams = self._stitch_archives(
                    chat_id=chat_id,
                    archive_manifest=archive_manifest,
                    output_filename=output_filename)

                #generate waveform
                stitched_archive_streams = self._generate_waveform(
                    chat_id=chat_id,
                    archive_streams=stitched_archive_streams,
                    output_filename=output_filename)

                #persist streams
                self._persist_archives(
                    chat_id=chat_id,
                    archive_manifest=archive_manifest,
                    stitched_archive_streams=stitched_archive_streams)

                #delete fetcher streams
                self._delete_fetcher_streams(chat_id, chat_session)

                self.log.info("Done with archive for chat_id=%s (%s)" \
                        % (chat_id, encoded_chat_id))

        except JobOwned:
            self.log.info("Job for chat_id=%s already owned." \
                    % (job.chat_id))
        except Exception as error:
            if job:
                self.log.error("Job for chat_id=%s failed." \
                        % (job.chat_id))
                self.log.exception(error)
                self._retry_job(job)
            else:
                self.log.error("Job failed but is empty ...")
                self.log.exception(error)
Exemple #13
0
 def encoded_tenant_id(self):
     return basic_encode(self.tenant_id)
Exemple #14
0
 def encoded_id(self):
     return basic_encode(self.id)