Beispiel #1
0
def associate_account_users_to_project(manager, questionnaire):
    user_ids = get_all_user_repids_for_org(
        get_organization_from_manager(manager).org_id)
    # for id in user_ids:
    questionnaire.associate_data_sender_to_project(manager, user_ids)
    for data_senders_code in user_ids:
        update_datasender_index_by_id(data_senders_code, manager)
Beispiel #2
0
    def accept(self, file_contents):
        from datawinners.utils import get_organization_from_manager

        organization = get_organization_from_manager(self.dbm)
        rows = self.parser.parse(file_contents)
        form_model = self._get_form_model(rows)

        responses = []
        for (form_code, values) in rows:
            responses.append(
                self._import_submission(organization, values, form_model))
        return responses
Beispiel #3
0
    def validate_dsid(self):
        sender_id = self.data.get("dsid")
        if sender_id:
            from datawinners.accountmanagement.models import User
            from datawinners.utils import get_organization_from_manager
            org_id = get_organization_from_manager(self.form_model._dbm).org_id
            is_admin = len(
                User.objects.filter(
                    ngouserprofile__org_id=org_id,
                    ngouserprofile__reporter_id=sender_id,
                    groups__name__in=["NGO Admins", "Project Managers"])) > 0

            if self.form_model.is_open_survey or is_admin:
                self.errors.pop("dsid")
Beispiel #4
0
def rep_id_name_dict_of_users(manager):
    org_id = get_organization_from_manager(manager).org_id
    orgUsers = NGOUserProfile.objects.filter(org_id=org_id).values_list(
        "user_id", "reporter_id")

    rep_id_map = {}
    user_id_name_map = {}
    for u in orgUsers:
        rep_id_map.update({u[0]: u[1]})
    users = User.objects.filter(
        groups__name__in=['Project Managers', 'NGO Admins', "Extended Users"],
        id__in=rep_id_map.keys()).values()

    for user in users:
        user_id_name_map[rep_id_map[user["id"]]] = user["first_name"]

    return user_id_name_map
Beispiel #5
0
 def accept(self, file_contents):
     responses = []
     from datawinners.utils import get_organization_from_manager
     organization = get_organization_from_manager(self.dbm)
     registered_phone_numbers = get_all_registered_phone_numbers_on_trial_account() \
         if organization.in_trial_mode else get_datasenders_mobile(self.dbm)
     if type(self.parser) == XlsDatasenderParser:
         registered_emails = User.objects.values_list('email', flat=True)
     else:
         registered_emails = []
     submissions = self.parser.parse(file_contents)
     if len(submissions) > 0:
         (form_code, values) = submissions[0]
         if self.form_code is not None and form_code != self.form_code:
             form_model = get_form_model_by_code(self.dbm, self.form_code)
             raise FormCodeDoesNotMatchException(ugettext(
                 'The file you are uploading is not a list of [%s]. Please check and upload again.'
             ) % form_model.entity_type[0],
                                                 form_code=form_code)
     for (form_code, values) in submissions:
         self.import_submission(form_code, organization, registered_emails,
                                registered_phone_numbers, responses, values)
     return responses
Beispiel #6
0
def _associate_account_users_to_project(manager, questionnaire):
    user_ids = get_all_user_repids_for_org(
        get_organization_from_manager(manager).org_id)
    for id in user_ids:
        questionnaire.associate_data_sender_to_project(manager, id)