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

Web app #138

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,5 @@ dmypy.json
# Cython debug symbols
cython_debug/

.idea
.idea
interface/media/
Empty file.
16 changes: 16 additions & 0 deletions interface/CodArtInterface/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for CodArtInterface project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CodArtInterface.settings')

application = get_asgi_application()
154 changes: 154 additions & 0 deletions interface/CodArtInterface/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
"""
Django settings for CodArtInterface project.

Generated by 'django-admin startproject' using Django 3.2.2.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-#vv!m(u-k%(cihg8olsq%_rlu#(wamjvf17vcucj9*z3v5j5-j'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# Project's Apps
'index.apps.IndexConfig',
# Third Party Apps
'tinymce',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'CodArtInterface.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates']
,
'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',
'index.context_processors.refactoring_renderer'
],
},
},
]

WSGI_APPLICATION = 'CodArtInterface.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/3.2/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/3.2/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/3.2/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = [
BASE_DIR/'static',
]
STATIC_ROOT = '/var/www/'

MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR/'media'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# tinymce
# https://django-tinymce.readthedocs.io/en/latest/index.html
TINYMCE_JS_URL = 'https://cdn.tiny.cloud/1/8gmtybnbslqqckpvg78unqpkqnpanxi1onix7gdd8j4bo9md/tinymce/5/tinymce.min.js'
TINYMCE_DEFAULT_CONFIG = {
'plugins': [
'advlist anchor autolink codesample fullscreen help image imagetools',
' lists link media noneditable preview',
' searchreplace table template visualblocks wordcount'
],
'toolbar':
'insertfile undo redo | bold italic | forecolor backcolor | template codesample | alignleft aligncenter alignright alignjustify | bullist numlist | link image tinydrive',
'content_style': 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }'
}
# TINYMCE_SPELLCHECKER = True
# TINYMCE_COMPRESSOR = True
26 changes: 26 additions & 0 deletions interface/CodArtInterface/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""CodArtInterface URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('tinymce/', include('tinymce.urls')),
path('', include('index.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) \
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
16 changes: 16 additions & 0 deletions interface/CodArtInterface/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for CodArtInterface 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/3.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CodArtInterface.settings')

application = get_wsgi_application()
Empty file added interface/__init__.py
Empty file.
Empty file added interface/index/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions interface/index/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin

from index.models import Refactoring, Parameter


@admin.register(Refactoring, Parameter)
class ModelNameAdmin(admin.ModelAdmin):
list_display = ['name', ]
search_fields = ['name', ]
6 changes: 6 additions & 0 deletions interface/index/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class IndexConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'index'
7 changes: 7 additions & 0 deletions interface/index/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from index.models import Refactoring


def refactoring_renderer(request):
return {
'all_refactorings': Refactoring.objects.all()
}
26 changes: 26 additions & 0 deletions interface/index/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django import forms


def get_field_by_type(data_type):
if data_type == "str" or data_type == "list":
return forms.CharField
elif data_type == "int":
return forms.IntegerField
elif data_type == "float":
return forms.FloatField
elif data_type == "bool":
return forms.BooleanField


class DynamicForm(forms.Form):

project_file = forms.FileField(
help_text="Upload your project's zip file.",
widget=forms.FileInput(attrs={'accept': '.zip'})
)

def __init__(self, *args, **kwargs):
dynamic_fields = kwargs.pop('dynamic_fields')
super(DynamicForm, self).__init__(*args, **kwargs)
for obj in dynamic_fields:
self.fields[obj['name']] = get_field_by_type(obj['type'])(help_text=obj['hint'])
41 changes: 41 additions & 0 deletions interface/index/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 3.2.3 on 2021-05-28 05:27

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Parameter',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128)),
('description', models.TextField(blank=True, null=True)),
('data_type', models.CharField(choices=[('int', 'Integer'), ('float', 'Float'), ('str', 'String'), ('bool', 'Boolean'), ('list', 'List')], max_length=128)),
],
),
migrations.CreateModel(
name='Refactoring',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128)),
('map_string', models.CharField(max_length=256)),
('description', models.TextField(blank=True, null=True)),
('input_example', models.TextField(blank=True, null=True)),
('output_example', models.TextField(blank=True, null=True)),
('has_example', models.BooleanField(default=True)),
('has_description', models.BooleanField(default=True)),
('parameters', models.ManyToManyField(to='index.Parameter')),
],
options={
'ordering': ('name',),
'abstract': False,
},
),
]
31 changes: 31 additions & 0 deletions interface/index/migrations/0002_auto_20210528_0532.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 3.2.3 on 2021-05-28 05:32

from django.db import migrations, models


class Migration(migrations.Migration):

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

operations = [
migrations.RemoveField(
model_name='refactoring',
name='has_description',
),
migrations.RemoveField(
model_name='refactoring',
name='has_example',
),
migrations.AddField(
model_name='refactoring',
name='post_conditions',
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name='refactoring',
name='pre_conditions',
field=models.TextField(blank=True, null=True),
),
]
17 changes: 17 additions & 0 deletions interface/index/migrations/0003_alter_parameter_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.3 on 2021-05-30 20:04

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('index', '0002_auto_20210528_0532'),
]

operations = [
migrations.AlterModelOptions(
name='parameter',
options={'ordering': ('name',)},
),
]
Loading