Merge pull request '20_Multiple_laws' (#23) from 20_Multiple_laws into master
Reviewed-on: SGD-Nord/konova#23
This commit is contained in:
		
						commit
						ce204fff2e
					
				@ -50,6 +50,19 @@
 | 
			
		||||
                        <th scope="row">{% trans 'Intervention handler' %}</th>
 | 
			
		||||
                        <td class="align-middle">{{obj.responsible.handler|default_if_none:""}}</td>
 | 
			
		||||
                    </tr>
 | 
			
		||||
                    <tr>
 | 
			
		||||
                        <th scope="row">{% trans 'Funded by' %}</th>
 | 
			
		||||
                        <td class="align-middle">
 | 
			
		||||
                            {% for funding in obj.fundings.all %}
 | 
			
		||||
                                <div class="badge badge-pill rlp-r-outline">
 | 
			
		||||
                                    {{ funding.short_name}}
 | 
			
		||||
                                </div>
 | 
			
		||||
                                <br>
 | 
			
		||||
                            {% empty %}
 | 
			
		||||
                            {% trans 'None' %}
 | 
			
		||||
                            {% endfor %}
 | 
			
		||||
                        </td>
 | 
			
		||||
                    </tr>
 | 
			
		||||
                    <tr>
 | 
			
		||||
                        <th scope="row">{% trans 'Last modified' %}</th>
 | 
			
		||||
                        <td class="align-middle">
 | 
			
		||||
 | 
			
		||||
@ -31,7 +31,6 @@ class LegalAdmin(admin.ModelAdmin):
 | 
			
		||||
    list_display = [
 | 
			
		||||
        "id",
 | 
			
		||||
        "process_type",
 | 
			
		||||
        "law",
 | 
			
		||||
        "registration_date",
 | 
			
		||||
        "binding_date",
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
@ -412,10 +412,13 @@ class RunCheckForm(BaseModalForm):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
        self.form_title = _("Run check")
 | 
			
		||||
        self.form_caption = _("I, {} {}, confirm that all necessary control steps have been performed by myself.").format(self.user.first_name, self.user.last_name)
 | 
			
		||||
        # Disable automatic w-100 setting for this type of modal form. Looks kinda strange
 | 
			
		||||
        self.fields["confirm"].widget.attrs["class"] = ""
 | 
			
		||||
 | 
			
		||||
    def is_valid(self):
 | 
			
		||||
    def is_valid(self) -> bool:
 | 
			
		||||
        """ Perform a validity check based on quality_check() logic
 | 
			
		||||
 | 
			
		||||
        Returns:
 | 
			
		||||
            result (bool)
 | 
			
		||||
        """
 | 
			
		||||
        super_result = super().is_valid()
 | 
			
		||||
        # Perform check
 | 
			
		||||
        msgs = self.instance.quality_check()
 | 
			
		||||
@ -427,6 +430,11 @@ class RunCheckForm(BaseModalForm):
 | 
			
		||||
        return super_result and (len(msgs) == 0)
 | 
			
		||||
 | 
			
		||||
    def save(self):
 | 
			
		||||
        """ Saving logic
 | 
			
		||||
 | 
			
		||||
        Returns:
 | 
			
		||||
 | 
			
		||||
        """
 | 
			
		||||
        with transaction.atomic():
 | 
			
		||||
            user_action = UserActionLogEntry.objects.create(
 | 
			
		||||
                user=self.user,
 | 
			
		||||
 | 
			
		||||
@ -136,6 +136,7 @@ class RevocationDocument(AbstractDocument):
 | 
			
		||||
                # Folder seems to be missing already
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class LegalData(UuidModel):
 | 
			
		||||
    """
 | 
			
		||||
    Holds intervention legal data such as important dates, laws or responsible handler
 | 
			
		||||
@ -158,11 +159,9 @@ class LegalData(UuidModel):
 | 
			
		||||
            "is_archived": False,
 | 
			
		||||
        }
 | 
			
		||||
    )
 | 
			
		||||
    law = models.ForeignKey(
 | 
			
		||||
    laws = models.ManyToManyField(
 | 
			
		||||
        KonovaCode,
 | 
			
		||||
        on_delete=models.SET_NULL,
 | 
			
		||||
        null=True,
 | 
			
		||||
        related_name="+",
 | 
			
		||||
        blank=True,
 | 
			
		||||
        limit_choices_to={
 | 
			
		||||
            "code_lists__in": [CODELIST_LAW_ID],
 | 
			
		||||
@ -173,13 +172,6 @@ class LegalData(UuidModel):
 | 
			
		||||
 | 
			
		||||
    revocation = models.OneToOneField(Revocation, null=True, blank=True, help_text="Refers to 'Widerspruch am'", on_delete=models.SET_NULL)
 | 
			
		||||
 | 
			
		||||
    def __str__(self):
 | 
			
		||||
        return "{} | {} | {}".format(
 | 
			
		||||
            self.process_type,
 | 
			
		||||
            self.law,
 | 
			
		||||
            self.id
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Intervention(BaseObject):
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
@ -34,9 +34,14 @@
 | 
			
		||||
                        <th scope="row">{% trans 'Process type' %}</th>
 | 
			
		||||
                        <td class="align-middle">{{intervention.legal.process_type|default_if_none:""}}</td>
 | 
			
		||||
                    </tr>
 | 
			
		||||
                    <tr {% if not intervention.legal.law %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
 | 
			
		||||
                    <tr {% if intervention.legal.laws.count == 0 %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
 | 
			
		||||
                        <th scope="row">{% trans 'Law' %}</th>
 | 
			
		||||
                        <td class="align-middle">{{intervention.legal.law|default_if_none:""}}</td>
 | 
			
		||||
                        <td class="align-middle">
 | 
			
		||||
                            {% for law in intervention.legal.laws.all %}
 | 
			
		||||
                                <div class="badge pill-badge rlp-r-outline">{{law.short_name}} - {{law.long_name}}</div>
 | 
			
		||||
                                <br>
 | 
			
		||||
                            {% endfor %}
 | 
			
		||||
                        </td>
 | 
			
		||||
                    </tr>
 | 
			
		||||
                    <tr {% if not intervention.responsible.registration_office %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
 | 
			
		||||
                        <th scope="row">{% trans 'Registration office' %}</th>
 | 
			
		||||
 | 
			
		||||
@ -101,6 +101,37 @@ class BaseForm(forms.Form):
 | 
			
		||||
        for field in disabled_fields:
 | 
			
		||||
            self.disable_form_field(field)
 | 
			
		||||
 | 
			
		||||
    def add_widget_html_class(self, field: str, cls: str):
 | 
			
		||||
        """ Adds a HTML class string to the widget of a field
 | 
			
		||||
 | 
			
		||||
        Args:
 | 
			
		||||
            field (str): The field's name
 | 
			
		||||
            cls (str): The new class string
 | 
			
		||||
 | 
			
		||||
        Returns:
 | 
			
		||||
 | 
			
		||||
        """
 | 
			
		||||
        set_class = self.fields[field].widget.attrs.get("class", "")
 | 
			
		||||
        if cls in set_class:
 | 
			
		||||
            return
 | 
			
		||||
        else:
 | 
			
		||||
            set_class += " " + cls
 | 
			
		||||
        self.fields[field].widget.attrs["class"] = set_class
 | 
			
		||||
 | 
			
		||||
    def remove_widget_html_class(self, field: str, cls: str):
 | 
			
		||||
        """ Removes a HTML class string from the widget of a field
 | 
			
		||||
 | 
			
		||||
        Args:
 | 
			
		||||
            field (str): The field's name
 | 
			
		||||
            cls (str): The new class string
 | 
			
		||||
 | 
			
		||||
        Returns:
 | 
			
		||||
 | 
			
		||||
        """
 | 
			
		||||
        set_class = self.fields[field].widget.attrs.get("class", "")
 | 
			
		||||
        set_class = set_class.replace(cls, "")
 | 
			
		||||
        self.fields[field].widget.attrs["class"] = set_class
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class RemoveForm(BaseForm):
 | 
			
		||||
    check = forms.BooleanField(
 | 
			
		||||
@ -153,17 +184,16 @@ class BaseModalForm(BaseForm, BSModalForm):
 | 
			
		||||
    """
 | 
			
		||||
    is_modal_form = True
 | 
			
		||||
    render_submit = True
 | 
			
		||||
    full_width_fields = False
 | 
			
		||||
    template = "modal/modal_form.html"
 | 
			
		||||
 | 
			
		||||
    def __init__(self, *args, **kwargs):
 | 
			
		||||
    def __init__(self, full_width_fields: bool = True, *args, **kwargs):
 | 
			
		||||
        self.full_width_fields = full_width_fields
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
        # Automatically add bootstrap w-100 class for maximum width of form fields in modals
 | 
			
		||||
        for key, val in self.fields.items():
 | 
			
		||||
            val.widget.attrs.update(
 | 
			
		||||
                {
 | 
			
		||||
                    "class": "w-100"
 | 
			
		||||
                }
 | 
			
		||||
            )
 | 
			
		||||
        if self.full_width_fields:
 | 
			
		||||
            # Automatically add bootstrap w-100 class for maximum width of form fields in modals
 | 
			
		||||
            for key, val in self.fields.items():
 | 
			
		||||
                self.add_widget_html_class(key, "w-100")
 | 
			
		||||
 | 
			
		||||
    def process_request(self, request: HttpRequest, msg_success: str = _("Object removed"), msg_error: str = FORM_INVALID, redirect_url: str = None):
 | 
			
		||||
        """ Generic processing of request
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user