コード例 #1
0
 def _convert_contacts_to_datasenders(self, contact_short_codes, manager, request):
     datasender_id_email_map = {}
     for contact_short_code in contact_short_codes:
         datasender = contact_by_short_code(manager, contact_short_code)
         if datasender.is_contact:
             datasender.change_status_to_datasender()
             datasender.save(process_post_update=False)
             if datasender.email:
                 datasender_id_email_map.update({datasender.short_code: datasender.email})
         update_datasender_index_by_id(contact_short_code, manager)
     org_id = get_org_id(request)
     create_web_users(org_id, datasender_id_email_map, request.LANGUAGE_CODE)
コード例 #2
0
def _set_email_for_contacts(dbm, org_id, request):
    contact_id_email_map = create_contact_id_email_map(request)
    content, duplicate_entries, errors = validate_email_addresses(contact_id_email_map)
    if errors.__len__() == 0 and duplicate_entries.keys().__len__() == 0:
        web_user_id_email_map = _set_contacts_email_address(dbm, request)
        content = create_web_users(org_id, web_user_id_email_map, request.LANGUAGE_CODE)
    return content
コード例 #3
0
ファイル: datasenders.py プロジェクト: venumurthy/datawinners
def registered_datasenders(request, project_id):
    manager = get_database_manager(request.user)
    questionnaire = Project.get(manager, project_id)
    project_links = get_project_link(questionnaire)
    dashboard_page = settings.HOME_PAGE + "?deleted=true"
    if questionnaire.is_void():
        return HttpResponseRedirect(dashboard_page)
    if request.method == 'GET':
        in_trial_mode = _in_trial_mode(request)
        is_open_survey_allowed = _is_pro_sms(
            request) and not questionnaire.xform
        is_open_survey = 'open' if questionnaire.is_open_survey else 'restricted'
        user_rep_id_name_dict = rep_id_name_dict_of_users(manager)
        return render_to_response(
            'project/registered_datasenders.html', {
                'project': questionnaire,
                'project_links': project_links,
                'questionnaire_code': questionnaire.form_code,
                'current_language': translation.get_language(),
                'is_quota_reached': is_quota_reached(request),
                'in_trial_mode': in_trial_mode,
                'is_open_survey_allowed': is_open_survey_allowed,
                'is_open_survey': is_open_survey,
                'user_dict': json.dumps(user_rep_id_name_dict)
            },
            context_instance=RequestContext(request))
    if request.method == 'POST':
        error_message, failure_imports, success_message, successful_imports = import_module.import_data(
            request,
            manager,
            default_parser=XlsDatasenderParser,
            is_datasender=True)
        imported_data_senders = parse_successful_imports(successful_imports)

        reporter_id_email_map = dict([
            (imported_datasender['id'], imported_datasender['email'])
            for imported_datasender in imported_data_senders
        ])
        org_id = request.user.get_profile().org_id
        create_web_users(org_id, reporter_id_email_map, request.LANGUAGE_CODE)

        imported_datasenders_ids = [
            imported_data_sender["id"]
            for imported_data_sender in imported_data_senders
        ]
        _add_imported_datasenders_to_project(imported_datasenders_ids, manager,
                                             questionnaire)
        convert_open_submissions_to_registered_submissions.delay(
            manager.database_name, imported_datasenders_ids)

        if len(imported_datasenders_ids):
            UserActivityLog().log(request,
                                  action=IMPORTED_DATA_SENDERS,
                                  detail=json.dumps(
                                      dict({
                                          "Unique ID":
                                          "[%s]" %
                                          ", ".join(imported_datasenders_ids)
                                      })),
                                  project=questionnaire.name)
        return HttpResponse(
            json.dumps({
                'success':
                error_message is None and is_empty(failure_imports),
                'message':
                success_message,
                'error_message':
                error_message,
                'failure_imports':
                failure_imports,
                'successful_imports':
                imported_data_senders
            }))
コード例 #4
0
def create_single_web_user(org_id, email_address, reporter_id, language_code):
    """Create single web user from My Data Senders page"""
    return HttpResponse(
        create_web_users(org_id, {reporter_id: email_address}, language_code))
コード例 #5
0
def _set_email_for_contacts(dbm, org_id, request):
    contact_id_email_map = _set_contacts_email_address(dbm, request)
    content = create_web_users(org_id, contact_id_email_map,
                               request.LANGUAGE_CODE)
    return content