Skip to content

Commit

Permalink
Merge pull request #24 from LangCorrect/04-migrate-corrections
Browse files Browse the repository at this point in the history
04 migrate corrections
  • Loading branch information
danielzeljko committed Jul 22, 2023
2 parents e057b05 + a3c3af1 commit 00f4319
Show file tree
Hide file tree
Showing 15 changed files with 575 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DATABASE_URL=postgres:///langcorrect
CELERY_BROKER_URL=redis://127.0.0.1:6379
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ Master grammar, spelling, and syntax in the language(s) you’re learning throug
[![Built with Cookiecutter Django](https://img.shields.io/badge/built%20with-Cookiecutter%20Django-ff69b4.svg?logo=cookiecutter)](https://github.com/cookiecutter/cookiecutter-django/)
[![Black code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)

## Installation

### Create the environment

- To create a new virtual environment, run the following command:

$ python -m venv venv

- Install the project dependencies by running the following command:

$ pip install -r requirements/local.txt

- Create the database:

createdb --username=postgres langcorrect

- Set up your environment variables in .env (check .env example)

### Install the fixtures

- To install the supported languages, run the following command:

python manage.py loaddata fixtures/languages.json

- To install the correction types, run the following command:

python manage.py loaddata fixtures/correction_types.json

## Settings

Moved to [settings](http://cookiecutter-django.readthedocs.io/en/latest/settings.html).
Expand Down
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"langcorrect.challenges",
"langcorrect.prompts",
"langcorrect.posts",
"langcorrect.corrections",
]
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
Expand Down
112 changes: 112 additions & 0 deletions fixtures/correction_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
[
{
"model": "corrections.correctiontype",
"pk": 1,
"fields": {
"created": "2023-07-12T01:02:18.866Z",
"modified": "2023-07-12T01:02:18.866Z",
"is_removed": false,
"name": "Formatting and Citations",
"description": "This correction type deals with issues related to the proper formatting of the document, including indentation, spacing, font styles, and citation styles. It aims to ensure adherence to standard writing conventions, citation guidelines, and any specific formatting requirements."
}
},
{
"model": "corrections.correctiontype",
"pk": 2,
"fields": {
"created": "2023-07-12T01:03:20.975Z",
"modified": "2023-07-12T01:03:20.975Z",
"is_removed": false,
"name": "Content and Development",
"description": "This correction type involves evaluating the substance and development of ideas in the writing. It focuses on the relevance, coherence, and depth of the content, ensuring that ideas are well-supported, logical, and effectively communicated to engage the reader and convey the intended message."
}
},
{
"model": "corrections.correctiontype",
"pk": 3,
"fields": {
"created": "2023-07-12T01:04:32.395Z",
"modified": "2023-07-12T01:04:32.395Z",
"is_removed": false,
"name": "Style and Tone",
"description": "This correction type focuses on refining the writing style, tone, and voice. It aims to create a consistent and appropriate tone throughout the writing, aligning it with the intended audience and purpose. This correction type may involve suggestions to enhance the writing's persuasiveness, formality, informality, or other stylistic aspects."
}
},
{
"model": "corrections.correctiontype",
"pk": 4,
"fields": {
"created": "2023-07-12T01:05:44.944Z",
"modified": "2023-07-12T01:05:44.944Z",
"is_removed": false,
"name": "Clarity and Coherence",
"description": "This correction type aims to improve the overall clarity, logical flow, and organization of ideas in writing. It involves identifying and rectifying issues related to unclear or ambiguous expressions, lack of logical connections between ideas, or inconsistencies in paragraph organization to enhance the reader's understanding."
}
},
{
"model": "corrections.correctiontype",
"pk": 5,
"fields": {
"created": "2023-07-12T01:06:46.076Z",
"modified": "2023-07-12T01:06:46.076Z",
"is_removed": false,
"name": "Sentence Structure",
"description": "This correction type focuses on analyzing and improving the structure of sentences. It involves addressing issues such as run-on sentences, sentence fragments, awkward phrasing, and inconsistencies in sentence construction to improve the overall flow and readability of the writing."
}
},
{
"model": "corrections.correctiontype",
"pk": 6,
"fields": {
"created": "2023-07-12T01:07:38.225Z",
"modified": "2023-07-12T01:07:38.225Z",
"is_removed": false,
"name": "Word Choice",
"description": "This correction type involves suggesting alternatives or improvements for specific words or phrases used in the writing. It aims to enhance precision, clarity, and vocabulary richness by recommending more appropriate or effective words that convey the intended meaning more accurately."
}
},
{
"model": "corrections.correctiontype",
"pk": 7,
"fields": {
"created": "2023-07-12T01:08:29.733Z",
"modified": "2023-07-12T01:08:29.733Z",
"is_removed": false,
"name": "Capitalization",
"description": "This correction type focuses on ensuring correct capitalization throughout the writing. It involves correcting errors related to the capitalization of proper nouns, sentence beginnings, titles, and other instances where capital letters should be more appropriately used."
}
},
{
"model": "corrections.correctiontype",
"pk": 8,
"fields": {
"created": "2023-07-12T01:09:31.829Z",
"modified": "2023-07-12T01:09:31.829Z",
"is_removed": false,
"name": "Punctuation",
"description": "This correction type entails reviewing and correcting errors related to the proper use of punctuation marks. It includes fixing issues with commas, periods, question marks, exclamation marks, quotation marks, colons, semicolons, and other punctuation symbols to enhance readability and convey meaning effectively."
}
},
{
"model": "corrections.correctiontype",
"pk": 9,
"fields": {
"created": "2023-07-12T01:10:24.955Z",
"modified": "2023-07-12T01:10:24.955Z",
"is_removed": false,
"name": "Grammar",
"description": "This correction type addresses errors in sentence structure and grammatical rules. It involves rectifying mistakes in verb tenses, subject-verb agreement, articles, pronouns, prepositions, and other grammatical elements to improve the overall accuracy and clarity of the writing."
}
},
{
"model": "corrections.correctiontype",
"pk": 10,
"fields": {
"created": "2023-07-12T01:11:06.092Z",
"modified": "2023-07-12T01:11:06.092Z",
"is_removed": false,
"name": "Spelling",
"description": "This correction type focuses on identifying and correcting errors related to incorrect spelling. This correction type involves fixing mistakes in the spelling of words, ensuring proper usage of homophones, and correcting any typos or misspelled words"
}
}
]
Empty file.
65 changes: 65 additions & 0 deletions langcorrect/corrections/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from django.contrib import admin

from langcorrect.corrections.models import CorrectedRow, CorrectionType, OverallFeedback, PerfectRow


@admin.register(CorrectionType)
class CorrectionTypeAdmin(admin.ModelAdmin):
list_display = ["name", "description"]


@admin.register(CorrectedRow)
class CorrectedRowAdmin(admin.ModelAdmin):
readonly_fields = ["post", "user", "post_row", "correction", "note", "correction_types"]
list_display = ["author", "corrector", "original_sentence", "correction", "note", "get_correction_types"]
search_fields = ["post__user__username"]

def author(self, obj):
if obj.post:
return obj.post.user
else:
return None

def corrector(self, obj):
return obj.user

def original_sentence(self, obj):
return obj.post_row.sentence

def get_correction_types(self, obj):
return [t.name for t in obj.correction_types.all()]


@admin.register(PerfectRow)
class PerfectRowAdmin(admin.ModelAdmin):
readonly_fields = ["post", "user", "post_row"]
list_display = ["author", "corrector", "original_sentence"]
search_fields = ["post__user__username"]

def author(self, obj):
if obj.post:
return obj.post.user
else:
return None

def corrector(self, obj):
return obj.user

def original_sentence(self, obj):
return obj.post_row.sentence


@admin.register(OverallFeedback)
class OverallFeedbackAdmin(admin.ModelAdmin):
readonly_fields = ["post", "user", "comment"]
list_display = ["receiver", "corrector", "comment", "is_draft"]
search_fields = ["post__user__username"]

def receiver(self, obj):
if obj.post:
return obj.post.user
else:
return None

def corrector(self, obj):
return obj.user
8 changes: 8 additions & 0 deletions langcorrect/corrections/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _


class CorrectionsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "langcorrect.corrections"
verbose_name = _("Corrections")
77 changes: 77 additions & 0 deletions langcorrect/corrections/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Generated by Django 4.2.3 on 2023-07-21 07:53

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import model_utils.fields


class Migration(migrations.Migration):
initial = True

dependencies = [
("posts", "0002_postrow"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="CorrectionType",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
(
"created",
model_utils.fields.AutoCreatedField(
default=django.utils.timezone.now, editable=False, verbose_name="created"
),
),
(
"modified",
model_utils.fields.AutoLastModifiedField(
default=django.utils.timezone.now, editable=False, verbose_name="modified"
),
),
("is_removed", models.BooleanField(default=False)),
("name", models.CharField(max_length=100, unique=True)),
("description", models.TextField()),
],
options={
"verbose_name": "Correction Type",
"verbose_name_plural": "Correction Types",
},
),
migrations.CreateModel(
name="CorrectedRow",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
(
"created",
model_utils.fields.AutoCreatedField(
default=django.utils.timezone.now, editable=False, verbose_name="created"
),
),
(
"modified",
model_utils.fields.AutoLastModifiedField(
default=django.utils.timezone.now, editable=False, verbose_name="modified"
),
),
("is_removed", models.BooleanField(default=False)),
("correction", models.TextField()),
("note", models.TextField(blank=True, default=None, null=True)),
("correction_types", models.ManyToManyField(to="corrections.correctiontype")),
(
"post",
models.ForeignKey(
blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="posts.post"
),
),
("post_row", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="posts.postrow")),
("user", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
"abstract": False,
},
),
]
48 changes: 48 additions & 0 deletions langcorrect/corrections/migrations/0002_perfectrow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated by Django 4.2.3 on 2023-07-22 00:51

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import model_utils.fields


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("posts", "0002_postrow"),
("corrections", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="PerfectRow",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
(
"created",
model_utils.fields.AutoCreatedField(
default=django.utils.timezone.now, editable=False, verbose_name="created"
),
),
(
"modified",
model_utils.fields.AutoLastModifiedField(
default=django.utils.timezone.now, editable=False, verbose_name="modified"
),
),
("is_removed", models.BooleanField(default=False)),
(
"post",
models.ForeignKey(
blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to="posts.post"
),
),
("post_row", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="posts.postrow")),
("user", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
"abstract": False,
},
),
]
Loading

0 comments on commit 00f4319

Please sign in to comment.