Skip to content

Commit

Permalink
Merge pull request #36 from Elthan/feature-32
Browse files Browse the repository at this point in the history
Feature #32 & Bug #22
  • Loading branch information
torgeirl committed Jul 20, 2018
2 parents 7b905ee + 9d95c64 commit bc2bdad
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/develop/databasedumps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Users in the test database
After importing the test data, you will have some new users. Login to the Django admin UI (http://localhost:8000/admin/) with::

user: super@example.com
password: asdf
password: test

and select Users to list all users. The password of all other users are ``test``.

Expand Down
21 changes: 19 additions & 2 deletions trix/trix_admin/views/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django import forms
from django import http
from django.core.exceptions import ValidationError
from django.core import serializers
from django.shortcuts import get_object_or_404
from django.template import defaultfilters
from django.template.defaultfilters import truncatechars, urlencode
Expand All @@ -17,6 +18,7 @@
from cradmin_legacy import viewhelpers
from cradmin_legacy import crapp
from crispy_forms import layout
from crispy_forms.utils import flatatt
from cradmin_legacy.acemarkdown.widgets import AceMarkdownWidget

from trix.trix_core import models as trix_models
Expand Down Expand Up @@ -163,12 +165,13 @@ def get_field_layout(self):
return [
layout.Div('title', css_class="trix-focusfield"),
layout.Div('tags', css_class="trix-focusfield"),
layout.Div('hidden', css_class="trix-focusfield"),
layout.Div('text', css_class="trix-focusfield"),
layout.Div('solution', css_class="trix-focusfield"),
]

def get_form(self, *args, **kwargs):
form = super(AssignmentCreateUpdateMixin, self).get_form(*args, **kwargs)
def get_form(self, form_class=None):
form = super(AssignmentCreateUpdateMixin, self).get_form(form_class)
form.fields['tags'] = formfields.ManyToManyTagInputField(required=False)
form.fields['text'].widget = AceMarkdownWidget()
form.fields['solution'].widget = AceMarkdownWidget()
Expand All @@ -188,12 +191,26 @@ def form_saved(self, assignment):
if not assignment.tags.filter(tag=course.course_tag).exists():
assignment.tags.add(course.course_tag)

def get_buttons(self):
"""
Update the buttons to disable form validations since we use our own valdiation and text.
"""
buttons = super(AssignmentCreateUpdateMixin, self).get_buttons()
for button in buttons:
button.flat_attrs = flatatt({'formnovalidate': True}) + button.flat_attrs
return buttons

class AssignmentCreateView(AssignmentCreateUpdateMixin, create.CreateView):
"""
View used to create new assignments.
"""

def serialize_preview(self, form):
"""
Override this to use commit=True, this fixes previewing unsaved assignments.
"""
return serializers.serialize('json', [self.save_object(form, commit=True)])


class AssignmentUpdateView(AssignmentQuerysetForRoleMixin,
AssignmentCreateUpdateMixin,
Expand Down
26 changes: 15 additions & 11 deletions trix/trix_core/locale/nb/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ msgstr "Fjern administratortilgang til valgte brukere"
msgid "tag is in use"
msgstr "tag er i bruk"

#: trix/trix_core/admin.py:76
#: trix/trix_core/admin.py:76 trix/trix_core/models.py:266
msgid "Yes"
msgstr "Ja"

#: trix/trix_core/admin.py:77
#: trix/trix_core/admin.py:77 trix/trix_core/models.py:266
msgid "No"
msgstr "Nei"

Expand Down Expand Up @@ -79,7 +79,7 @@ msgid "No category"
msgstr "Ingen kategori"

#: trix/trix_core/models.py:149 trix/trix_core/models.py:213
#: trix/trix_core/models.py:321
#: trix/trix_core/models.py:326
msgid "Course"
msgstr "Kurs"

Expand All @@ -92,19 +92,19 @@ msgid "Tag"
msgstr "Tag"

#: trix/trix_core/models.py:156 trix/trix_core/models.py:251
#: trix/trix_core/models.py:325
#: trix/trix_core/models.py:330
msgid "Tags"
msgstr "Tags"

#: trix/trix_core/models.py:193 trix/trix_core/models.py:333
#: trix/trix_core/models.py:193 trix/trix_core/models.py:338
msgid "Description"
msgstr "Beskrivelse"

#: trix/trix_core/models.py:214
msgid "Courses"
msgstr "Kurs"

#: trix/trix_core/models.py:248 trix/trix_core/models.py:327
#: trix/trix_core/models.py:248 trix/trix_core/models.py:332
msgid "Title"
msgstr "Tittel"

Expand Down Expand Up @@ -137,26 +137,30 @@ msgid "Last changed"
msgstr "Sist modifisert"

#: trix/trix_core/models.py:270
msgid "Hide assignment from students"
msgstr "Skjul oppgaven for studenter"

#: trix/trix_core/models.py:275
msgid "Assignment"
msgstr "Oppgave"

#: trix/trix_core/models.py:271
#: trix/trix_core/models.py:276
msgid "Assignments"
msgstr "Oppgaver"

#: trix/trix_core/models.py:306
#: trix/trix_core/models.py:311
msgid "Solved by myself"
msgstr "Løste på egen hånd"

#: trix/trix_core/models.py:307
#: trix/trix_core/models.py:312
msgid "Solved with help"
msgstr "Løste med hjelp"

#: trix/trix_core/models.py:339
#: trix/trix_core/models.py:344
msgid "Permalink"
msgstr "Permalink"

#: trix/trix_core/models.py:340
#: trix/trix_core/models.py:345
msgid "Permalinks"
msgstr "Permalinker"

Expand Down
5 changes: 5 additions & 0 deletions trix/trix_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ class Assignment(models.Model):
lastupdate_datetime = models.DateTimeField(
verbose_name=_('Last changed'),
auto_now=True)
HIDDEN_CHOICES = [(True, _('Yes')), (False, _('No'))]
hidden = models.NullBooleanField(
choices=HIDDEN_CHOICES,
default=False,
verbose_name=_('Hide assignment from students'))

objects = AssignmentManager()

Expand Down
1 change: 1 addition & 0 deletions trix/trix_core/multiassignment_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def serialize(assignments):
('id', assignment.id),
('title', assignment.title),
('tags', [tag.tag for tag in assignment.tags.all()]),
('hidden', assignment.hidden),
('text', MarkdownString(assignment.text)),
])
if assignment.solution:
Expand Down
Binary file modified trix/trix_student/locale/nb/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion trix/trix_student/locale/nb/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ msgstr "Liste over permalinker"
msgid "All the permalinks created are listed below"
msgstr "Under listes alle permalinker opp"

#: trix/trix_student/views/common.py:109
#: trix/trix_student/views/common.py:115
msgid ""
"You have completed {{ solvedPercentage }} percent of assignments matching "
"the currently selected tags."
Expand Down
24 changes: 22 additions & 2 deletions trix/trix_student/static/trix_student/src/less/trix.less
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ body {
.cradmin-div-styled-as-textarea {
width: 60%;
border-right: 1px dashed #ccc;
padding: 40px 50px;
padding: 20px 50px 40px 50px;
float: left;
}

Expand All @@ -210,6 +210,10 @@ body {
margin: 7px 2px !important;
}

.btn-toolbar .btn-group .btn {
color: @navbar-inverse-bg;
}

/* Submit row */
.cradmin_legacy_submitrow {
width: auto;
Expand Down Expand Up @@ -259,11 +263,27 @@ body {
/**
* Preview page
**/
.cradmin-legacy-floating-fullsize-iframe-wrapper .cradmin-legacy-floating-fullsize-content

.cradmin-legacy-floating-fullsize-iframe-wrapper {
overflow: auto;
}

.cradmin-legacy-floating-fullsize-iframe-closebutton {
width: 20% !important;
float: right;
left: auto !important;
}

.cradmin-legacy-floating-fullsize-content {
width: 80% !important;
float: left;
}

.cradmin-legacy-floating-fullsize-iframe-inner iframe {
height: 100% !important;
}


/**
* Message container
**/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ <h3>{% trans "Print" %}:</h3>
<div class="col-sm-9 col-sm-pull-3 col-md-9 col-md-pull-3">
{% include "trix_student/include/pager.django.html" with pager_extraclass="pager-no-topmargin hidden-xs" %}
{% for assignment, howsolved in assignmentlist_with_howsolved %}
{% include "trix_student/include/assignment.django.html" %}
{% if assignment.hidden is False or assignment.hidden is None or user_is_admin %}
{% include "trix_student/include/assignment.django.html" %}
{% endif %}
{% endfor %}
{% include "trix_student/include/pager.django.html" %}
</div>
Expand Down
10 changes: 8 additions & 2 deletions trix/trix_student/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ def _get_user_is_admin(self):
raise NotImplementedError()

def _get_progress(self):
how_solved = models.HowSolved.objects.filter(assignment__in=self.get_queryset())\
"""
Gets the progress a user has made. Hidden tasks are not counted unless user is an admin.
"""
assignments = self.get_queryset()
if (not self.request.user.is_admin):
assignments = assignments.exclude(hidden=True)
how_solved = models.HowSolved.objects.filter(assignment__in=assignments)\
.filter(user=self.request.user.id)
num_solved = how_solved.count()
num_total = self.get_queryset().count()
num_total = assignments.count()
if num_total == 0:
percent = 0
else:
Expand Down
4 changes: 3 additions & 1 deletion trix/trix_student/views/howsolved.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class Meta:


class HowsolvedView(View):
"""docstring for UpdateHowSolvedView"""
"""
View of how the assignment was solved.
"""
http_method_names = ['post', 'delete']

def _bad_request_response(self, data):
Expand Down

0 comments on commit bc2bdad

Please sign in to comment.