Fix API item default kind
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
<h1 class="h5 m-0">{% if collection %}{% blocktrans with title=collection.title %}Create note for {{ title }}{% endblocktrans %}{% elif requested_kind == 'todo' %}{% trans "Create task" %}{% elif requested_kind == 'link' %}{% trans "Create link" %}{% elif requested_kind == 'journal' %}{% trans "Create journal entry" %}{% else %}{% trans "Create note" %}{% endif %}</h1>
|
<h1 class="h5 m-0">{% if collection %}{% blocktrans with title=collection.title %}Create note for {{ title }}{% endblocktrans %}{% elif requested_kind == 'todo' %}{% trans "Create task" %}{% elif requested_kind == 'link' %}{% trans "Create link" %}{% elif requested_kind == 'journal' %}{% trans "Create journal entry" %}{% else %}{% trans "Create note" %}{% endif %}</h1>
|
||||||
<div class="d-flex gap-2"><button class="btn btn-success px-3 py-2" title="{% trans 'Save' %}">✓</button><a class="btn btn-danger px-3 py-2" href="{{ next_url }}" title="{% trans 'Cancel' %}">×</a></div>
|
<div class="d-flex gap-2"><button class="btn btn-success px-3 py-2" title="{% trans 'Save' %}">✓</button><a class="btn btn-danger px-3 py-2" href="{{ next_url }}" title="{% trans 'Cancel' %}">×</a></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="small text-muted">{% trans "Type:" %} {% if requested_kind == 'todo' %}{% trans "Task" %}{% elif requested_kind == 'link' %}{% trans "Link" %}{% elif requested_kind == 'journal' %}{% trans "Journal" %}{% else %}{% trans "Note" %}{% endif %}</div>
|
||||||
<div class="mobile-tag-picker">
|
<div class="mobile-tag-picker">
|
||||||
<div class="small text-muted mb-1">{% trans "Add tags" %}</div>
|
<div class="small text-muted mb-1">{% trans "Add tags" %}</div>
|
||||||
<div class="d-flex flex-wrap gap-2 p-2 bg-light rounded">
|
<div class="d-flex flex-wrap gap-2 p-2 bg-light rounded">
|
||||||
|
|||||||
@@ -245,6 +245,8 @@ class DefaultItemKindTests(TestCase):
|
|||||||
def test_new_item_editor_uses_user_default(self):
|
def test_new_item_editor_uses_user_default(self):
|
||||||
response = self.client.get(reverse('new_item'))
|
response = self.client.get(reverse('new_item'))
|
||||||
self.assertEqual(response.context['requested_kind'], Item.Kind.TODO)
|
self.assertEqual(response.context['requested_kind'], Item.Kind.TODO)
|
||||||
|
self.assertContains(response, 'Typ:')
|
||||||
|
self.assertContains(response, 'Aufgabe')
|
||||||
|
|
||||||
|
|
||||||
class DueDateCommandTests(TestCase):
|
class DueDateCommandTests(TestCase):
|
||||||
@@ -1122,6 +1124,30 @@ class ApiItemFilterTests(TestCase):
|
|||||||
self.assertEqual(len(items), 1)
|
self.assertEqual(len(items), 1)
|
||||||
self.assertEqual(items[0]['id'], second.id)
|
self.assertEqual(items[0]['id'], second.id)
|
||||||
|
|
||||||
|
def test_api_create_ignores_user_default_kind(self):
|
||||||
|
UserPreference.objects.create(user=self.user, default_item_kind=Item.Kind.TODO)
|
||||||
|
|
||||||
|
response = self.client.post(
|
||||||
|
reverse('api_items'), {'content': 'API note #help'},
|
||||||
|
HTTP_X_API_KEY=self.api_key.token,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 201)
|
||||||
|
item = Item.objects.get(content='API note #help')
|
||||||
|
self.assertEqual(item.kind, Item.Kind.NOTE)
|
||||||
|
|
||||||
|
def test_api_create_still_accepts_explicit_kind(self):
|
||||||
|
UserPreference.objects.create(user=self.user, default_item_kind=Item.Kind.NOTE)
|
||||||
|
|
||||||
|
response = self.client.post(
|
||||||
|
reverse('api_items'), {'content': 'API task #help', 'kind': Item.Kind.TODO},
|
||||||
|
HTTP_X_API_KEY=self.api_key.token,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 201)
|
||||||
|
item = Item.objects.get(content='API task #help')
|
||||||
|
self.assertEqual(item.kind, Item.Kind.TODO)
|
||||||
|
|
||||||
|
|
||||||
class CopyButtonTests(TestCase):
|
class CopyButtonTests(TestCase):
|
||||||
def test_item_has_copy_button_with_original_text(self):
|
def test_item_has_copy_button_with_original_text(self):
|
||||||
|
|||||||
+1
-2
@@ -1556,8 +1556,7 @@ def api_items(request):
|
|||||||
data = json.loads(request.body or '{}') if request.content_type == 'application/json' else request.POST
|
data = json.loads(request.body or '{}') if request.content_type == 'application/json' else request.POST
|
||||||
raw = data.get('content', '')
|
raw = data.get('content', '')
|
||||||
raw, command_due_at, _ = parse_due_command(raw)
|
raw, command_due_at, _ = parse_due_command(raw)
|
||||||
prefs, created = UserPreference.objects.get_or_create(user=user)
|
kind, visibility, content, url = parse_quick_content(raw, Item.Kind.NOTE)
|
||||||
kind, visibility, content, url = parse_quick_content(raw, prefs.default_item_kind)
|
|
||||||
due_at = data['due_at'] if 'due_at' in data else command_due_at
|
due_at = data['due_at'] if 'due_at' in data else command_due_at
|
||||||
item = Item.objects.create(workspace=current_workspace(user, request.api_key), owner=user, kind=data.get('kind') or kind, visibility=data.get('visibility') or visibility, content=content, url=data.get('url') or url, due_at=due_at)
|
item = Item.objects.create(workspace=current_workspace(user, request.api_key), owner=user, kind=data.get('kind') or kind, visibility=data.get('visibility') or visibility, content=content, url=data.get('url') or url, due_at=due_at)
|
||||||
item.sync_metadata()
|
item.sync_metadata()
|
||||||
|
|||||||
Reference in New Issue
Block a user