Complete open my2dos tasks
This commit is contained in:
+18
-7
@@ -40,12 +40,21 @@ def fetch_page_title(url):
|
||||
return ''
|
||||
|
||||
|
||||
def parse_quick_content(raw):
|
||||
def parse_quick_content(raw, default_kind=Item.Kind.NOTE):
|
||||
content = raw.strip()
|
||||
commands = {c.lower() for c in COMMAND_RE.findall(content)}
|
||||
content = COMMAND_RE.sub('', content).strip()
|
||||
only_url = bool(ONLY_URL_RE.match(content))
|
||||
kind = Item.Kind.TODO if 'todo' in commands else Item.Kind.JOURNAL if 'journal' in commands else Item.Kind.LINK if 'link' in commands or only_url else Item.Kind.NOTE
|
||||
if 'todo' in commands:
|
||||
kind = Item.Kind.TODO
|
||||
elif 'journal' in commands:
|
||||
kind = Item.Kind.JOURNAL
|
||||
elif 'link' in commands or only_url:
|
||||
kind = Item.Kind.LINK
|
||||
elif 'note' in commands:
|
||||
kind = Item.Kind.NOTE
|
||||
else:
|
||||
kind = default_kind if default_kind in Item.Kind.values else Item.Kind.NOTE
|
||||
visibility = Item.Visibility.PUBLIC if 'public' in commands else Item.Visibility.PRIVATE
|
||||
url_match = URL_RE.search(content)
|
||||
url = url_match.group(0) if kind == Item.Kind.LINK and url_match else ''
|
||||
@@ -153,11 +162,12 @@ def index(request):
|
||||
if request.method == 'POST':
|
||||
return redirect('login')
|
||||
return render(request, 'core/landing.html')
|
||||
prefs, created = UserPreference.objects.get_or_create(user=request.user)
|
||||
if request.method == 'POST':
|
||||
form = QuickItemForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
raw = form.cleaned_data['content']
|
||||
kind, visibility, content, url = parse_quick_content(raw)
|
||||
kind, visibility, content, url = parse_quick_content(raw, prefs.default_item_kind)
|
||||
active_tag = request.GET.get('tag')
|
||||
if active_tag and f'#{active_tag.lower()}' not in content.lower():
|
||||
content = f'{content} #{active_tag}'
|
||||
@@ -183,7 +193,6 @@ def index(request):
|
||||
query.pop('q', None)
|
||||
return redirect(f'{request.path}?{query.urlencode()}')
|
||||
items = visible_items(request.user)
|
||||
prefs, created = UserPreference.objects.get_or_create(user=request.user)
|
||||
applied_preferences = False
|
||||
if active_tags:
|
||||
if active_tag_mode == 'all':
|
||||
@@ -234,7 +243,8 @@ def index(request):
|
||||
|
||||
@login_required
|
||||
def new_item(request):
|
||||
requested_kind = request.GET.get('kind', '')
|
||||
prefs, created = UserPreference.objects.get_or_create(user=request.user)
|
||||
requested_kind = request.GET.get('kind') or prefs.default_item_kind
|
||||
next_url = request.GET.get('next') or request.POST.get('next') or reverse('index')
|
||||
if next_url == 'index':
|
||||
next_url = reverse('index')
|
||||
@@ -244,7 +254,7 @@ def new_item(request):
|
||||
raw = form.cleaned_data['content']
|
||||
if requested_kind in {'todo', 'link', 'journal'} and not re.search(r'/(todo|note|link|journal)\b', raw, re.I):
|
||||
raw = f'/{requested_kind} {raw}'
|
||||
kind, visibility, content, url = parse_quick_content(raw)
|
||||
kind, visibility, content, url = parse_quick_content(raw, prefs.default_item_kind)
|
||||
item = Item.objects.create(owner=request.user, kind=kind, visibility=visibility, content=content, url=url)
|
||||
attach_files_and_replace_tokens(item, request.FILES.getlist('files'))
|
||||
item.sync_metadata()
|
||||
@@ -646,7 +656,8 @@ def api_items(request):
|
||||
return JsonResponse({'items': [serialize_item(i) for i in visible_items(user, request.api_key)[:200]]})
|
||||
data = json.loads(request.body or '{}') if request.content_type == 'application/json' else request.POST
|
||||
raw = data.get('content', '')
|
||||
kind, visibility, content, url = parse_quick_content(raw)
|
||||
prefs, created = UserPreference.objects.get_or_create(user=user)
|
||||
kind, visibility, content, url = parse_quick_content(raw, prefs.default_item_kind)
|
||||
item = Item.objects.create(owner=user, kind=data.get('kind') or kind, visibility=data.get('visibility') or visibility, content=content, url=data.get('url') or url)
|
||||
item.sync_metadata()
|
||||
apply_team_from_tags(item, user, force_private=bool(re.search(r'/private\b', raw, re.I)))
|
||||
|
||||
Reference in New Issue
Block a user