Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
elserj committed Sep 30, 2021
0 parents commit 7aadb18
Show file tree
Hide file tree
Showing 168 changed files with 40,364 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# env file
.env

# media files
media/annotations/*
media/dbxrefs/*
media/genes/*
media/taxonomy/*

# build files
__pycache__
.idea
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.6

ENV PYTHONUNBUFFERED 1
ENV DJANGO_ENV local

COPY ./requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt

COPY . /app/
WORKDIR /app/

EXPOSE 8000
Empty file added accounts/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions accounts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions accounts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts'
97 changes: 97 additions & 0 deletions accounts/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm

# models import
from .models import User


# orcID validator function
def orcIDValidator(url):
# get the actual orcid part
orcid = url.split('/')[-1]
# remove and store the last digit as it is the checksum
digit = orcid[-1]
orcid = orcid[:-1]
# remove dashes
orcid = orcid.replace('-', '')
# calculate checksum
total = 0
for i in str(orcid):
total = (total + int(i)) * 2
remainder = total % 11
chksum = (12 - remainder) % 11
if chksum == 10:
chksum = "X"
if digit == str(chksum):
return orcid
else:
raise forms.ValidationError("This field is not a valid ORCID")

class UserRegistrationForm(UserCreationForm):
ROLE_CHOICES = (
("Requestor", "Requestor"),
("Contributor", "Contributor"),
("Curator", "Curator"),
("Moderator", "Moderator"),
("Superuser", "Superuser")
)
email = forms.EmailField(label='Email address:')
first_name = forms.CharField(label='First Name:')
last_name = forms.CharField(label='Last Name:')
affiliation = forms.CharField(label='Affiliation:')
orcid = forms.CharField(label='<a href="https://orcid.org">ORCID</a>', validators=[orcIDValidator],
help_text="Example: https://orcid.org/0000-0012-3456-7890")
role = forms.ChoiceField(choices=ROLE_CHOICES, label='Role')

autofocus = 'email'

def signup(self, request, user):
pass

# Make sure no usernames with just digits, will mess up the account info lookups
def clean_username(self):
username = self.cleaned_data['username']
if username.isdigit():
raise forms.ValidationError("Usernames must contain at least one letter")
return username

class Meta(UserCreationForm.Meta):
model = User
fields = ['username', 'password1', 'password2', 'email', 'first_name', 'last_name', 'affiliation', 'orcid', 'role']

def save(self, commit=True):
user = super().save(commit=False)
user.email = self.cleaned_data['email']
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.affiliation = self.cleaned_data['affiliation']
user.orcid = self.cleaned_data['orcid']
user.role = self.cleaned_data['role']
user.is_active = False
user.needs_approval = True
self.approve(user)
if commit:
user.save()
return user

def approve(self, user):
# TODO: send email notification

return True


class UserLoginForm(AuthenticationForm):
def __init__(self, *args, **kwargs):
super(UserLoginForm, self).__init__(*args, **kwargs)

username = forms.TextInput(attrs={'class': 'form-control', 'placeholder': ''})
password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': ''}))


class UserApprovalForm(forms.ModelForm):
needs_approval = forms.CheckboxInput(attrs={'class': 'form-control', 'name': 'approvalChkbox'})

class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'affiliation', 'orcid', 'role', 'needs_approval')

51 changes: 51 additions & 0 deletions accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Generated by Django 3.2.5 on 2021-07-22 22:05

import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('affiliation', models.CharField(max_length=255)),
('contact_email', models.EmailField(blank=True, max_length=254, verbose_name='Contact E-Mail')),
('has_temp_password', models.BooleanField(default=False)),
('is_requestor', models.BooleanField(default=False)),
('is_contributor', models.BooleanField(default=False)),
('is_curator', models.BooleanField(default=False)),
('is_moderator', models.BooleanField(default=False)),
('is_superuser', models.BooleanField(default=False)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
39 changes: 39 additions & 0 deletions accounts/migrations/0002_auto_20210726_2205.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 3.2.5 on 2021-07-26 22:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0001_initial'),
]

operations = [
migrations.RemoveField(
model_name='user',
name='is_contributor',
),
migrations.RemoveField(
model_name='user',
name='is_curator',
),
migrations.RemoveField(
model_name='user',
name='is_moderator',
),
migrations.RemoveField(
model_name='user',
name='is_requestor',
),
migrations.AddField(
model_name='user',
name='role',
field=models.CharField(choices=[(1, 'Requestor'), (2, 'Contributor'), (3, 'Curator'), (4, 'Moderator'), (5, 'Superuser')], default=1, max_length=12),
),
migrations.AlterField(
model_name='user',
name='is_superuser',
field=models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status'),
),
]
23 changes: 23 additions & 0 deletions accounts/migrations/0003_auto_20210727_2011.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.5 on 2021-07-27 20:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0002_auto_20210726_2205'),
]

operations = [
migrations.AddField(
model_name='user',
name='needs_approval',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='user',
name='role',
field=models.CharField(choices=[('Requestor', 'Requestor'), ('Contributor', 'Contributor'), ('Curator', 'Curator'), ('Moderator', 'Moderator'), ('Superuser', 'Superuser')], default='Requestor', max_length=12),
),
]
17 changes: 17 additions & 0 deletions accounts/migrations/0004_remove_user_contact_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.5 on 2021-07-30 21:27

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('accounts', '0003_auto_20210727_2011'),
]

operations = [
migrations.RemoveField(
model_name='user',
name='contact_email',
),
]
21 changes: 21 additions & 0 deletions accounts/migrations/0005_user_orcid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.5 on 2021-08-25 21:35

import accounts.models
import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0004_remove_user_contact_email'),
]

operations = [
migrations.AddField(
model_name='user',
name='orcid',
field=models.URLField(default='https://orcid.org/0000-0002-1825-0097', help_text='Example: 0000-0001-2345-6789', max_length=40, validators=[django.core.validators.URLValidator, accounts.models.orcIDValidator]),
preserve_default=False,
),
]
20 changes: 20 additions & 0 deletions accounts/migrations/0006_alter_user_orcid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.5 on 2021-08-25 21:52

import accounts.models
import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0005_user_orcid'),
]

operations = [
migrations.AlterField(
model_name='user',
name='orcid',
field=models.URLField(help_text='Example: https://orcid.org/0000-0001-2345-6789', max_length=40, validators=[django.core.validators.URLValidator, accounts.models.orcIDValidator]),
),
]
Empty file added accounts/migrations/__init__.py
Empty file.
54 changes: 54 additions & 0 deletions accounts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.core.exceptions import ValidationError

# import validators
from django.core.validators import URLValidator

# orcID validator function
def orcIDValidator(url):
# get the actual orcid part
orcid = url.split('/')[-1]
# remove and store the last digit as it is the checksum
digit = orcid[-1]
orcid = orcid[:-1]
# remove dashes
orcid = orcid.replace('-', '')
# calculate checksum
total = 0
for i in str(orcid):
total = (total + int(i)) * 2
remainder = total % 11
chksum = (12 - remainder) % 11
if chksum == 10:
chksum = "X"
if digit == str(chksum):
return orcid
else:
raise ValidationError("This field is not a valid ORCID")

# Create your models here.
class User(AbstractUser):
#user = models.OneToOneField(User, on_delete=models.PROTECT, related_name='userprofile')
affiliation = models.CharField(max_length=255)
orcid = models.URLField(max_length=40, validators=[URLValidator, orcIDValidator],
help_text="Example: https://orcid.org/0000-0001-2345-6789")
has_temp_password = models.BooleanField(default=False)

# Roles
ROLE_CHOICES = (
("Requestor", "Requestor"),
("Contributor", "Contributor"),
("Curator", "Curator"),
("Moderator", "Moderator"),
("Superuser", "Superuser")
)
role = models.CharField(
max_length=12,
choices=ROLE_CHOICES,
default="Requestor",
)

needs_approval = models.BooleanField(default=False)


Loading

0 comments on commit 7aadb18

Please sign in to comment.