def index(request):
    disable_link_class, hide_link_class, page_heading = projects_index(request)
    project_list = get_project_list(request)

    smart_phone_instruction_link = reverse("smart_phone_instruction")

    activation_success = request.GET.get('activation', False)

    if is_crs_admin(request):
        return render_to_response('alldata/index.html',
                                  {'projects': project_list, 'page_heading': page_heading,
                                   'disable_link_class': disable_link_class,
                                   'hide_link_class': hide_link_class, 'is_crs_admin': True,
                                   'project_links': get_alldata_project_links(),
                                   'is_quota_reached':is_quota_reached(request),
                                   'activation_success': activation_success},
                                  context_instance=RequestContext(request))
    else:
        return render_to_response('alldata/index.html',
                                  {'projects': project_list, 'page_heading': page_heading,
                                   'disable_link_class': disable_link_class,
                                   'hide_link_class': hide_link_class, 'is_crs_admin': False,
                                   "smart_phone_instruction_link": smart_phone_instruction_link,
                                   'project_links': get_alldata_project_links(),
                                   'is_quota_reached':is_quota_reached(request),
                                   'activation_success': activation_success},
                                  context_instance=RequestContext(request))
Exemple #2
0
def broadcast_message(request, project_id):
    dbm = get_database_manager(request.user)
    project = Project.load(dbm.database, project_id)
    number_associated_ds = len(project.data_senders)
    number_of_ds = len(import_module.load_all_entities_of_type(dbm, type=REPORTER)[0]) - 1
    questionnaire = FormModel.get(dbm, project.qid)
    organization = utils.get_organization(request)
    if request.method == 'GET':
        form = BroadcastMessageForm(associated_ds=number_associated_ds, number_of_ds=number_of_ds)
        html = 'project/broadcast_message_trial.html' if organization.in_trial_mode else 'project/broadcast_message.html'
        return render_to_response(html, {'project': project,
                                         "project_links": make_project_links(project, questionnaire.form_code),
                                         'is_quota_reached': is_quota_reached(request, organization=organization),
                                         "form": form, "ong_country": organization.country,
                                         "success": None},
                                  context_instance=RequestContext(request))
    if request.method == 'POST':
        form = BroadcastMessageForm(associated_ds=number_associated_ds, number_of_ds=number_of_ds, data=request.POST)
        if form.is_valid():
            no_smsc = False
            data_senders = _get_data_senders(dbm, form, project)
            organization_setting = OrganizationSetting.objects.get(organization=organization)
            current_month = datetime.date(datetime.datetime.now().year, datetime.datetime.now().month, 1)
            message_tracker = organization._get_message_tracker(current_month)
            other_numbers = form.cleaned_data['others']
            failed_numbers = []
            try:
                failed_numbers = helper.broadcast_message(data_senders, form.cleaned_data['text'],
                                                          organization_setting.get_organisation_sms_number()[0],
                                                          other_numbers,
                                                          message_tracker,
                                                          country_code=organization.get_phone_country_code())
            except NoSMSCException as e:
                no_smsc = True
            success = not no_smsc and len(failed_numbers) == 0

            if success:
                form = BroadcastMessageForm(associated_ds=number_associated_ds, number_of_ds=number_of_ds)
            else:
                form = BroadcastMessageForm(associated_ds=number_associated_ds, number_of_ds=number_of_ds,
                                            data=request.POST)
            return render_to_response('project/broadcast_message.html',
                                      {'project': project,
                                       "project_links": make_project_links(project, questionnaire.form_code),
                                       'is_quota_reached': is_quota_reached(request, organization=organization),
                                       "form": form,
                                       "ong_country": organization.country, "no_smsc": no_smsc,
                                       'failed_numbers': ",".join(failed_numbers), "success": success},
                                      context_instance=RequestContext(request))

        return render_to_response('project/broadcast_message.html',
                                  {'project': project,
                                   "project_links": make_project_links(project, questionnaire.form_code), "form": form,
                                   'is_quota_reached': is_quota_reached(request, organization=organization),
                                   'success': None, "ong_country": organization.country},
                                  context_instance=RequestContext(request))
Exemple #3
0
def index(request):
    disable_link_class, hide_link_class, page_heading = projects_index(request)
    rows = get_project_list(request)
    project_list = []
    project_list.sort(key=itemgetter('name'))
    smart_phone_instruction_link = reverse("smart_phone_instruction")
    for project in rows:
        project_id = project['project_id']
        delete_links = reverse('delete_projects', args=[project_id])
        project = dict(delete_links=delete_links,
                       name=project['name'],
                       created=project['created'],
                       qid=project['qid'],
                       link=project['link'],
                       web_submission_link_disabled=project['web_submission_link_disabled'],
                       web_submission_link=project['web_submission_link'],
                       analysis=project['analysis'],
                       disabled=project['disabled'],
                       log=project['log'],
                       create_subjects_link=project['create_subjects_link'],
                       entity_type=project['entity_type'],
                       encoded_name=project['encoded_name'],
                       import_template_file_name=project['import_template_file_name']
        )

        project_list.append(project)
    activation_success = request.GET.get('activation', False)

    error_messages = []
    if "associate" in request.GET.keys():
        error_messages = [_('You may have been dissociated from the project. Please contact your administrator for more details.')]
    if is_crs_admin(request):
        return render_to_response('alldata/index.html',
                                  {'projects': project_list, 'page_heading': page_heading,
                                   'disable_link_class': disable_link_class,
                                   'hide_link_class': hide_link_class, 'is_crs_admin': True,
                                   'project_links': get_alldata_project_links(),
                                   'is_quota_reached':is_quota_reached(request),
                                   'error_messages': error_messages,
                                   'activation_success': activation_success},
                                  context_instance=RequestContext(request))
    else:
        return render_to_response('alldata/index.html',
                                  {'projects': project_list, 'page_heading': page_heading,
                                   'disable_link_class': disable_link_class,
                                   'hide_link_class': hide_link_class, 'is_crs_admin': False,
                                   "smart_phone_instruction_link": smart_phone_instruction_link,
                                   'project_links': get_alldata_project_links(),
                                   'is_quota_reached':is_quota_reached(request),
                                   'error_messages': error_messages,
                                   'activation_success': activation_success},
                                  context_instance=RequestContext(request))
Exemple #4
0
def index(request):
    organization = get_organization(request)
    page_heading = get_page_heading(request)
    hide_for_data_sender = 'none' if request.user.get_profile(
    ).reporter else ''
    rows = get_project_list(request)
    project_list = []
    smart_phone_instruction_link = reverse("smart_phone_instruction")
    local_time_delta = get_country_time_delta(organization.country)
    for project in rows:
        project_list.append(
            _construct_project_dict(request.user, local_time_delta, project))
    project_list.sort(key=itemgetter('name'))

    activation_success = request.GET.get('activation', False)

    error_messages = []
    if "associate" in request.GET.keys():
        error_messages = [
            _('You may have been dissociated from the project. Please contact your administrator for more details.'
              )
        ]
    if is_crs_admin(request):
        return render_to_response('alldata/index.html', {
            'projects': project_list,
            'page_heading': page_heading,
            'is_crs_admin': True,
            'project_links': get_alldata_project_links(),
            'is_quota_reached': is_quota_reached(request),
            'error_messages': error_messages,
            'is_pro_sms': organization.is_pro_sms,
            'activation_success': activation_success,
            'hide_for_data_sender': hide_for_data_sender,
            'current_lang': get_language()
        },
                                  context_instance=RequestContext(request))
    else:
        return render_to_response('alldata/index.html', {
            'projects': project_list,
            'page_heading': page_heading,
            'is_crs_admin': False,
            "smart_phone_instruction_link": smart_phone_instruction_link,
            'project_links': get_alldata_project_links(),
            'is_quota_reached': is_quota_reached(request),
            'error_messages': error_messages,
            'is_pro_sms': organization.is_pro_sms,
            'activation_success': activation_success,
            'hide_for_data_sender': hide_for_data_sender,
            'current_lang': get_language()
        },
                                  context_instance=RequestContext(request))
Exemple #5
0
def index(request):
    organization = get_organization(request)
    page_heading = get_page_heading(request)
    hide_for_data_sender = 'none' if request.user.get_profile(
    ).reporter else ''
    project_list = []
    smart_phone_instruction_link = reverse("smart_phone_instruction")

    activation_success = request.GET.get('activation', False)

    error_messages = []
    if "associate" in request.GET.keys():
        error_messages = [
            _('You may have been dissociated from the project. Please contact your administrator for more details.'
              )
        ]
    if is_crs_admin(request):
        return render_to_response('alldata/index.html', {
            'projects': project_list,
            'page_heading': page_heading,
            'is_crs_admin': True,
            'project_links': get_alldata_project_links(),
            'is_quota_reached': is_quota_reached(request),
            'error_messages': error_messages,
            'is_pro_sms': organization.is_pro_sms,
            'activation_success': activation_success,
            'hide_for_data_sender': hide_for_data_sender,
            'hide_link_class': hide_for_data_sender,
            'current_lang': get_language()
        },
                                  context_instance=RequestContext(request))
    else:
        return render_to_response('alldata/index.html', {
            'projects': project_list,
            'page_heading': page_heading,
            'is_crs_admin': False,
            "smart_phone_instruction_link": smart_phone_instruction_link,
            'project_links': get_alldata_project_links(),
            'is_quota_reached': is_quota_reached(request),
            'error_messages': error_messages,
            'is_pro_sms': organization.is_pro_sms,
            'activation_success': activation_success,
            'hide_for_data_sender': hide_for_data_sender,
            'hide_link_class': hide_for_data_sender,
            'user_group': request.user.groups.all()[0].name,
            'current_lang': get_language()
        },
                                  context_instance=RequestContext(request))
Exemple #6
0
def failed_submissions(request):
    disable_link_class, hide_link_class, page_heading = projects_index(request)
    header_dict = OrderedDict([('from_number', 'Data Sender'),
                               ('created_at', 'Submission Date'),
                               ('form_code', 'Questionnaire Code'),
                               ('message', 'SMS Text'),
                               ('error1', 'Error Message')])
    organization = get_organization(request)

    return render_to_response('alldata/failed_submissions.html', {
        'page_heading':
        page_heading,
        'failedsubmissions_headers':
        header_dict,
        'disable_link_class':
        disable_link_class,
        'hide_link_class':
        hide_link_class,
        'is_crs_admin':
        is_crs_admin(request),
        'project_links':
        get_alldata_project_links(),
        'is_quota_reached':
        is_quota_reached(request, organization=organization)
    },
                              context_instance=RequestContext(request))
Exemple #7
0
def sent_reminders(request, project_id):
    dbm = get_database_manager(request.user)
    dashboard_page = settings.HOME_PAGE + "?deleted=true"
    questionnaire = Project.get(dbm, project_id)
    if questionnaire.is_void():
        return HttpResponseRedirect(dashboard_page)
    organization = Organization.objects.get(
        org_id=request.user.get_profile().org_id)
    is_trial_account = organization.in_trial_mode
    html = 'project/sent_reminders_trial.html' if organization.in_trial_mode else 'project/sent_reminders.html'
    return render_to_response(html, {
        'project':
        questionnaire,
        "project_links":
        make_project_links(questionnaire),
        'is_quota_reached':
        is_quota_reached(request, organization=organization),
        'reminders':
        get_all_reminder_logs_for_project(project_id, dbm),
        'in_trial_mode':
        is_trial_account,
        'questionnaire_code':
        questionnaire.form_code
    },
                              context_instance=RequestContext(request))
Exemple #8
0
def subject_registration_form_preview(request,
                                      project_id=None,
                                      entity_type=None):
    manager = get_database_manager(request.user)
    questionnaire = Project.get(manager, project_id)
    dashboard_page = settings.HOME_PAGE + "?deleted=true"
    if questionnaire.is_void():
        return HttpResponseRedirect(dashboard_page)
    if not entity_type:
        entity_type = questionnaire.entity_type[0]
    if request.method == "GET":
        fields, project_links, questions, registration_questionnaire = _get_registration_form(
            manager, questionnaire, entity_type)
        example_sms = get_example_sms_message(
            fields, registration_questionnaire.form_code)
        return render_to_response(
            'project/questionnaire_preview_list.html', {
                "questions": questions,
                'questionnaire_code': registration_questionnaire.form_code,
                'project': questionnaire,
                'project_links': project_links,
                'is_quota_reached': is_quota_reached(request),
                'example_sms': example_sms,
                'org_number': get_organization_telephone_number(request)
            },
            context_instance=RequestContext(request))
Exemple #9
0
def edit_my_subject_questionnaire(request, project_id, entity_type=None):
    manager = get_database_manager(request.user)
    questionnaire = Project.get(manager, project_id)
    if not entity_type:
        entity_type = questionnaire.entity_type[0]
    project_links = get_project_link(questionnaire, entity_type)
    dashboard_page = settings.HOME_PAGE + "?deleted=true"
    if questionnaire.is_void():
        return HttpResponseRedirect(dashboard_page)
    reg_form = _get_subject_form_model(manager, entity_type)
    if reg_form is None:
        reg_form = form_model.get_form_model_by_code(manager,
                                                     REGISTRATION_FORM_CODE)
    fields = reg_form.fields
    existing_questions = json.dumps(fields, default=field_to_json)
    subject = get_entity_type_info(entity_type, manager=manager)
    return render_to_response('project/subject_questionnaire.html', {
        'project': questionnaire,
        'entity_type': entity_type,
        'project_links': project_links,
        'is_quota_reached': is_quota_reached(request),
        'existing_questions': repr(existing_questions),
        'questionnaire_code': reg_form.form_code,
        'language': reg_form.activeLanguages[0],
        'project_id': questionnaire.id,
        'subject': subject,
        'post_url': reverse(subject_save_questionnaire)
    },
                              context_instance=RequestContext(request))
Exemple #10
0
 def response_for_get_request(self, initial_data=None, is_update=False):
     dashboard_page = settings.HOME_PAGE + "?deleted=true"
     if self.questionnaire.is_void():
         return HttpResponseRedirect(dashboard_page)
     questionnaire_form = self.form(initial_data=initial_data)
     form_context = get_form_context(self.questionnaire,
                                     questionnaire_form,
                                     self.manager,
                                     self.hide_link_class,
                                     self.disable_link_class,
                                     is_update=is_update)
     if self.questionnaire.xform:
         form_context.update({
             'xform_xml':
             re.sub(
                 r"\n", " ",
                 XFormTransformer(
                     self.questionnaire.xform_with_unique_ids_substituted(
                     )).transform())
         })
         form_context.update({'is_advance_questionnaire': True})
         form_context.update(
             {'submission_create_url': reverse('new_web_submission')})
     form_context.update(
         {'is_quota_reached': is_quota_reached(self.request)})
     return render_to_response(self.template,
                               form_context,
                               context_instance=RequestContext(
                                   self.request))
Exemple #11
0
def analysis_results(request, project_id=None, questionnaire_code=None):
    manager = get_database_manager(request.user)
    org_id = helper.get_org_id_by_user(request.user)

    if request.method == 'GET':
        questionnaire = Project.get(manager, project_id)
        dashboard_page = settings.HOME_PAGE + "?deleted=true"
        if questionnaire.is_void():
            return HttpResponseRedirect(dashboard_page)

        filterable_fields = get_filterable_fields(questionnaire.fields, [])
        first_filterable_fields = filterable_fields.pop(
            0) if filterable_fields else None

        result_dict = {
            "xform": questionnaire.xform,
            "user_email": request.user.email,
            "is_quota_reached": is_quota_reached(request, org_id=org_id),
            "first_filterable_field": first_filterable_fields,
            "filterable_fields": filterable_fields,
            'is_pro_sms': get_organization(request).is_pro_sms,
            "is_media_field_present":
            questionnaire.is_media_type_fields_present
            # first 3 columns are additional submission data fields (ds_is, ds_name and submission_status
        }
        result_dict.update(
            project_info(request, questionnaire, questionnaire_code))
        return render_to_response('project/analysis_results.html',
                                  result_dict,
                                  context_instance=RequestContext(request))
Exemple #12
0
def registered_subjects(request, project_id, entity_type=None):
    manager = get_database_manager(request.user)
    questionnaire = Project.get(manager, project_id)
    dashboard_page = settings.HOME_PAGE + "?deleted=true"
    if questionnaire.is_void():
        return HttpResponseRedirect(dashboard_page)
    current_entity_type = entity_type
    if not current_entity_type:
        current_entity_type = questionnaire.entity_type[0]

    subject = get_entity_type_info(current_entity_type, manager=manager)
    project_links = get_project_link(questionnaire, current_entity_type)
    subject_form_model = get_form_model_by_entity_type(manager,
                                                       [current_entity_type])
    in_trial_mode = _in_trial_mode(request)
    return render_to_response(
        'project/subjects/registered_subjects_list.html', {
            'project': questionnaire,
            'project_links': project_links,
            'is_quota_reached': is_quota_reached(request),
            "subject": subject,
            'in_trial_mode': in_trial_mode,
            'project_id': project_id,
            'entity_type': current_entity_type,
            'subject_headers': header_fields(subject_form_model),
            'questionnaire_code': questionnaire.form_code,
            'form_code': subject_form_model.form_code
        },
        context_instance=RequestContext(request))
Exemple #13
0
def questionnaire_preview(request, project_id=None, sms_preview=False):
    manager = get_database_manager(request.user)
    if request.method == 'GET':
        dashboard_page = settings.HOME_PAGE + "?deleted=true"
        questionnaire = Project.get(manager, project_id)
        if questionnaire.is_void():
            return HttpResponseRedirect(dashboard_page)
            #if form_model.is_entity_type_reporter():
        #    fields = helper.hide_entity_question(form_model.fields)
        project_links = make_project_links(questionnaire)
        questions = []
        fields = questionnaire.fields
        for field in fields:
            question = helper.get_preview_for_field(field)
            questions.append(question)
        example_sms = "%s" % (questionnaire.form_code)
        example_sms += get_example_sms(fields)

    template = 'project/questionnaire_preview.html' if sms_preview else 'project/questionnaire_preview_list.html'
    return render_to_response(
        template, {
            "questions": questions,
            'questionnaire_code': questionnaire.form_code,
            'project': questionnaire,
            'project_links': project_links,
            'is_quota_reached': is_quota_reached(request),
            'example_sms': example_sms,
            'org_number': get_organization_telephone_number(request)
        },
        context_instance=RequestContext(request))
Exemple #14
0
def questionnaire(request, project_id):
    manager = get_database_manager(request.user)
    if request.method == 'GET':
        questionnaire = Project.get(manager, project_id)
        if questionnaire.is_void():
            return HttpResponseRedirect(settings.HOME_PAGE + "?deleted=true")
        fields = questionnaire.fields
        existing_questions = json.dumps(fields, default=field_to_json)
        project_links = make_project_links(questionnaire)
        success, error = submission_stats(manager, questionnaire.form_code)
        project_has_submissions = (success + error > 0)
        in_trial_mode = _in_trial_mode(request)
        is_success = False
        active_language = request.LANGUAGE_CODE
        if "success" in [m.message for m in messages.get_messages(request)]:
            is_success = True
        return render_to_response(
            'project/questionnaire.html', {
                "existing_questions": repr(existing_questions),
                'questionnaire_code': questionnaire.form_code,
                'project': questionnaire,
                'project_has_submissions': project_has_submissions,
                'project_links': project_links,
                'is_quota_reached': is_quota_reached(request),
                'in_trial_mode': in_trial_mode,
                'is_success': is_success,
                'active_language': active_language,
                'post_url': reverse(edit_project, args=[project_id]),
                'unique_id_types': get_unique_id_types(manager),
                'preview_links': get_preview_and_instruction_links()
            },
            context_instance=RequestContext(request))
Exemple #15
0
    def response_for_post_request(self, is_update=None):
        questionnaire_form = self.form(self.request.POST)
        quota_reached = is_quota_reached(self.request)
        if not questionnaire_form.is_valid() or quota_reached:
            form_context = get_form_context(self.questionnaire,
                                            questionnaire_form, self.manager,
                                            self.hide_link_class,
                                            self.disable_link_class)
            form_context.update({'is_quota_reached': quota_reached})
            return render_to_response(self.template,
                                      form_context,
                                      context_instance=RequestContext(
                                          self.request))

        success_message = None
        error_message = None
        # if self.is_data_sender:
        #     questionnaire_form.cleaned_data['eid'] = self.request.user.get_profile().reporter_id
        try:
            created_request = helper.create_request(questionnaire_form,
                                                    self.request.user.username,
                                                    is_update=is_update)
            reporter_id = self.request.POST.get('dsid')
            response = self.player_response(created_request, reporter_id)
            if response.success:
                ReportRouter().route(
                    get_organization(self.request).org_id, response)
                success_message = _("Successfully submitted")
            else:
                questionnaire_form._errors = helper.errors_to_list(
                    response.errors, self.questionnaire.fields)
        except DataObjectNotFound as exception:
            logger.exception(exception)
            message = exception_messages.get(DataObjectNotFound).get(WEB)
            error_message = _(message) % (self.questionnaire.entity_type[0],
                                          self.questionnaire.entity_type[0])
        except Exception as exception:
            logger.exception('Web Submission failure:-')
            error_message = _(
                get_exception_message_for(exception=exception,
                                          channel=Channel.WEB))

        _project_context = get_form_context(self.questionnaire,
                                            questionnaire_form,
                                            self.manager,
                                            self.hide_link_class,
                                            self.disable_link_class,
                                            is_update=is_update)

        _project_context.update({
            'success_message': success_message,
            'error_message': error_message,
            'questionnaire_form': self.form(),
        })

        return render_to_response(self.template,
                                  _project_context,
                                  context_instance=RequestContext(
                                      self.request))
Exemple #16
0
 def response_for_get_request(self, initial_data=None, is_update=False):
     questionnaire_form = self.form(initial_data=initial_data)
     form_context = get_form_context(self.form_code, self.project, questionnaire_form,
                                     self.manager, self.hide_link_class, self.disable_link_class, is_update)
     self._update_form_context(form_context, questionnaire_form,
                               web_view_enabled=self.request.GET.get("web_view", False))
     form_context.update({'is_quota_reached': is_quota_reached(self.request)})
     return render_to_response(self.template, form_context, context_instance=RequestContext(self.request))
Exemple #17
0
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)
        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,
                '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)
        imported_data_senders = parse_successful_imports(successful_imports)
        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)

        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
            }))
def failed_submissions(request):
    disable_link_class, hide_link_class, page_heading = projects_index(request)
    organization = get_organization(request)
    org_logs = DatawinnerLog.objects.filter(organization=organization)
    return render_to_response('alldata/failed_submissions.html',
                              {'logs': org_logs, 'page_heading': page_heading,
                               'disable_link_class': disable_link_class,
                               'hide_link_class': hide_link_class, 'is_crs_admin': is_crs_admin(request),
                               'project_links': get_alldata_project_links(),
                               'is_quota_reached':is_quota_reached(request, organization=organization)},
                              context_instance=RequestContext(request))
def registered_datasenders(request, project_id):
    manager = get_database_manager(request.user)
    project, project_links = _get_project_and_project_link(manager, project_id)
    if request.method == 'GET':
        in_trial_mode = _in_trial_mode(request)
        user_rep_id_name_dict = rep_id_name_dict_of_users(manager)
        return render_to_response(
            'project/registered_datasenders.html', {
                'project': project,
                'project_links': project_links,
                'current_language': translation.get_language(),
                'is_quota_reached': is_quota_reached(request),
                'in_trial_mode': in_trial_mode,
                'user_dict': json.dumps(user_rep_id_name_dict)
            },
            context_instance=RequestContext(request))
    if request.method == 'POST':
        error_message, failure_imports, success_message, imported_entities, successful_imports = import_module.import_data(
            request, manager, default_parser=XlsDatasenderParser)
        imported_data_senders = _parse_successful_imports(successful_imports)
        imported_datasenders_ids = [
            imported_data_sender["id"]
            for imported_data_sender in imported_data_senders
        ]
        _add_imported_datasenders_to_project(imported_datasenders_ids, manager,
                                             project)

        if len(imported_datasenders_ids):
            UserActivityLog().log(request,
                                  action=IMPORTED_DATA_SENDERS,
                                  detail=json.dumps(
                                      dict({
                                          "Unique ID":
                                          "[%s]" %
                                          ", ".join(imported_datasenders_ids)
                                      })),
                                  project=project.name)
        org_id = request.user.get_profile().org_id
        _add_imported_datasenders_to_trail_account(imported_data_senders,
                                                   org_id)
        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
            }))
Exemple #20
0
def reminder_settings(request, project_id):
    dbm = get_database_manager(request.user)
    questionnaire = Project.get(dbm, project_id)
    dashboard_page = settings.HOME_PAGE + "?deleted=true"
    if questionnaire.is_void():
        return HttpResponseRedirect(dashboard_page)
    if questionnaire.is_poll:
         return HttpResponseRedirect('/project/'+ project_id + '/results/'+questionnaire.form_code)
    from datawinners.project.views.views import make_project_links


    project_links = make_project_links(questionnaire)
    active_language = request.LANGUAGE_CODE
    org_id = (NGOUserProfile.objects.get(user=request.user)).org_id
    organization = Organization.objects.get(org_id=org_id)
    is_reminder_disabled = is_empty(questionnaire.data_senders)
    url_to_my_datasender = project_links['registered_datasenders_link']
    html = 'project/reminders_trial.html' if organization.in_trial_mode else 'project/reminder_settings.html'
    if request.method == 'GET':
        data = (_reminder_info_about_project(questionnaire))

        return render_to_response(html,
                                  {'project_links': project_links,
                                   'is_quota_reached': is_quota_reached(request, organization=organization),
                                   'project': questionnaire,
                                   'reminder_data': repr(json.dumps(data)),
                                   'questionnaire_code': questionnaire.form_code,
                                   'is_reminder_disabled': is_reminder_disabled,
                                   'active_language': active_language,
                                   'no_of_my_datasenders': len(questionnaire.data_senders),
                                   'is_pro_sms': get_organization(request).is_pro_sms,
                                   'url_to_my_datasender': url_to_my_datasender,
                                   'post_url': reverse(reminder_settings, args=[project_id])
                                  }, context_instance=RequestContext(request))

    if request.method == 'POST':
        post_data = request.POST.copy()
        post_data['should_send_reminder_to_all_ds'] = not post_data['whom_to_send_message'] == 'true'
        post_data = _populate_week_month_data(post_data)
        org_id = NGOUserProfile.objects.get(user=request.user).org_id
        organization = Organization.objects.get(org_id=org_id)
        reminder_list = Reminder.objects.filter(project_id=questionnaire.id)
        action = _get_activity_log_action(reminder_list, post_data)
        questionnaire, set_deadline = _add_reminder_info_to_project(post_data, questionnaire, organization,
                                                              reminder_list=reminder_list)
        questionnaire.save()
        if action is not None:
            UserActivityLog().log(request, action=action, project=questionnaire.name)
        if set_deadline:
            UserActivityLog().log(request, action=SET_DEADLINE, project=questionnaire.name)
        response = {'success_message': ugettext("Reminder settings saved successfully."), 'success': True, 'is_pro_sms': get_organization(request).is_pro_sms,}
        return HttpResponse(json.dumps(response))
Exemple #21
0
    def test_should_return_false_if_quota_not_reached(self):
        message_tracker = self.message_tracker
        message_tracker.incoming_sms_count = 50
        message_tracker.incoming_sp_count = 30
        message_tracker.incoming_web_count = 25
        message_tracker.sms_registration_count = 4

        with patch.object(
                Organization,
                "_get_all_message_trackers") as patch_message_tracker:
            patch_message_tracker.return_value = [message_tracker]
            from datawinners.project.utils import is_quota_reached
            self.assertFalse(is_quota_reached(self.request))
def data_export(request):
    disable_link_class, hide_link_class, page_heading = projects_index(request)
    project_list = sorted(get_project_list(request), key=lambda x: x['name'])
    subject_types = sorted(get_subject_type_list(request))
    registered_subject_types = [each for each in subject_types if each != REPORTER_ENTITY_TYPE];
    return render_to_response('alldata/data_export.html',
                              {'subject_types': subject_types, 'registered_subject_types': registered_subject_types,
                               'projects': project_list, 'page_heading': page_heading,
                               'disable_link_class': disable_link_class,
                               'hide_link_class': hide_link_class, 'is_crs_admin': is_crs_admin(request),
                               'project_links': get_alldata_project_links(),
                               'is_quota_reached':is_quota_reached(request)},
                              context_instance=RequestContext(request))
def reminder_settings(request, project_id):
    dbm = get_database_manager(request.user)
    project = Project.load(dbm.database, project_id)
    questionnaire = FormModel.get(dbm, project.qid)
    from datawinners.project.views.views import make_project_links

    project_links = make_project_links(project, questionnaire.form_code)
    org_id = (NGOUserProfile.objects.get(user=request.user)).org_id
    organization = Organization.objects.get(org_id=org_id)
    html = 'project/reminders_trial.html' if organization.in_trial_mode else 'project/reminder_settings.html'
    if request.method == 'GET':
        form = ReminderForm(data=(_reminder_info_about_project(project)))
        return render_to_response(html,
                                  {'project_links': project_links,
                                   'is_quota_reached': is_quota_reached(request, organization=organization),
                                   'project': project, 'form': form}, context_instance=RequestContext(request))

    if request.method == 'POST':
        form = ReminderForm(data=request.POST.copy())
        if form.is_valid():
            org_id = NGOUserProfile.objects.get(user=request.user).org_id
            organization = Organization.objects.get(org_id=org_id)
            reminder_list = Reminder.objects.filter(project_id=project.id)
            action = _get_activity_log_action(reminder_list, form.cleaned_data)
            project, set_deadline = _add_reminder_info_to_project(form.cleaned_data, project, organization,
                                                                  reminder_list=reminder_list)
            project.save(dbm)
            if action is not None:
                UserActivityLog().log(request, action=action, project=project.name)
            if set_deadline:
                UserActivityLog().log(request, action=SET_DEADLINE, project=project.name)
            messages.success(request, _("Reminder settings saved successfully."))
            return HttpResponseRedirect('')
        else:
            return render_to_response(html,
                                      {'project_links': project_links,
                                       'is_quota_reached': is_quota_reached(request, organization=organization),
                                       'project': project, 'form': form}, context_instance=RequestContext(request))
Exemple #24
0
def submission(request):
    if request.method != 'POST':
        response = HttpResponse(status=204)
        response['Location'] = request.build_absolute_uri()
        return response

    send_to_carbon(create_path('submissions.smartphone'), 1)
    request_user = request.user
    submission_file = request.FILES.get("xml_submission_file").read()
    manager = get_database_manager(request_user)

    if not __authorized_to_make_submission_on_requested_form(request_user, submission_file, manager) \
            or is_quota_reached(request):
        response = HttpResponse(status=403)
        return response

    player = XFormPlayerV2(manager, get_feeds_database(request_user))
    try:
        user_profile = NGOUserProfile.objects.get(user=request_user)
        mangrove_request = Request(
            message=submission_file,
            transportInfo=TransportInfo(transport=SMART_PHONE,
                                        source=request_user.email,
                                        destination=''),
            media=request.FILES if len(request.FILES) > 1 else [])

        response = player.add_survey_response(mangrove_request,
                                              user_profile.reporter_id,
                                              logger=sp_submission_logger)
        mail_feed_errors(response, manager.database_name)
        if response.errors:
            logger.error("Error in submission : \n%s" %
                         get_errors(response.errors))
            return HttpResponseBadRequest()

    except MediaAttachmentNotFoundException as me:
        _send_media_error_mail(request, request_user, user_profile, me.message)
        return HttpResponseBadRequest()

    except Exception as e:
        logger.exception("Exception in submission : \n%s" % e)
        return HttpResponseBadRequest()

    organization = Organization.objects.get(org_id=user_profile.org_id)
    organization.increment_message_count_for(incoming_sp_count=1)

    check_quotas_and_update_users(organization)
    response = HttpResponse(status=201)
    response['Location'] = request.build_absolute_uri(request.path)
    return response
def reports(request):
    report_list = get_reports_list(get_organization(request).org_id, request.session.get('django_language', 'en'))
    if not is_crs_user(request):
        raise Http404

    response = render_to_response('alldata/reports_page.html',
                                  {'reports': report_list, 'page_heading': "All Data",
                                   'project_links': get_alldata_project_links(),
                                   'is_quota_reached':is_quota_reached(request),
                                   'is_crs_admin': True},
                                  context_instance=RequestContext(request))
    response.set_cookie('crs_session_id', request.COOKIES['sessionid'])

    return response
Exemple #26
0
def sent_reminders(request, project_id):
    dbm = get_database_manager(request.user)
    project = Project.load(dbm.database, project_id)
    questionnaire = FormModel.get(dbm, project.qid)
    organization = Organization.objects.get(org_id=request.user.get_profile().org_id)
    is_trial_account = organization.in_trial_mode
    html = 'project/reminders_trial.html' if organization.in_trial_mode else 'project/sent_reminders.html'
    return render_to_response(html,
                              {'project': project,
                               "project_links": make_project_links(project, questionnaire.form_code),
                               'is_quota_reached': is_quota_reached(request, organization=organization),
                               'reminders': get_all_reminder_logs_for_project(project_id, dbm),
                               'in_trial_mode': is_trial_account,
                               'create_reminder_link': reverse(create_reminder, args=[project_id])},
                              context_instance=RequestContext(request))
Exemple #27
0
def subject_registration_form_preview(request, project_id=None):
    manager = get_database_manager(request.user)
    project = Project.load(manager.database, project_id)
    if request.method == "GET":
        fields, project_links, questions, registration_questionnaire = _get_registration_form(manager,
                                                                                              project,
                                                                                              project.entity_type)
        example_sms = get_example_sms_message(fields, registration_questionnaire.form_code)
        return render_to_response('project/questionnaire_preview_list.html',
                                  {"questions": questions, 'questionnaire_code': registration_questionnaire.form_code,
                                   'project': project, 'project_links': project_links,
                                   'is_quota_reached': is_quota_reached(request),
                                   'example_sms': example_sms,
                                   'org_number': get_organization_telephone_number(request)},
                                  context_instance=RequestContext(request))
def analysis_results(request, project_id=None, questionnaire_code=None):
    manager = get_database_manager(request.user)

    form_model = get_form_model_by_code(manager, questionnaire_code)
    org_id = helper.get_org_id_by_user(request.user)

    if request.method == 'GET':
        result_dict = {
            "is_quota_reached": is_quota_reached(request, org_id=org_id),
        }
        result_dict.update(
            project_info(request, manager, form_model, project_id,
                         questionnaire_code))
        return render_to_response('project/analysis_results.html',
                                  result_dict,
                                  context_instance=RequestContext(request))
Exemple #29
0
def registered_subjects(request, project_id=None):
    manager = get_database_manager(request.user)
    project, project_links = _get_project_and_project_link(manager, project_id)
    subject = get_entity_type_info(project.entity_type, manager=manager)
    in_trial_mode = _in_trial_mode(request)
    form_model = get_form_model_by_entity_type(manager, [subject.get('entity')])
    return render_to_response('project/subjects/registered_subjects_list.html',
                              {'project': project,
                               'project_links': project_links,
                               'is_quota_reached': is_quota_reached(request),
                               "subject": subject,
                               'in_trial_mode': in_trial_mode,
                               'project_id': project_id,
                               'entity_type': subject.get('entity'),
                               'subject_headers': header_fields(form_model),
                               'form_code': subject.get('code')}, context_instance=RequestContext(request))
Exemple #30
0
def find_dbm_for_web_sms(request):
    incoming_request = dict()
    MangroveWebSMSRequestProcessor().process(http_request=request, mangrove_request=incoming_request)
    incoming_request['organization'] = get_organization(request)
    incoming_request['test_sms_questionnaire'] = True

    if is_quota_reached(request, organization=incoming_request.get('organization')):
        incoming_request['outgoing_message'] = ''
        return incoming_request

    incoming_request['next_state'] = check_account_and_datasender
    import logging

    websubmission_logger = logging.getLogger("websubmission")
    incoming_request["logger"] = websubmission_logger
    return incoming_request