Skip to content

Commit

Permalink
#476 fix line length issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlittle committed Nov 21, 2019
1 parent 185dda2 commit 538ec80
Show file tree
Hide file tree
Showing 19 changed files with 256 additions and 132 deletions.
19 changes: 15 additions & 4 deletions activitylog/migrations/0001_initial.py
Expand Up @@ -20,11 +20,22 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='UploadedActivityLog',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name=b'date created')),
('lastupdated_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name=b'date updated')),
('id', models.AutoField(auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID')),
('created_date',
models.DateTimeField(default=django.utils.timezone.now,
verbose_name=b'date created')),
('lastupdated_date',
models.DateTimeField(default=django.utils.timezone.now,
verbose_name=b'date updated')),
('file', models.FileField(upload_to=b'activitylog/%Y/%m/')),
('create_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='activitylog_create_user', to=settings.AUTH_USER_MODEL)),
('create_user',
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='activitylog_create_user',
to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Uploaded Activity Log',
Expand Down
13 changes: 8 additions & 5 deletions activitylog/views.py
Expand Up @@ -36,7 +36,7 @@ def process_uploaded_trackers(request, trackers, user, user_api_key):
u"Already uploaded: tracker activity %(uuid)s for \
%(username)s added" % {'username': user.username,
'uuid': tracker.get('digest')}),
'danger')
'danger')


def process_uploaded_quizresponses(request,
Expand Down Expand Up @@ -94,7 +94,8 @@ def process_uploaded_file(request, json_data):
req_user = User.objects.filter(username=username).first()

try:
user_api_key, created = ApiKey.objects.get_or_create(user=req_user)
user_api_key, created = ApiKey.objects \
.get_or_create(user=req_user)
if (created):
messages.warning(request, _(
u"Generated new ApiKey for %(username)s : %(apikey)s" % {
Expand Down Expand Up @@ -169,16 +170,18 @@ def upload_view(request):
activity_log_file = request.FILES["activity_log_file"]

# save activity_log_file
uploaded_activity_log = UploadedActivityLog(create_user=request.user,
file=activity_log_file)
uploaded_activity_log = \
UploadedActivityLog(create_user=request.user,
file=activity_log_file)
uploaded_activity_log.save()

# open file and process
with open(uploaded_activity_log.file.path, 'rb') as file:
file_data = file.read()
success = process_activitylog(request, file_data)
if success:
return HttpResponseRedirect(reverse('oppia_activitylog_upload_success'))
return HttpResponseRedirect(
reverse('oppia_activitylog_upload_success'))
else:
form = UploadActivityLogForm()
return render(request, 'activitylog/upload.html',
Expand Down
5 changes: 3 additions & 2 deletions av/forms.py
Expand Up @@ -53,8 +53,9 @@ def clean(self):
and media_file.content_type not in settings.OPPIA_MEDIA_FILE_TYPES:
raise forms.ValidationError(_(u"You may only upload a media file \
which is one of the following types: \
%s"
% ', '.join(settings.OPPIA_MEDIA_FILE_TYPES)))
%s"
% ', '
.join(settings.OPPIA_MEDIA_FILE_TYPES)))

'''
check this file hasn't already been uploaded
Expand Down
8 changes: 4 additions & 4 deletions av/management/commands/generate_media_images.py
Expand Up @@ -41,10 +41,10 @@ def handle(self, *args, **options):
self.stdout.write(" > Generating miniatures... \r", )
image_generator_command = ("%s %s" % (settings.SCREENSHOT_GENERATOR_PROGRAM,
settings.SCREENSHOT_GENERATOR_PROGRAM_PARAMS)) \
% (m.file.path,
content.SCREENSHOT_IMAGE_WIDTH,
content.SCREENSHOT_IMAGE_HEIGHT,
cache_dir)
% (m.file.path,
content.SCREENSHOT_IMAGE_WIDTH,
content.SCREENSHOT_IMAGE_HEIGHT,
cache_dir)
ffmpeg = subprocess.Popen(image_generator_command,
shell=True,
stdout=subprocess.PIPE,
Expand Down
6 changes: 3 additions & 3 deletions av/migrations/0001_initial.py
Expand Up @@ -22,11 +22,11 @@ class Migration(migrations.Migration):
primary_key=True)),
('course_shortname', models.CharField(max_length=100)),
('created_date',
models.DateTimeField(default=django.utils.timezone.now,
verbose_name=b'date created')),
models.DateTimeField(default=django.utils.timezone.now,
verbose_name=b'date created')),
('lastupdated_date',
models.DateTimeField(default=django.utils.timezone.now,
verbose_name=b'date updated')),
verbose_name=b'date updated')),
('file', models.FileField(upload_to=b'uploaded')),
('image', models.FileField(default=None,
upload_to=b'uploaded',
Expand Down
8 changes: 4 additions & 4 deletions gamification/views.py
Expand Up @@ -193,13 +193,13 @@ def edit_course_gamification(request, course_id):

default_points = {
'course': DefaultGamificationEvent.objects
.exclude(level=DefaultGamificationEvent.GLOBAL),
.exclude(level=DefaultGamificationEvent.GLOBAL),
'activity': DefaultGamificationEvent.objects
.filter(level=DefaultGamificationEvent.ACTIVITY),
.filter(level=DefaultGamificationEvent.ACTIVITY),
'quiz': DefaultGamificationEvent.objects
.filter(level=DefaultGamificationEvent.QUIZ),
.filter(level=DefaultGamificationEvent.QUIZ),
'media': DefaultGamificationEvent.objects
.filter(level=DefaultGamificationEvent.MEDIA)
.filter(level=DefaultGamificationEvent.MEDIA)
}

course_events = CourseGamificationEvent.objects.filter(course=course)
Expand Down
23 changes: 16 additions & 7 deletions helpers/templatetags/query_string.py
Expand Up @@ -14,16 +14,23 @@ def query_string(parser, token):
If a given value is a context variable it will resolve it.
Usage:
http://www.url.com/{% query_string "param_to_add=value, param_to_add=value"
"param_to_remove, params_to_remove" %}
http://www.url.com/{% query_string "param_to_add=value,
param_to_add=value"
"param_to_remove,
params_to_remove" %}
"""

try:
tag_name, add_string, remove_string = token.split_contents()
except ValueError:
raise(template.TemplateSyntaxError, "%r tag requires two arguments" % token.contents.split()[0])
if not (add_string[0] == add_string[-1] and add_string[0] in ('"', "'")) or not (remove_string[0] == remove_string[-1] and remove_string[0] in ('"', "'")):
raise(template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name)
raise(template.TemplateSyntaxError,
"%r tag requires two arguments" % token.contents.split()[0])
if not (add_string[0] == add_string[-1]
and add_string[0] in ('"', "'")) \
or not (remove_string[0] == remove_string[-1]
and remove_string[0] in ('"', "'")):
raise(template.TemplateSyntaxError,
"%r tag's argument should be in quotes" % tag_name)

add = string_to_dict(add_string[1:-1])
remove = string_to_list(remove_string[1:-1])
Expand Down Expand Up @@ -63,8 +70,10 @@ def get_query_string(p, new_params, remove, context):
except:
p[k] = v

return mark_safe('?' + '&'.join([u'%s=%s' % (urllib.parse.quote_plus(str(k)),
urllib.parse.quote_plus(str(v))) for k, v in p.items()]))
return mark_safe('?' + '&'
.join([u'%s=%s' % (urllib.parse.quote_plus(str(k)),
urllib.parse.quote_plus(str(v)))
for k, v in p.items()]))


# Taken from lib/utils.py
Expand Down
6 changes: 5 additions & 1 deletion helpers/templatetags/settings_value.py
Expand Up @@ -3,7 +3,11 @@

register = template.Library()

ALLOWABLE_VALUES = ("OPPIA_ANDROID_PACKAGEID", "OPPIA_ANDROID_ON_GOOGLE_PLAY", "OPPIA_ANDROID_DEFAULT_PACKAGEID", "BASESITE_URL", "OPPIA_MAX_UPLOAD_SIZE")
ALLOWABLE_VALUES = ("OPPIA_ANDROID_PACKAGEID",
"OPPIA_ANDROID_ON_GOOGLE_PLAY",
"OPPIA_ANDROID_DEFAULT_PACKAGEID",
"BASESITE_URL",
"OPPIA_MAX_UPLOAD_SIZE")

# settings value (based on https://stackoverflow.com/a/21593607)
@register.simple_tag
Expand Down
39 changes: 25 additions & 14 deletions integrations/dhis/views.py
Expand Up @@ -27,19 +27,26 @@ def home(request):

@staff_member_required
def export_latest(request):
last_month = datetime.datetime.now() + dateutil.relativedelta.relativedelta(months=-1)
last_month = datetime.datetime.now() \
+ dateutil.relativedelta.relativedelta(months=-1)
data = create_csv(last_month.year, last_month.month)
response = HttpResponse(data.csv, content_type='application/text;charset=utf-8')
response['Content-Disposition'] = "attachment; filename=dhis-export-{year}-{month}.csv".format(year=last_month.year, month=last_month.month)
response = HttpResponse(data.csv,
content_type='application/text;charset=utf-8')
response['Content-Disposition'] = \
"attachment; filename=dhis-export-{year}-{month}.csv" \
.format(year=last_month.year, month=last_month.month)

return response


@staff_member_required
def export_month(request, year, month):
data = create_csv(year, month)
response = HttpResponse(data.csv, content_type='application/text;charset=utf-8')
response['Content-Disposition'] = "attachment; filename=dhis-export-{year}-{month}.csv".format(year=year, month=month)
response = HttpResponse(data.csv,
content_type='application/text;charset=utf-8')
response['Content-Disposition'] = \
"attachment; filename=dhis-export-{year}-{month}.csv" \
.format(year=year, month=month)

return response

Expand All @@ -56,17 +63,21 @@ def create_csv(year, month):
data = tablib.Dataset(*data, headers=headers)

# get all the usernames for users who've had trackers or quizzes submitted
users = Tracker.objects.filter(submitted_date__month=month,
submitted_date__year=year).values('user').distinct()
users = Tracker.objects \
.filter(submitted_date__month=month,
submitted_date__year=year).values('user').distinct()

for user in users:
activities_completed = Tracker.objects.filter(submitted_date__month=month,
submitted_date__year=year,
user__id=user['user'],
completed=True).count()
points_earned = Tracker.objects.filter(submitted_date__month=month,
submitted_date__year=year,
user__id=user['user']).aggregate(Sum('points'))['points__sum']
activities_completed = Tracker.objects \
.filter(submitted_date__month=month,
submitted_date__year=year,
user__id=user['user'],
completed=True).count()
points_earned = Tracker.objects \
.filter(submitted_date__month=month,
submitted_date__year=year,
user__id=user['user']) \
.aggregate(Sum('points'))['points__sum']
quizzes_passed = Tracker.objects.filter(submitted_date__month=month,
submitted_date__year=year,
user__id=user['user'],
Expand Down
31 changes: 14 additions & 17 deletions oppia/permissions.py
Expand Up @@ -67,24 +67,21 @@ def get_user(request, view_user_id):
return view_user, None
except User.DoesNotExist:
raise Http404()
else:
try:
view_user = User.objects.get(pk=view_user_id)
courses = Course.objects.filter(
coursecohort__cohort__participant__user=view_user,
coursecohort__cohort__participant__role=Participant.STUDENT) \
.filter(
coursecohort__cohort__participant__user=
request.user,
coursecohort__cohort__participant__role=
Participant.TEACHER) \
.count()
if courses > 0:
return view_user, None
else:
raise exceptions.PermissionDenied
except User.DoesNotExist:
try:
view_user = User.objects.get(pk=view_user_id)
courses = Course.objects.filter(
coursecohort__cohort__participant__user=view_user,
coursecohort__cohort__participant__role=Participant.STUDENT) \
.filter(
coursecohort__cohort__participant__user=request.user,
coursecohort__cohort__participant__role=Participant.TEACHER) \
.count()
if courses > 0:
return view_user, None
else:
raise exceptions.PermissionDenied
except User.DoesNotExist:
raise exceptions.PermissionDenied


def get_user_courses(request, view_user):
Expand Down
26 changes: 20 additions & 6 deletions profile/migrations/0001_initial.py
Expand Up @@ -20,13 +20,27 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='UserProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('about', models.TextField(blank=True, default=None, null=True)),
('id', models.AutoField(auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID')),
('about', models.TextField(blank=True,
default=None,
null=True)),
('can_upload', models.BooleanField(default=False)),
('job_title', models.TextField(blank=True, default=None, null=True)),
('organisation', models.TextField(blank=True, default=None, null=True)),
('phone_number', models.TextField(blank=True, default=None, null=True)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('job_title', models.TextField(blank=True,
default=None,
null=True)),
('organisation', models.TextField(blank=True,
default=None,
null=True)),
('phone_number', models.TextField(blank=True,
default=None,
null=True)),
('user',
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL)),
],
),
]
Expand Down

0 comments on commit 538ec80

Please sign in to comment.