Beispiel #1
0
 def change_unique_id(form):
     unique_id = form['unique_id']
     new_unique_id = FormBase.generate_id()
     form['unique_id'] = new_unique_id
     if ("%s.xml" % unique_id) in app_source['_attachments']:
         app_source['_attachments']["%s.xml" % new_unique_id] = app_source['_attachments'].pop("%s.xml" % unique_id)
     return new_unique_id
Beispiel #2
0
    def clean(self):
        cleaned_data = self.cleaned_data
        sm = cleaned_data["share_multimedia"]
        license = cleaned_data["license"]
        app_ids = self._get_apps_to_publish()

        if sm and license not in self.dom.most_restrictive_licenses(apps_to_check=app_ids):
            license_choices = [LICENSES[l] for l in self.dom.most_restrictive_licenses(apps_to_check=app_ids)]
            msg = render_to_string('domain/partials/restrictive_license.html', {'licenses': license_choices})
            self._errors["license"] = self.error_class([msg])

            del cleaned_data["license"]

        sr = cleaned_data["share_reminders"]
        if sr:  # check that the forms referenced by the events in each reminders exist in the project
            referenced_forms = CaseReminderHandler.get_referenced_forms(domain=self.dom.name)
            if referenced_forms:
                apps = [Application.get(app_id) for app_id in app_ids]
                app_forms = [f.unique_id for forms in [app.get_forms() for app in apps] for f in forms]
                nonexistent_forms = filter(lambda f: f not in app_forms, referenced_forms)
                nonexistent_forms = [FormBase.get_form(f) for f in nonexistent_forms]
                if nonexistent_forms:
                    msg = """
                        Your reminders reference forms that are not being published.
                        Make sure the following forms are being published: %s
                    """ % str([f.default_name() for f in nonexistent_forms]).strip('[]')
                    self._errors["share_reminders"] = self.error_class([msg])

        return cleaned_data
Beispiel #3
0
 def convert_form_unique_id_function(form_unique_id):
     from corehq.apps.app_manager.models import FormBase
     form = FormBase.get_form(form_unique_id)
     form_app = form.get_app()
     m_index, f_index = form_app.get_form_location(form.unique_id)
     form_copy = new_app_components[form_app._id].get_module(m_index).get_form(f_index)
     return form_copy.unique_id
Beispiel #4
0
 def convert_form_unique_id_function(form_unique_id):
     from corehq.apps.app_manager.models import FormBase
     form = FormBase.get_form(form_unique_id)
     form_app = form.get_app()
     m_index, f_index = form_app.get_form_location(form.unique_id)
     form_copy = new_app_components[form_app._id].get_module(m_index).get_form(f_index)
     return form_copy.unique_id
Beispiel #5
0
 def update_events(handler):
     """
     Change the form_unique_id to the proper form for each event in a newly copied CaseReminderHandler
     """
     from corehq.apps.app_manager.models import FormBase
     for event in handler.events:
         if not event.form_unique_id:
             continue
         form = FormBase.get_form(event.form_unique_id)
         form_app = form.get_app()
         m_index, f_index = form_app.get_form_location(form.unique_id)
         form_copy = new_comps[form_app._id].get_module(m_index).get_form(f_index)
         event.form_unique_id = form_copy.unique_id
Beispiel #6
0
 def update_events(handler):
     """
     Change the form_unique_id to the proper form for each event in a newly copied CaseReminderHandler
     """
     from corehq.apps.app_manager.models import FormBase
     for event in handler.events:
         if not event.form_unique_id:
             continue
         form = FormBase.get_form(event.form_unique_id)
         form_app = form.get_app()
         m_index, f_index = form_app.get_form_location(form.unique_id)
         form_copy = new_app_components[form_app._id].get_module(m_index).get_form(f_index)
         event.form_unique_id = form_copy.unique_id
Beispiel #7
0
    def clean(self):
        cleaned_data = self.cleaned_data
        sm = cleaned_data["share_multimedia"]
        license = cleaned_data["license"]
        app_ids = self._get_apps_to_publish()

        if sm and license not in self.dom.most_restrictive_licenses(
                apps_to_check=app_ids):
            license_choices = [
                LICENSES[l] for l in self.dom.most_restrictive_licenses(
                    apps_to_check=app_ids)
            ]
            msg = render_to_string('domain/partials/restrictive_license.html',
                                   {'licenses': license_choices})
            self._errors["license"] = self.error_class([msg])

            del cleaned_data["license"]

        sr = cleaned_data["share_reminders"]
        if sr:  # check that the forms referenced by the events in each reminders exist in the project
            referenced_forms = CaseReminderHandler.get_referenced_forms(
                domain=self.dom.name)
            if referenced_forms:
                apps = [Application.get(app_id) for app_id in app_ids]
                app_forms = [
                    f.unique_id for forms in [app.get_forms() for app in apps]
                    for f in forms
                ]
                nonexistent_forms = filter(lambda f: f not in app_forms,
                                           referenced_forms)
                nonexistent_forms = [
                    FormBase.get_form(f) for f in nonexistent_forms
                ]
                if nonexistent_forms:
                    msg = """
                        Your reminders reference forms that are not being published.
                        Make sure the following forms are being published: %s
                    """ % str([f.default_name()
                               for f in nonexistent_forms]).strip('[]')
                    self._errors["share_reminders"] = self.error_class([msg])

        return cleaned_data