Skip to content

Commit

Permalink
Merge branch 'release/3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
JackMorganNZ committed Jun 12, 2020
2 parents 807eefd + ad0cdf4 commit 4226d7f
Show file tree
Hide file tree
Showing 78 changed files with 3,310 additions and 111 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,6 @@ pip-selfcheck.json

### Project template
codewof/media/

### Tem files
codewof/temp/
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## 3.0.0

Add style checker for beginners.

- Style checker for beginners is a freely accessible style checker.
- Currently only Python 3 is supported.
- Code is anonymously stored on the website for analysis and then instantly deleted.
- Count of style issues triggered by submitted code are stored, but the code itself is not permanently stored.
- Statistics of style issue occurence counts are publically visible.
- Dependency updates:
- Add django-bootstrap-breadcrumbs 0.9.2.
- Set flake8 to custom version that allows isolated configurations, to be updated to official release in next update.
- Add flake8-docstrings 1.5.0.
- Add flake8-quotes 2.1.1.
- Add pep8-naming 0.9.1.

## 2.0.0

Adds gamification elements (points and achievements) to the website, including for all previous submissions for each user.
Expand Down
2 changes: 1 addition & 1 deletion codewof/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Configuration for Django system."""

__version__ = "2.0.0"
__version__ = "3.0.0"
__version_info__ = tuple(
[
int(num) if num.isdigit() else num
Expand Down
35 changes: 35 additions & 0 deletions codewof/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@
'ckeditor',
'ckeditor_uploader',
'captcha',
'django_bootstrap_breadcrumbs',
]
LOCAL_APPS = [
'general.apps.GeneralAppConfig',
'users.apps.UsersAppConfig',
'programming.apps.ProgrammingConfig',
'research.apps.ResearchConfig',
'style.apps.StyleAppConfig',
]
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
Expand Down Expand Up @@ -249,6 +251,7 @@
],
'libraries': {
'query_replace': 'config.templatetags.query_replace',
'simplify_error_template': 'config.templatetags.simplify_error_template',
},
},
},
Expand Down Expand Up @@ -382,6 +385,7 @@

# Other
# ------------------------------------------------------------------------------
BREADCRUMBS_TEMPLATE = "django_bootstrap_breadcrumbs/bootstrap4.html"
DEPLOYMENT_TYPE = env("DEPLOYMENT", default='local')
QUESTIONS_BASE_PATH = os.path.join(str(ROOT_DIR.path("programming")), "content")
CUSTOM_VERTO_TEMPLATES = os.path.join(str(ROOT_DIR.path("utils")), "custom_converter_templates", "")
Expand All @@ -390,6 +394,37 @@
SVG_DIRS = [
os.path.join(str(STATIC_ROOT), 'svg')
]
# Key 'example_code' uses underscore to be accessible in templates
STYLE_CHECKER_LANGUAGES = {
'python3': {
'name': 'Python 3',
'svg-icon': 'devicon-python.svg',
'checker-config': os.path.join(
str(ROOT_DIR),
'style',
'style_checkers',
'flake8.ini'
),
'example_code': """\"\"\"a simple fizzbuzz program.\"\"\"
def fizzbuzz():
for i in range(1 ,100):
if i % 3 == 0 and i % 5 == 0 :
print("FizzBuzz")
elif i%3 == 0:
print( "Fizz")
elif i % 5==0:
print("Buzz")
else:
print(i)
"""
},
}
# Add slug key to values for each language
for slug, data in STYLE_CHECKER_LANGUAGES.items():
data['slug'] = slug
STYLE_CHECKER_TEMP_FILES_ROOT = os.path.join(str(ROOT_DIR), 'temp', 'style')
STYLE_CHECKER_MAX_CHARACTER_COUNT = 10000

# reCAPTCHA
# ------------------------------------------------------------------------------
Expand Down
23 changes: 23 additions & 0 deletions codewof/config/templatetags/simplify_error_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Module for the custom simplify_error_template template tag."""

from django import template
from django.utils.safestring import mark_safe

register = template.Library()

SEARCH_TEXT = '{article} {character_description}'
REPLACE_TEXT = 'a {character}'


@register.simple_tag
def simplify_error_template(template):
"""Simplify template for rendering to user.
Args:
template (str): String of template.
Returns:
Updated string.
"""
new_text = template.replace(SEARCH_TEXT, REPLACE_TEXT)
return mark_safe(new_text)
1 change: 1 addition & 0 deletions codewof/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
path('', include('general.urls', namespace='general')),
path(settings.ADMIN_URL, admin.site.urls),
path('research/', include('research.urls', namespace='research')),
path('style/', include('style.urls', namespace='style')),
path('users/', include('users.urls', namespace='users'),),
path('accounts/', include('allauth.urls')),
path('', include('programming.urls', namespace='programming'),),
Expand Down
5 changes: 4 additions & 1 deletion codewof/general/management/commands/sampledata.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def handle(self, *args, **options):

management.call_command('load_user_types')
print(LOG_HEADER.format('Create sample users'))
User = get_user_model()
User = get_user_model() # noqa N806
# Create admin account
admin = User.objects.create_superuser(
'admin',
Expand Down Expand Up @@ -88,6 +88,9 @@ def handle(self, *args, **options):
management.call_command('load_achievements')
print('Achievements loaded.\n')

management.call_command('load_style_errors')
print('Style errors loaded.\n')

# Research
StudyFactory.create_batch(size=5)
StudyGroupFactory.create_batch(size=15)
Expand Down
1 change: 1 addition & 0 deletions codewof/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"bootstrap": "4.3.1",
"codemirror": "5.47.0",
"clipboard": "2.0.6",
"details-element-polyfill": "2.3.1",
"fuse.js": "3.4.4",
"jquery": "3.4.1",
Expand Down
6 changes: 3 additions & 3 deletions codewof/programming/codewof_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ def backdate_user(profile):
profile.save()


def backdate_points_and_achievements(n=-1, ignoreFlags=True):
def backdate_points_and_achievements(n=-1, ignore_flags=True):
"""Perform batch backdate of all points and achievements for n profiles in the system."""
backdate_achievements_times = []
backdate_points_times = []
time_before = time.perf_counter()
profiles = Profile.objects.all()
if not ignoreFlags:
if not ignore_flags:
profiles = profiles.filter(has_backdated=False)
if (n > 0):
profiles = profiles[:n]
Expand All @@ -252,7 +252,7 @@ def backdate_points_and_achievements(n=-1, ignoreFlags=True):
# The commented out part below seems to break travis somehow
print("Backdating user: {}/{}".format(str(i + 1), str(num_profiles))) # , end="\r")
profile = profiles[i]
if not profile.has_backdated or ignoreFlags:
if not profile.has_backdated or ignore_flags:
attempts = all_attempts.filter(profile=profile)

achievements_time_before = time.perf_counter()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def celsius_to_fahrenheit(temperature):
return (temperature * (9/5) + 32)
return (temperature * (9 / 5) + 32)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def fahrenheit_to_celsius(temperature):
return ((temperature - 32) * 5/9)
return ((temperature - 32) * 5 / 9)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
number = int(input("Enter a positive integer: "))
sum = 0
for i in range(1, number+1):
for i in range(1, number + 1):
if (i % 3 == 0) or (i % 5 == 0):
sum += i

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ def triangle(x):
if x <= 1:
print("That isn't a triangle!")
else:
for i in range(1, x+1):
for i in range(1, x + 1):
print(i * '*')
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def add_arguments(self, parser):
def handle(self, *args, **options):
"""Automatically called when the backdate command is given."""
print("Backdating points and achievements\n")
ignoreFlags = options['ignore_flags']
ignore_flags = options['ignore_flags']
number = int(options['profiles'])
if ignoreFlags and number > 0:
if ignore_flags and number > 0:
raise ValueError("If ignoring backdate flags you must backdate all profiles.")
backdate_points_and_achievements(number, ignoreFlags)
backdate_points_and_achievements(number, ignore_flags)
Loading

0 comments on commit 4226d7f

Please sign in to comment.