diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0902ce --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.DS_Store +*.sqlite3 +data/ +library/migrations/ +*.hypothesis* +*__pycache__* diff --git a/WheresMyField/.DS_Store b/WheresMyField/.DS_Store new file mode 100644 index 0000000..d087523 Binary files /dev/null and b/WheresMyField/.DS_Store differ diff --git a/WheresMyField/__init__.py b/WheresMyField/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/WheresMyField/__pycache__/__init__.cpython-35.pyc b/WheresMyField/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000..08ead89 Binary files /dev/null and b/WheresMyField/__pycache__/__init__.cpython-35.pyc differ diff --git a/WheresMyField/__pycache__/settings.cpython-35.pyc b/WheresMyField/__pycache__/settings.cpython-35.pyc new file mode 100644 index 0000000..39bbcba Binary files /dev/null and b/WheresMyField/__pycache__/settings.cpython-35.pyc differ diff --git a/WheresMyField/__pycache__/urls.cpython-35.pyc b/WheresMyField/__pycache__/urls.cpython-35.pyc new file mode 100644 index 0000000..e5c8bef Binary files /dev/null and b/WheresMyField/__pycache__/urls.cpython-35.pyc differ diff --git a/WheresMyField/__pycache__/wsgi.cpython-35.pyc b/WheresMyField/__pycache__/wsgi.cpython-35.pyc new file mode 100644 index 0000000..9951bec Binary files /dev/null and b/WheresMyField/__pycache__/wsgi.cpython-35.pyc differ diff --git a/WheresMyField/settings.py b/WheresMyField/settings.py new file mode 100644 index 0000000..8be8746 --- /dev/null +++ b/WheresMyField/settings.py @@ -0,0 +1,128 @@ +""" +Django settings for WheresMyField project. + +Generated by 'django-admin startproject' using Django 1.9.9. + +For more information on this file, see +https://docs.djangoproject.com/en/1.9/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.9/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'sqo*d$_e9^l5ah%3p50tr#ui1k9-6&b=3ac7qze56^toty9yr1' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + 'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',), + 'PAGE_SIZE': 10 +} + +# Application definition + +INSTALLED_APPS = [ + 'rest_framework', + 'library.apps.LibraryConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'bootstrap3', +] + +MIDDLEWARE_CLASSES = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'WheresMyField.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'WheresMyField.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.9/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/1.9/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.9/howto/static-files/ + +STATIC_URL = '/static/' + diff --git a/WheresMyField/urls.py b/WheresMyField/urls.py new file mode 100644 index 0000000..d376cd7 --- /dev/null +++ b/WheresMyField/urls.py @@ -0,0 +1,18 @@ +from django.contrib import admin +from django.conf.urls import url, include +from rest_framework import routers +from library import views + +router = routers.DefaultRouter() +router.register(r'article', views.ArticleViewSet) +router.register(r'author', views.AuthorViewSet) +router.register(r'year', views.YearViewSet) +router.register(r'label', views.LabelViewSet) +router.register(r'keyword', views.KeyWordViewSet) +router.register(r'strategies', views.StrategiesViewSet) + +urlpatterns = [ + url(r'^index', views.viewDashboard), + url(r'^admin/', admin.site.urls), + url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) +] diff --git a/WheresMyField/wsgi.py b/WheresMyField/wsgi.py new file mode 100644 index 0000000..ca0b14f --- /dev/null +++ b/WheresMyField/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for WheresMyField project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "WheresMyField.settings") + +application = get_wsgi_application() diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..6f9fa63 Binary files /dev/null and b/db.sqlite3 differ diff --git a/library/.DS_Store b/library/.DS_Store new file mode 100644 index 0000000..61c080b Binary files /dev/null and b/library/.DS_Store differ diff --git a/library/__init__.py b/library/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/library/__pycache__/__init__.cpython-35.pyc b/library/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000..3a054b2 Binary files /dev/null and b/library/__pycache__/__init__.cpython-35.pyc differ diff --git a/library/__pycache__/admin.cpython-35.pyc b/library/__pycache__/admin.cpython-35.pyc new file mode 100644 index 0000000..b42192c Binary files /dev/null and b/library/__pycache__/admin.cpython-35.pyc differ diff --git a/library/__pycache__/apps.cpython-35.pyc b/library/__pycache__/apps.cpython-35.pyc new file mode 100644 index 0000000..d308203 Binary files /dev/null and b/library/__pycache__/apps.cpython-35.pyc differ diff --git a/library/__pycache__/models.cpython-35.pyc b/library/__pycache__/models.cpython-35.pyc new file mode 100644 index 0000000..74918a0 Binary files /dev/null and b/library/__pycache__/models.cpython-35.pyc differ diff --git a/library/__pycache__/serializers.cpython-35.pyc b/library/__pycache__/serializers.cpython-35.pyc new file mode 100644 index 0000000..dd828df Binary files /dev/null and b/library/__pycache__/serializers.cpython-35.pyc differ diff --git a/library/__pycache__/views.cpython-35.pyc b/library/__pycache__/views.cpython-35.pyc new file mode 100644 index 0000000..f79cb57 Binary files /dev/null and b/library/__pycache__/views.cpython-35.pyc differ diff --git a/library/admin.py b/library/admin.py new file mode 100644 index 0000000..266cdcc --- /dev/null +++ b/library/admin.py @@ -0,0 +1,26 @@ +from django.contrib import admin + +from .models import Article, Author, Year, Label, Strategies, KeyWord + + +class ArticleAdmin(admin.ModelAdmin): + model = Article + search_fields = ['title', 'key'] + filter_horizontal = ('author', 'list_strategies', 'labels', 'key_word') + + +class AuthorAdmin(admin.ModelAdmin): + model = Author + search_fields = ['name'] + + +class StrategiesAdmin(admin.ModelAdmin): + model = Strategies + search_fields = ['strategy_name'] + +admin.site.register(Article, ArticleAdmin) +admin.site.register(Author, AuthorAdmin) +admin.site.register(Year) +admin.site.register(Label) +admin.site.register(KeyWord) +admin.site.register(Strategies, StrategiesAdmin) diff --git a/library/apps.py b/library/apps.py new file mode 100644 index 0000000..e01db0a --- /dev/null +++ b/library/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class LibraryConfig(AppConfig): + name = 'library' diff --git a/library/models.py b/library/models.py new file mode 100644 index 0000000..682bf1d --- /dev/null +++ b/library/models.py @@ -0,0 +1,156 @@ +from django.db import models +from django.core.validators import MaxValueValidator + + +class Author(models.Model): + """ + A module for representing an author + + Attributes: + ---------- + - name: Character Field + """ + name = models.CharField(max_length=200) + + class Meta: + ordering = ['name'] + + def __str__(self): + return self.name + + +class Year(models.Model): + """ + A module for representing the year of publication + + Attributes: + ---------- + - year: Positive Integer Field + + """ + year = models.PositiveIntegerField(validators=[MaxValueValidator(9999)]) + + class Meta: + ordering = ['year'] + + def __str__(self): + return "{}".format(self.year) + + +class Label(models.Model): + """ + A module for representing labels of the article. + + Labels are used mainly by me to categorize the papers + I have read. For example, Simple, Noisy, Spatial tournaments. + + Attributes: + ---------- + - label: Char Field + """ + label = models.CharField(max_length=100) + + class Meta: + ordering = ['label'] + + def __str__(self): + return self.label + + +class KeyWord(models.Model): + """ + A module for representing key words of the article. + + Key words of the article. + + Attributes: + ---------- + - key_word: Char Field + """ + key_word = models.CharField(max_length=100) + + class Meta: + ordering = ['key_word'] + + def __str__(self): + return self.key_word + + +class Strategies(models.Model): + """ + A module for representing the strategies used by the + author for his/her article research. + + Attributes: + ---------- + - strategy_name: Char Field + the name of a strategy + - description: Text Field + a simple description of the strategy + - implemented : Char Field + whether the strategy has been implemented in Axelrod python library or not + (this could possible change in the future and become Choice Field) + """ + strategy_name = models.CharField(max_length=300) + description = models.TextField(blank=True) + implemented = models.CharField(max_length=100, blank=True, null=True) + + class Meta: + ordering = ['strategy_name'] + + def __str__(self): + return self.strategy_name + + +class Article(models.Model): + """ + A module for representing an article + + Attributes: + ----------- + + - title: Text Field + the title of the article + - author: Many to Many Field + a list of authors of the article + - date: Foreign Key Field + the year of publication + - abstract: Text Field + the abstract of the article + - key: Char Field + a key for citation. Looks similar to the Mendeley key + - unique_key: Char Field + a unique key. Hash of ('Author', 'Title', 'Year', 'Abstract') + - labels: Many to Many Field + labels for the article + - pages: Integer Field + the pages the article is within the journal + - journal: Text Field + the journal the article was published + - notes: Text Field + personal notes for each article when I read it + - list_strategies: Many to Many Field + a list of strategies + - read: Boolean Field + true when I have read file, false otherwise + - key_word: Many to Many Field + a list of key words for the article + """ + title = models.TextField() + author = models.ManyToManyField(Author, blank=True) + date = models.ForeignKey(Year) + abstract = models.TextField(blank=True) + key = models.CharField(max_length=20) + unique_key = models.CharField(max_length=32, unique=True) + labels = models.ManyToManyField(Label, blank=True) + pages = models.CharField(max_length=10, blank=True) + journal = models.TextField(blank=True) + notes = models.TextField(blank=True) + list_strategies = models.ManyToManyField(Strategies, blank=True) + read = models.BooleanField(blank=True, default=False) + key_word = models.ManyToManyField(KeyWord, blank=True) + provenance = models.CharField(max_length=20, default='Manual') + + def __str__(self): + return "{} - {}".format(self.key, self.title) + diff --git a/library/serializers.py b/library/serializers.py new file mode 100644 index 0000000..f0be430 --- /dev/null +++ b/library/serializers.py @@ -0,0 +1,82 @@ +from library.models import Article, Author, Year, Label, Strategies, KeyWord +from rest_framework import serializers + + +class AuthorSerializer(serializers.HyperlinkedModelSerializer): + papers_on_this_db = serializers.SerializerMethodField() + + class Meta: + model = Author + fields = "__all__" + + def get_papers_on_this_db(self, obj): + return obj.article_set.count() + + +class YearSerializer(serializers.HyperlinkedModelSerializer): + papers_on_specific_year = serializers.SerializerMethodField() + + class Meta: + model = Year + fields = "__all__" + + def get_papers_on_specific_year(self, obj): + return obj.article_set.count() + + +class LabelsSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Label + fields = ["label"] + + +class KeyWordSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = KeyWord + fields = ["key_word"] + + +class StrategiesSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Strategies + fields = ["strategy_name"] + + +class ArticleSerializer(serializers.HyperlinkedModelSerializer): + author = AuthorSerializer(many=True, ) + date = YearSerializer() + labels = LabelsSerializer(many=True, ) + key_word = KeyWordSerializer(many=True, ) + list_strategies = StrategiesSerializer(many=True) + + class Meta: + model = Article + fields = ('key', 'unique_key', 'title', 'author', 'date', 'abstract', + 'pages', 'journal', 'labels', 'read', 'key_word', + 'provenance', 'list_strategies') + + def create(self, validated_data): + + # Create the new article attributes + date = Year.objects.create(year=validated_data['date'].get("year")) + # create the article + article = Article(date=date, title=validated_data['title'], + abstract=validated_data['abstract'], + key=validated_data['key'], + pages=validated_data['pages'], + journal=validated_data['journal'], + provenance=validated_data['provenance']) + + article.save() + + for author in validated_data['author']: + article.author.add(Author.objects.create(name=author['name'])) + for label in validated_data['labels']: + article.labels.add(Label.objects.create(label=label['label'])) + for strategy in validated_data['list_strategies']: + article.list_strategies.add(Strategies.objects.create( + strategy_name=strategy['strategy_name'])) + for keyword in validated_data['key_word']: + article.key_word.add(KeyWord.objects.create(key_word=keyword[ + 'key_word'])) + return article diff --git a/library/templates/library/base.html b/library/templates/library/base.html new file mode 100644 index 0000000..cf9cf47 --- /dev/null +++ b/library/templates/library/base.html @@ -0,0 +1,44 @@ +{% load bootstrap3 %} + +{% bootstrap_css %} +{% bootstrap_javascript %} + +{% bootstrap_messages %} + +Popular keywords:: + +