Dependencies for other languages, scheduled tasks import, logs per type, home button filter urls
This commit is contained in:
@@ -28,7 +28,8 @@ def link_list(request):
|
||||
# Charts
|
||||
"http://localhost:8000/api/charts",
|
||||
# Logs
|
||||
"http://localhost:8000/api/logs",
|
||||
"http://localhost:8000/api/logs_debug",
|
||||
"http://localhost:8000/api/logs_info",
|
||||
"http://localhost:8000/api/logs_error",
|
||||
# API tasks
|
||||
] + [os.path.join(prefix, l) for l in links]
|
||||
@@ -263,8 +264,13 @@ def logs_error(request):
|
||||
file_content = f.read()
|
||||
return HttpResponse(file_content, content_type="text/plain")
|
||||
|
||||
def logs(request):
|
||||
with open(os.getenv("PATH_LOGS", "logs/log_app_fetcher.log"), "r") as f:
|
||||
def logs_info(request):
|
||||
with open(os.getenv("PATH_LOGS_INFO", "logs/log_app_fetcher_info.log"), "r") as f:
|
||||
file_content = f.read()
|
||||
return HttpResponse(file_content, content_type="text/plain")
|
||||
|
||||
def logs_debug(request):
|
||||
with open(os.getenv("PATH_LOGS_DEBUG", "logs/log_app_fetcher_debug.log"), "r") as f:
|
||||
file_content = f.read()
|
||||
return HttpResponse(file_content, content_type="text/plain")
|
||||
|
||||
@@ -278,29 +284,40 @@ def filtered_urls(request):
|
||||
statuses = Urls.STATUS_ENUM.choices
|
||||
searches = Search.objects.all()
|
||||
sources = Source.objects.all()
|
||||
|
||||
# Check if filters are applied; if not, select all by default
|
||||
selected_status = request.GET.getlist('status', [str(status[0]) for status in statuses])
|
||||
selected_search = request.GET.getlist('search', [str(search.id) for search in searches])
|
||||
selected_source = request.GET.getlist('source', [str(source.id) for source in sources])
|
||||
|
||||
# Get selected parameters
|
||||
selected_status = request.GET.getlist('status')
|
||||
selected_search = request.GET.getlist('search')
|
||||
selected_source = request.GET.getlist('source')
|
||||
selected_days = request.GET.get("days", 30)
|
||||
per_page = request.GET.get('per_page', 100) # Default is X URLs per page
|
||||
page_number = request.GET.get('page') # Get the current page number
|
||||
|
||||
# charts = request.GET.get('charts', False)
|
||||
|
||||
# "Home" -> No parameters -> Override filter with default values
|
||||
if ( len(request.GET.keys()) == 0 ):
|
||||
selected_status = [str(status[0]) for status in statuses]
|
||||
selected_search = [str(search.id) for search in searches]
|
||||
selected_source = [str(source.id) for source in sources]
|
||||
|
||||
# Filter URLs based on selected filters
|
||||
urls = Urls.objects.filter(
|
||||
Q(urlssourcesearch__id_source__in=selected_source) &
|
||||
Q(urlssourcesearch__id_search__in=selected_search) &
|
||||
Q(status__in=selected_status) &
|
||||
Q(ts_fetch__gte=now() - timedelta(days=float(selected_days)))
|
||||
).distinct() # .order_by('-ts_fetch')
|
||||
if ('' in selected_status) or ('' in selected_search) or ('' in selected_source):
|
||||
urls = []
|
||||
else:
|
||||
urls = Urls.objects.filter(
|
||||
Q(urlssourcesearch__id_source__in=selected_source) &
|
||||
Q(urlssourcesearch__id_search__in=selected_search) &
|
||||
Q(status__in=selected_status) &
|
||||
Q(ts_fetch__gte=now() - timedelta(days=float(selected_days)))
|
||||
).distinct() # .order_by('-ts_fetch')
|
||||
|
||||
# Custom replace search type
|
||||
for s in searches:
|
||||
s.type = s.type.replace("rss_feed", "rss").replace("url_host", "url").replace("keyword_search", "keyword")
|
||||
|
||||
# Pagination
|
||||
per_page = request.GET.get('per_page', 25) # Default is 50 URLs per page
|
||||
paginator = Paginator(urls, per_page) # Paginate the filtered URLs
|
||||
page_number = request.GET.get('page') # Get the current page number
|
||||
page_obj = paginator.get_page(page_number) # Get the current page object
|
||||
|
||||
# Map URL IDs to their sources & searches, only for subset of URLs (page of interest)
|
||||
@@ -323,6 +340,7 @@ def filtered_urls(request):
|
||||
"selected_days": selected_days,
|
||||
"sources_map": sources_map,
|
||||
"searches_map": searches_map,
|
||||
# "charts": charts,
|
||||
}
|
||||
|
||||
return render(request, 'filtered_urls.html', context)
|
||||
|
||||
Reference in New Issue
Block a user