Repository: apluslms/a-plus

Issue:
Missing time on late submission deadline
Time is not shown on late submissions, only the date can be seen. Jaakko tasked me to create an issue for it.


Discussion:
![ongelma](https://user-images.githubusercontent.com/2327687/51984772-ccc1cc00-24a4-11e9-9faa-1ece76157504.png)

Datetime rendering in this message box
Looks like a very small task.
@alalav1 can work on this.
Time is missing in three locations: User results page, module pages  and exercises themselves.
In the results page and module pages:

The `late_time` values formatting changes in the `blocktrans` block in the html template. The formatting can be overridden: `deadline=current.late_time|date:"D Y m d, P"` https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date , but then we cannot use different formatting for finish and english.
One solution is that we get rid of the block trans and use normal trans block. Then the date couldn't be in the middle of the sentence. This is not a problem, since the two trans blocks gives some flexibility how we can arrange the texts. If we are ever planning to add more than just two languages, this kind of solutions would be trickier and more vulnerable. But as far as I know, that is not going to happen in some time.
In the exercises:

Date is formatted in the `once_has_access` function:
```
_("Deadline for the exercise has passed. Late submissions are allowed until {date} but points are only worth {percent:d}% of normal.").format(
                date=date_format(d),
                percent=self.course_module.get_late_submission_point_worth(),
            )
```
The default formatting consider the language and uses the correct format. However, only the date is shown, not the time. This can be fixed by using custom format. We can make separate formats for finish and english.
> In the results page and module pages:
> 
> The `late_time` values formatting changes in the `blocktrans` block in the html template. The formatting can be overridden: `deadline=current.late_time|date:"D Y m d, P"` https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date , but then we cannot use different formatting for finish and english.
> One solution is that we get rid of the block trans and use normal trans block. Then the date couldn't be in the middle of the sentence. This is not a problem, since the two trans blocks gives some flexibility how we can arrange the texts. If we are ever planning to add more than just two languages, this kind of solutions would be trickier and more vulnerable. But as far as I know, that is not going to happen in some time.

Using two trans blocks to add a date in the middle of the sentence sounds like a bad, hacky solution. Don't do that, please. There must be a way to format dates without using multiple trans blocks.

Resolving patch:
diff --git a/course/templatetags/course.py b/course/templatetags/course.py
--- a/course/templatetags/course.py
+++ b/course/templatetags/course.py
@@ -81,6 +81,13 @@ def exercises_open(entry, now):
     return entry['opening_time'] <= now <= entry['closing_time']
 
 
+@register.filter
+def exercises_submittable(entry, now):
+    if entry['late_allowed']:
+        return entry['opening_time'] <= now <= entry['late_time']
+    return entry['opening_time'] <= now <= entry['closing_time']
+
+
 @register.filter
 def has_opened(entry, now):
     return entry['opening_time'] <= now
diff --git a/exercise/exercise_models.py b/exercise/exercise_models.py
--- a/exercise/exercise_models.py
+++ b/exercise/exercise_models.py
@@ -443,29 +443,31 @@ def one_has_access(self, students, when=None):
         in consideration.
         """
         timing,d = self.get_timing(students, when or timezone.now())
+
+        formatted_time = date_format(timezone.localtime(d), "DATETIME_FORMAT")
         if timing == self.TIMING.OPEN:
             return True,[]
         if timing == self.TIMING.LATE:
             # xgettext:no-python-format
             return True,[_("Deadline for the exercise has passed. Late submissions are allowed until {date} but points are only worth {percent:d}% of normal.").format(
-                date=date_format(d),
+                date=formatted_time,
                 percent=self.course_module.get_late_submission_point_worth(),
             )]
         if timing == self.TIMING.UNOFFICIAL:
             return True,[_("Deadline for the exercise has passed ({date}). You may still submit to receive feedback, but your current grade will not change.").format(
-                date=date_format(d)
+                date=formatted_time,
             )]
         if timing == self.TIMING.CLOSED_BEFORE:
             return False,[_("The exercise opens {date} for submissions.").format(
-                date=date_format(d)
+                date=formatted_time,
             )]
         if timing == self.TIMING.CLOSED_AFTER:
             return False,[_("Deadline for the exercise has passed ({date}).").format(
-                date=date_format(d)
+                date=formatted_time,
             )]
         if timing == self.TIMING.ARCHIVED:
             return False,[_("This course has been archived ({date}).").format(
-                date=date_format(d)
+                date=formatted_time,
             )]
         return False,["ERROR"]
 


Test patch: