def update_submission_date(response, submission_date):
    submission = Submission.get(dbm, response.submission_id)
    submission._doc.submitted_on = submission_date
    submission._doc.created = submission_date
    submission._doc.event_time = submission_date
    submission.save()
    pprint(submission.values)
Esempio n. 2
0
    def test_should_import_csv_string_if_it_contains_data_about_reporters(
            self):
        organization = Mock(spec=Organization)
        with patch("datawinners.utils.get_organization_from_manager"
                   ) as get_organization_from_dbm_mock:
            with patch("datawinners.entity.import_data.get_form_model_by_code"
                       ) as get_form_model_by_code_mock:
                with patch(
                        "datawinners.entity.import_data.get_location_field_code"
                ) as get_location_field_code_mock:
                    get_organization_from_dbm_mock.return_value = Mock(
                        return_value=organization)
                    form_model = Mock(spec=FormModel)
                    get_form_model_by_code_mock.return_value = form_model
                    form_model.entity_question.code = 'rep987645'
                    get_location_field_code_mock.return_value = Mock()

                    responses = self.file_player.accept(
                        self.csv_data_about_reporter)

        self.assertTrue(responses[0].success)
        submission = Submission.get(self.manager, responses[0].submission_id)
        self.assertEquals(True, submission.status)
        self.assertEquals("csv", submission.channel)
        self.assertEquals("reg", submission.form_code)
        self.assertDictContainsSubset(
            {
                't': 'reporter',
                'n': 'Dr. A',
                'l': 'Pune',
                'd': 'Description',
                'm': '201'
            }, submission.values)
Esempio n. 3
0
 def get_submissions(self,
                     dbm,
                     form_code,
                     from_time,
                     to_time,
                     page_number=0,
                     page_size=None,
                     view_name="submissionlog"):
     startkey, endkey = self._get_start_and_end_key(form_code, from_time,
                                                    to_time)
     if page_size is None:
         rows = dbm.load_all_rows_in_view(view_name,
                                          reduce=False,
                                          descending=True,
                                          startkey=startkey,
                                          endkey=endkey)
     else:
         rows = dbm.load_all_rows_in_view(view_name,
                                          reduce=False,
                                          descending=True,
                                          startkey=startkey,
                                          endkey=endkey,
                                          skip=page_number * page_size,
                                          limit=page_size)
     submissions = [
         Submission.new_from_doc(dbm=dbm,
                                 doc=Submission.__document_class__.wrap(
                                     row['value'])) for row in rows
     ]
     return submissions
Esempio n. 4
0
 def test_should_import_next_value_if_exception_with_previous(self):
     organization = Mock(spec=Organization)
     with patch("datawinners.utils.get_organization_from_manager"
                ) as get_organization_from_dbm_mock:
         get_organization_from_dbm_mock.return_value = Mock(
             return_value=organization)
         responses = self.file_player.accept(self.csv_data_with_exception)
     self.assertTrue(responses[0].success)
     self.assertFalse(responses[1].success)
     self.assertTrue(responses[2].success)
     submission_log = Submission.get(self.manager,
                                     responses[0].submission_id)
     self.assertDictContainsSubset(
         {
             't': 'reporter',
             'n': 'Dr. A',
             'l': 'Pune',
             'd': 'Description',
             'm': '201'
         }, submission_log.values)
     self.assertEquals(
         {
             'error': {
                 'm':
                 u'Sorry, the telephone number 201 has already been registered'
             },
             'row': {
                 't': u'reporter',
                 'n': u'Dr. B',
                 'l': [u'arantany'],
                 'd': u'Description',
                 'm': u'201',
                 's': u'rep3'
             }
         }, responses[1].errors)
     submission_log = Submission.get(self.manager,
                                     responses[2].submission_id)
     self.assertDictContainsSubset(
         {
             't': 'reporter',
             'n': 'Dr. C',
             'l': 'Pune',
             'd': 'Description',
             'm': '202'
         }, submission_log.values)
def create_survey_response(dbm, form_codes, row):
    submission = Submission.new_from_doc(
        dbm=dbm, doc=Submission.__document_class__.wrap(row['value']))
    log_statement('Submission id : %s' % submission.uuid)
    if submission.form_code not in form_codes:
        survey_response = create_survey_response(submission, dbm)
        log_statement('Created survey response id : %s' % survey_response.uuid)
        return True
    else:
        log_statement('Skipping Creation of Survey Response.')
        return False
Esempio n. 6
0
 def test_should_import_csv_string_if_it_contains_data_for_activity_reporters(
         self):
     organization = Mock(spec=Organization)
     with patch("datawinners.utils.get_organization_from_manager"
                ) as get_organization_from_dbm_mock:
         get_organization_from_dbm_mock.return_value = Mock(
             return_value=organization)
         responses = self.file_player.accept(
             self.csv_data_for_activity_report)
     self.assertTrue(responses[0].success)
     submission_log = Submission.get(self.manager,
                                     responses[0].submission_id)
     self.assertEquals("csv", submission_log.channel)
     self.assertEquals(u'rep1', responses[0].short_code)
 def _load_submissions_for(self,
                           questionnaire_code,
                           crs_database_manager,
                           datarecords_id=None):
     startkey = [questionnaire_code]
     endkey = [questionnaire_code, {}]
     print 'loading submissions for %s' % questionnaire_code
     rows = crs_database_manager.view.submissionlog(reduce=False,
                                                    startkey=startkey,
                                                    endkey=endkey)
     return [
         Submission.new_from_doc(dbm=crs_database_manager,
                                 doc=Submission.__document_class__.wrap(
                                     row['value'])) for row in rows
         if row['value']['status'] == True and (
             datarecords_id is None
             or row["value"]["data_record_id"] in datarecords_id)
     ]