-
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/ad/module-badges-UI' into autost…
…aging
- Loading branch information
Showing
11 changed files
with
325 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
corehq/apps/fixtures/migrations/0011_csqlfixtureexpression_csqlfixtureexpressionlog.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Generated by Django 4.2.16 on 2024-10-29 18:29 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('fixtures', '0010_lookuptable_is_synced'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CSQLFixtureExpression', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('domain', models.CharField(default='', max_length=64)), | ||
('name', models.CharField(default='', max_length=64)), | ||
('csql', models.CharField(default='', max_length=2000)), | ||
('date_created', models.DateTimeField(auto_now_add=True)), | ||
('last_modified', models.DateTimeField(auto_now=True)), | ||
('deleted', models.BooleanField(default=False)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='CSQLFixtureExpressionLog', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('date', models.DateTimeField(auto_now_add=True)), | ||
('action', models.CharField(choices=[('update', 'Updated'), ('create', 'Created'), ('delete', 'Deleted')], max_length=16)), | ||
('name', models.CharField(default='', max_length=64)), | ||
('csql', models.CharField(default='', max_length=2000)), | ||
('expression', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fixtures.csqlfixtureexpression')), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
corehq/apps/fixtures/templates/fixtures/csql_fixture_configuration.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{% extends 'hqwebapp/bootstrap5/base_section.html' %} | ||
{% load hq_shared_tags %} | ||
{% load i18n %} | ||
|
||
{% js_entry_b3 "hqwebapp/js/htmx_and_alpine" %} | ||
|
||
{% block page_title %} | ||
{% trans 'CSQL Fixture Configuration' %} | ||
{% endblock %} | ||
|
||
{% block page_content %} | ||
<div x-data="{ | ||
validationFailed: false, | ||
isDirty: false, | ||
rows: {{ csql_fixture_configurations|safe }}, | ||
addRow() { | ||
this.rows.push({ row: '', csql: '', id: '' }); | ||
}, | ||
deleteRow(index) { | ||
this.rows.splice(index, 1); | ||
this.markDirty(); | ||
}, | ||
markDirty() { | ||
this.isDirty = true; | ||
}, | ||
unmarkDirty() { | ||
this.isDirty = false; | ||
} | ||
}"> | ||
<form hx-post={{ save_url }} action="/submit" method="POST" hx-target="#response-message" hx-swap="innerHTML" | ||
@change="markDirty" @submit="unmarkDirty"> | ||
<div id="response-message"></div> | ||
<button type="submit" class="btn btn-primary" id="Save" x-bind:disabled="!isDirty">{% trans "Save" %}</button> | ||
<p/> | ||
<table class="table table-striped table-bordered"> | ||
<thead> | ||
<tr> | ||
<th class="col-sm-2"> | ||
{% trans "Name" %} | ||
</th> | ||
<th class="col-sm-7"> | ||
{% trans "Case Search QL Expression" %} | ||
</th> | ||
<th class="col-sm-1"> | ||
{% trans "Delete" %} | ||
</th> | ||
</thead> | ||
<tbody> | ||
<template x-for="(row, index) in rows" :key="index"> | ||
<tr> | ||
<td><input class="form-control" type="text" name="name" x-model="row.name" maxlength="64"></td> | ||
<td><textarea class="form-control vertical-resize" spellcheck="false" rows="1" name="csql" | ||
x-model="row.csql" maxlength="2000"></textarea></td> | ||
<td><button class="btn btn-danger" | ||
@click="deleteRow(index)"> | ||
<i class="fa-regular fa-trash-can"></i> | ||
{% trans "Delete" %} | ||
</button></td> | ||
<input type="hidden" name="id" x-model="row.id"> | ||
</tr> | ||
</template> | ||
</tbody> | ||
</table> | ||
<button type="button" class="btn btn-default" @click="addRow()"> | ||
<i class="fa fa-plus"></i> | ||
{% trans "Add Indicator" %} | ||
</button> | ||
<br> | ||
</form> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,14 @@ | |
from corehq.apps.domain.models import Domain | ||
|
||
from corehq.apps.domain.shortcuts import create_domain | ||
from corehq.apps.users.models import WebUser | ||
|
||
from corehq.util.test_utils import flag_enabled | ||
from corehq.apps.fixtures.models import CSQLFixtureExpression, CSQLFixtureExpressionLog | ||
from corehq.apps.fixtures.views import CSQLFixtureExpressionView, update_tables | ||
from corehq.apps.users.dbaccessors import delete_all_users | ||
from corehq.apps.users.models import HqPermissions, WebUser | ||
from corehq.apps.users.models_role import UserRole | ||
from ..interface import FixtureEditInterface | ||
from ..models import LookupTable, LookupTableRow, Field, TypeField | ||
from corehq.apps.fixtures.views import update_tables | ||
|
||
DOMAIN = "lookup" | ||
USER = "[email protected]" | ||
|
@@ -316,3 +319,53 @@ def _create_request(self, method): | |
request.user = request.couch_user = WebUser(is_superuser=True, is_authenticated=True, is_active=True) | ||
|
||
return request | ||
|
||
|
||
@flag_enabled('MODULE_BADGES') | ||
class TestCSQLFixtureExpressionView(TestCase): | ||
|
||
DOMAIN = 'test-domain' | ||
DEFAULT_USER_PASSWORD = 'password' | ||
USERNAME = '[email protected]' | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super(TestCSQLFixtureExpressionView, cls).setUpClass() | ||
cls.domain_obj = create_domain(cls.DOMAIN) | ||
cls.user = WebUser.create( | ||
cls.DOMAIN, cls.USERNAME, cls.DEFAULT_USER_PASSWORD, None, None, is_admin=True | ||
) | ||
cls.role = UserRole.create(cls.DOMAIN, 'Fixtures Access', HqPermissions(edit_data=True)) | ||
cls.user.set_role(cls.DOMAIN, cls.role.get_qualified_id()) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
cls.user.delete(cls.DOMAIN, deleted_by=None) | ||
cls.domain_obj.delete() | ||
delete_all_users() | ||
super(TestCSQLFixtureExpressionView, cls).tearDownClass() | ||
|
||
def _get_view_response(self, data): | ||
self.client.login(username=self.USERNAME, password=self.DEFAULT_USER_PASSWORD) | ||
response = self.client.post(reverse(CSQLFixtureExpressionView.urlname, args=[self.DOMAIN]), data) | ||
return response | ||
|
||
@patch('django_prbac.decorators.has_privilege', return_value=True) | ||
def test_create_update_delete(self, has_privilege): | ||
deleted_exp = CSQLFixtureExpression.objects.create(domain=self.DOMAIN, name='deleted_exp', csql='asdf') | ||
exp2 = CSQLFixtureExpression.objects.create(domain=self.DOMAIN, name='exp2', csql='asdf') | ||
data = { | ||
'id': [exp2.id, ''], | ||
'name': ['exp2', 'exp3'], | ||
'csql': ['asdfg', 'asdf'], | ||
} | ||
response = self._get_view_response(data) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertFalse(CSQLFixtureExpression.objects.filter( | ||
domain=self.DOMAIN, name='deleted_exp', deleted=False).exists()) | ||
CSQLFixtureExpression.objects.get(domain=self.DOMAIN, name='exp2', id=exp2.id, csql='asdfg') | ||
CSQLFixtureExpression.objects.get(domain=self.DOMAIN, name='exp3', csql='asdf') | ||
CSQLFixtureExpressionLog.objects.get(expression=deleted_exp, | ||
action=CSQLFixtureExpressionLog.DELETE) | ||
CSQLFixtureExpressionLog.objects.get(expression=exp2, action=CSQLFixtureExpressionLog.UPDATE) | ||
CSQLFixtureExpressionLog.objects.get(name='exp3', action=CSQLFixtureExpressionLog.CREATE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.