Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dummy database #5

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
*.sqlite3
data/
library/migrations/
*.hypothesis*
*__pycache__*
Binary file added WheresMyField/.DS_Store
Binary file not shown.
Empty file added WheresMyField/__init__.py
Empty file.
Binary file added WheresMyField/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added WheresMyField/__pycache__/settings.cpython-35.pyc
Binary file not shown.
Binary file added WheresMyField/__pycache__/urls.cpython-35.pyc
Binary file not shown.
Binary file added WheresMyField/__pycache__/wsgi.cpython-35.pyc
Binary file not shown.
128 changes: 128 additions & 0 deletions WheresMyField/settings.py
Original file line number Diff line number Diff line change
@@ -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/'

18 changes: 18 additions & 0 deletions WheresMyField/urls.py
Original file line number Diff line number Diff line change
@@ -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'))
]
16 changes: 16 additions & 0 deletions WheresMyField/wsgi.py
Original file line number Diff line number Diff line change
@@ -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()
Binary file added db.sqlite3
Binary file not shown.
Binary file added library/.DS_Store
Binary file not shown.
Empty file added library/__init__.py
Empty file.
Binary file added library/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added library/__pycache__/admin.cpython-35.pyc
Binary file not shown.
Binary file added library/__pycache__/apps.cpython-35.pyc
Binary file not shown.
Binary file added library/__pycache__/models.cpython-35.pyc
Binary file not shown.
Binary file added library/__pycache__/serializers.cpython-35.pyc
Binary file not shown.
Binary file added library/__pycache__/views.cpython-35.pyc
Binary file not shown.
26 changes: 26 additions & 0 deletions library/admin.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions library/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class LibraryConfig(AppConfig):
name = 'library'
156 changes: 156 additions & 0 deletions library/models.py
Original file line number Diff line number Diff line change
@@ -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)

Loading