diff --git a/build-and-run-labelbase.sh b/build-and-run-labelbase.sh index 08c8051..bfa4ec3 100755 --- a/build-and-run-labelbase.sh +++ b/build-and-run-labelbase.sh @@ -1,6 +1,8 @@ -#!/bin/sh +#!/bin/bash -# git pull origin ... +docker-compose down # make sure Labelbase is terminated. + +# Check env vars first if [[ -z "${MYSQL_ROOT_PASSWORD}" ]]; then echo "Error: MYSQL_ROOT_PASSWORD environment variable is not set" @@ -16,4 +18,33 @@ else export $MYSQL_PASSWORD fi -docker-compose up --build +# Check git next + +LAST_GIT_COMMIT_FILE=".last_git_commit" + +if [ -f "$LAST_GIT_COMMIT_FILE" ]; then + LAST_COMMIT=$(cat "$LAST_GIT_COMMIT_FILE") +else + LAST_COMMIT="" +fi + +git fetch origin master + +LATEST_COMMIT=$(git rev-parse origin/master) + + + + + +if [ "$LATEST_COMMIT" != "$LAST_COMMIT" ]; then + echo "New Labelbase updates found. Pulling latest changes from $LAST_COMMIT, then build and run." + git pull origin master --no-rebase + echo $LATEST_COMMIT > "$LAST_GIT_COMMIT_FILE" + DOCKER_COMPOSE_COMMAND="up --build -d" +else + echo "Running Labelbase $LAST_COMMIT." + DOCKER_COMPOSE_COMMAND="up -d" +fi + +docker-compose $DOCKER_COMPOSE_COMMAND +echo "Excecute 'docker-compose down' to terminate Labelbase." diff --git a/django/knowledge_base/views.py b/django/knowledge_base/views.py index 7ce24a3..261a7d1 100644 --- a/django/knowledge_base/views.py +++ b/django/knowledge_base/views.py @@ -6,6 +6,7 @@ from .models import Category, Article, ExportSnapshot from .forms import JSONUploadForm from django.utils.text import slugify + class ExportJSONView(View): def get(self, request): categories = Category.objects.all().exclude(exclude_from_export=True) @@ -13,7 +14,7 @@ class ExportJSONView(View): for category in categories: articles = list(category.article_set.all().exclude(exclude_from_export=True).values()) data[category.name] = articles - export_snapshot = ExportSnapshot.objects.create( + ExportSnapshot.objects.create( exported_data=data ) return JsonResponse(data) @@ -37,8 +38,7 @@ class ImportJSONView(View): category = Category.objects.get(slug=slugify(category_name)) except Category.DoesNotExist: category = Category.objects.create(name=category_name, - slug=slugify(category_name)) - + slug=slugify(category_name)) for article_data in articles: try: article = Article.objects.get(slug=article_data['slug']) @@ -48,9 +48,9 @@ class ImportJSONView(View): article.save() except Article.DoesNotExist: Article.objects.create(title=article_data['title'], - content=article_data['content'], - category=category, - slug=article_data['slug']) + content=article_data['content'], + category=category, + slug=article_data['slug']) return JsonResponse({'message': 'Import successful'}) except json.JSONDecodeError: return JsonResponse({'error': 'Invalid JSON format'}, status=400) @@ -63,12 +63,14 @@ class IndexView(ListView): template_name = 'knowledge_base/index.html' context_object_name = 'categories' + class CategoryDetailView(DetailView): model = Category template_name = 'knowledge_base/category_detail.html' context_object_name = 'category' slug_url_kwarg = 'slug' + class ArticleDetailView(DetailView): model = Article template_name = 'knowledge_base/article_detail.html' diff --git a/django/labelbase/models.py b/django/labelbase/models.py index 667d68f..22433c1 100644 --- a/django/labelbase/models.py +++ b/django/labelbase/models.py @@ -71,7 +71,8 @@ class Labelbase(models.Model): max_length=10, choices=OPERATION_MODE_CHOICES, default='duplicate', - help_text="Choose the operation mode for handling entries with the same 'type' and 'ref'. The default mode is to create duplicate entries." + help_text=("Choose the operation mode for handling entries with the same" + "'type' and 'ref'. The default mode is to create duplicate entries.") ) MAINNET = 'mainnet' @@ -111,6 +112,7 @@ class Labelbase(models.Model): def get_hashtags_url(self): return reverse('labelbase_hashtags', kwargs={'labelbase_id': self.id}) + class Label(models.Model): """ Reference: diff --git a/django/labellabor/urls.py b/django/labellabor/urls.py index 7e409e5..04f8b05 100644 --- a/django/labellabor/urls.py +++ b/django/labellabor/urls.py @@ -38,7 +38,7 @@ from .views import ( TreeMapsView, FixAndMergeLabelsView, LabelbaseDatatableView, - LabelbasePortfolioView, + #LabelbasePortfolioView, OutputStatUpdateRedirectView, ) diff --git a/django/templates/about.html b/django/templates/about.html index 67e076f..274d9ff 100644 --- a/django/templates/about.html +++ b/django/templates/about.html @@ -10,4 +10,21 @@ :) + +{% comment %} + +