Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

Commit

Permalink
PEP8.
Browse files Browse the repository at this point in the history
  • Loading branch information
moschlar committed Nov 16, 2013
1 parent cfa4887 commit b04e4b8
Show file tree
Hide file tree
Showing 33 changed files with 184 additions and 122 deletions.
44 changes: 24 additions & 20 deletions sauce/bin/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,32 @@
sys.exit(1)


d = csv.DictReader(open('DSEA Teilnehmer.csv'), ['id', 'matrnr', 'nachname', 'vorname', 'x1', 'x2', 'email', 'x3', 'x4', 'sem', 'stat'], delimiter=';')
d = csv.DictReader(open('DSEA Teilnehmer.csv'),
['id', 'matrnr', 'nachname', 'vorname', 'x1', 'x2', 'email', 'x3', 'x4', 'sem', 'stat'],
delimiter=';')

users_ = list(d)
users = dict()

for row in users_:
for k in row:
row[k] = row[k].decode('utf-8')
users[row['nachname'], row['vorname']] = row
pprint(row)
for k in row:
row[k] = row[k].decode('utf-8')
users[row['nachname'], row['vorname']] = row
pprint(row)

groups = dict()

f = open('dsea-Gruppen.txt')

i = 0
for line in f:
line = line.strip().decode('utf-8')
if line:
if line.startswith(u'GRUPPE'):
i += 1
else:
nachname, vorname = line.split(', ', 1)
groups[nachname, vorname] = i
line = line.strip().decode('utf-8')
if line:
if line.startswith(u'GRUPPE'):
i += 1
else:
nachname, vorname = line.split(', ', 1)
groups[nachname, vorname] = i
pprint(groups)

print "Inconsistencies: "
Expand All @@ -66,14 +68,16 @@
print "Only in users file: %s" % sorted(userset - groupset)
print "Only in groups file: %s" % sorted(groupset - userset)

d = csv.DictWriter(open('dsea_compiled.csv', 'w'), ['user_name', 'last_name', 'first_name', 'email_address', 'lesson_id'], delimiter=';')
d = csv.DictWriter(open('dsea_compiled.csv', 'w'),
['user_name', 'last_name', 'first_name', 'email_address', 'lesson_id'],
delimiter=';')
d.writeheader()

for n, v in userset & groupset:
d.writerow(dict(
user_name=users[n, v]['email'].split('@', 1)[0].encode('utf-8'),
last_name=users[n, v]['nachname'].encode('utf-8'),
first_name=users[n, v]['vorname'].encode('utf-8'),
email_address=users[n, v]['email'].encode('utf-8'),
lesson_id=groups[n, v]
))
d.writerow(dict(
user_name=users[n, v]['email'].split('@', 1)[0].encode('utf-8'),
last_name=users[n, v]['nachname'].encode('utf-8'),
first_name=users[n, v]['vorname'].encode('utf-8'),
email_address=users[n, v]['email'].encode('utf-8'),
lesson_id=groups[n, v]
))
9 changes: 5 additions & 4 deletions sauce/bin/fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import os
import sys
from getpass import getpass
from argparse import ArgumentParser
import traceback

Expand All @@ -37,15 +36,18 @@

import transaction


def load_config(filename):
conf = appconfig('config:' + os.path.abspath(filename))
load_environment(conf.global_conf, conf.local_conf)


def parse_args():
parser = ArgumentParser(description=__doc__)
parser.add_argument("conf_file", help="configuration to use")
return parser.parse_args()


def main():
args = parse_args()
load_config(args.conf_file)
Expand All @@ -54,7 +56,7 @@ def main():

events = Session.query(model.Event).all()

print [(i, e.name) for i,e in enumerate(events)]
print [(i, e.name) for i, e in enumerate(events)]

event_id = raw_input('event_id: ')
event = events[int(event_id)]
Expand All @@ -66,7 +68,7 @@ def main():

for a in Session.query(model.Assignment).filter_by(event_id=event.id).all():
a = Session.merge(a)
a.allowed_languages=l
a.allowed_languages = l
Session.add(a)

try:
Expand Down Expand Up @@ -94,7 +96,6 @@ def main():
transaction.abort()



if __name__ == '__main__':
print >>sys.stderr, 'Do not use this program unmodified.'
sys.exit(1)
Expand Down
14 changes: 10 additions & 4 deletions sauce/bin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@

import transaction


def load_config(filename):
conf = appconfig('config:' + os.path.abspath(filename))
load_environment(conf.global_conf, conf.local_conf)


def parse_args():
parser = ArgumentParser(description=__doc__)
parser.add_argument("conf_file", help="configuration to use")
return parser.parse_args()


def main():
args = parse_args()
load_config(args.conf_file)
Expand All @@ -54,7 +57,7 @@ def main():

events = Session.query(model.Event).all()

print [(i, e.name) for i,e in enumerate(events)]
print [(i, e.name) for i, e in enumerate(events)]

event_id = raw_input('event_id: ')
event = events[int(event_id)]
Expand All @@ -70,9 +73,12 @@ def main():
team.events.append(event)
Session.add(team)

student = model.Student(user_name=teamname, display_name=teamname,
email_address=teamname+'@students.uni-mainz.de',
password=password, teams=[team])
student = model.Student(
user_name=teamname, display_name=teamname,
email_address=teamname + '@students.uni-mainz.de',
password=password,
teams=[team],
)
Session.add(student)

try:
Expand Down
2 changes: 2 additions & 0 deletions sauce/config/app_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def __init__(self):
super(SauceAppConfig, self).__init__()

# Feature switches like http://code.flickr.net/2009/12/02/flipping-out/
# Please note that all of the features here are off by default for a reason:
# they are either highly specific to certain requirements or rarely tested
self.features = {
'externalauth': False,
'lti': False,
Expand Down
12 changes: 9 additions & 3 deletions sauce/controllers/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from sauce.model import Assignment, Submission, DBSession
from sauce.lib.menu import menu
from sauce.controllers.lessons import SubmissionsController
from sauce.widgets import SubmissionTable, SubmissionTableFiller
from sauce.widgets import SubmissionTable, SubmissionTableFiller

try:
from sauce.controllers.similarity import SimilarityController
Expand Down Expand Up @@ -87,7 +87,10 @@ def index(self, page=1, *args, **kwargs):
if request.user:
c.table = SubmissionTable(DBSession)

values = SubmissionTableFiller(DBSession).get_value(assignment_id=self.assignment.id, user_id=request.user.id)
values = SubmissionTableFiller(DBSession).get_value(
assignment_id=self.assignment.id,
user_id=request.user.id,
)

teams = set()
for lesson in self.assignment.sheet.event.lessons:
Expand All @@ -100,7 +103,10 @@ def index(self, page=1, *args, **kwargs):
teammates.discard(request.user)

for teammate in teammates:
values.extend(SubmissionTableFiller(DBSession).get_value(assignment_id=self.assignment.id, user_id=teammate.id))
values.extend(SubmissionTableFiller(DBSession).get_value(
assignment_id=self.assignment.id,
user_id=teammate.id,
))

return dict(page='assignments', event=self.event, assignment=self.assignment, values=values)

Expand Down
10 changes: 5 additions & 5 deletions sauce/controllers/crc/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class SheetsCrudController(FilterCrudRestController):
'__xml_fields__': ['assignments'],
'start_time': lambda filler, obj: h.strftime(obj.start_time, False),
'end_time': lambda filler, obj: h.strftime(obj.end_time, False),
'assignments': lambda filler, obj: \
', '.join(link_to(ass.name, '../assignments/%d/edit' % ass.id) \
'assignments': lambda filler, obj:
', '.join(link_to(ass.name, '../assignments/%d/edit' % ass.id)
for ass in obj.assignments),
'__base_widget_args__': {'sortList': [[1, 0]]},
}
Expand Down Expand Up @@ -111,10 +111,10 @@ class AssignmentsCrudController(FilterCrudRestController):
'__xml_fields__': ['sheet', 'allowed_languages'],
'start_time': lambda filler, obj: h.strftime(obj.start_time, False),
'end_time': lambda filler, obj: h.strftime(obj.end_time, False),
'sheet': lambda filler, obj: \
'sheet': lambda filler, obj:
link_to(obj.sheet.name, '../sheets/%d/edit' % obj.sheet.id),
'allowed_languages': lambda filler, obj: \
', '.join(link_to(l.name, '/languages/%d' % l.id) \
'allowed_languages': lambda filler, obj:
', '.join(link_to(l.name, '/languages/%d' % l.id)
for l in obj.allowed_languages),
'__base_widget_args__': {'sortList': [[1, 0], [3, 0]]},
}
Expand Down
25 changes: 13 additions & 12 deletions sauce/controllers/crc/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
import tw2.jqplugins.chosen.widgets as twjc
import sprox.widgets.tw2widgets.widgets as sw
from sauce.widgets.datagrid import JSSortableDataGrid
from sauce.widgets.widgets import LargeMixin, SmallMixin, Wysihtml5, MediumTextField, SmallTextField, CalendarDateTimePicker
from sauce.widgets.widgets import LargeMixin, SmallMixin, Wysihtml5, \
MediumTextField, SmallTextField, CalendarDateTimePicker

from sprox.sa.widgetselector import SAWidgetSelector
from sauce.controllers.crc.provider import FilterSAORMSelector
Expand Down Expand Up @@ -97,16 +98,16 @@ class MyWidgetSelector(SAWidgetSelector):

def __init__(self, *args, **kwargs):
self.default_widgets.update({
sqlat.String: MediumTextField,
sqlat.Integer: SmallTextField,
sqlat.Numeric: SmallTextField,
sqlat.DateTime: CalendarDateTimePicker,
sqlat.Date: twb.CalendarDatePicker,
sqlat.Time: twb.CalendarTimePicker,
sqlat.Binary: twb.FileField,
sqlat.BLOB: twb.FileField,
sqlat.String: MediumTextField,
sqlat.Integer: SmallTextField,
sqlat.Numeric: SmallTextField,
sqlat.DateTime: CalendarDateTimePicker,
sqlat.Date: twb.CalendarDatePicker,
sqlat.Time: twb.CalendarTimePicker,
sqlat.Binary: twb.FileField,
sqlat.BLOB: twb.FileField,
sqlat.PickleType: MediumTextField,
sqlat.Enum: twjc.ChosenSingleSelectField,
sqlat.Enum: twjc.ChosenSingleSelectField,
})
super(MyWidgetSelector, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -218,7 +219,7 @@ class MyTableFiller(TableFiller):
class EditForm(EditableForm):
__model__ = __entity__ = self.model
__provider_type_selector_type__ = FilterSAORMSelector
def _do_get_validator_args(self, field_name, field, validator_type):
def _do_get_validator_args(self, field_name, field, validator_type): # @IgnorePep8
args = super(EditForm, self)._do_get_validator_args(field_name, field, validator_type)
widget_type = self._do_get_field_wiget_type(field_name, field)
if widget_type and issubclass(widget_type, (twb.CalendarDatePicker, twb.CalendarDateTimePicker)):
Expand All @@ -239,7 +240,7 @@ class EditFiller(EditFormFiller):
class NewForm(AddRecordForm):
__model__ = __entity__ = self.model
__provider_type_selector_type__ = FilterSAORMSelector
def _do_get_validator_args(self, field_name, field, validator_type):
def _do_get_validator_args(self, field_name, field, validator_type): # @IgnorePep8
args = super(NewForm, self)._do_get_validator_args(field_name, field, validator_type)
widget_type = self._do_get_field_wiget_type(field_name, field)
if widget_type and issubclass(widget_type, (twb.CalendarDatePicker, twb.CalendarDateTimePicker)):
Expand Down
38 changes: 21 additions & 17 deletions sauce/controllers/crc/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ class EventsCrudController(FilterCrudRestController):
'teachers', 'tutors', '_members',
],
'__search_fields__': ['id', '_url', 'name'],
# '__headers__': {'_url': 'Url'},
# '__headers__': {'_url': 'Url'},
'__xml_fields__': ['teachers', 'tutors'],
'start_time': lambda filler, obj: h.strftime(obj.start_time, False),
'end_time': lambda filler, obj: h.strftime(obj.end_time, False),
'teachers': lambda filler, obj: \
', '.join(link_to(teacher.display_name, '../tutors/%d/edit' % teacher.id) \
'teachers': lambda filler, obj:
', '.join(link_to(teacher.display_name, '../tutors/%d/edit' % teacher.id)
for teacher in set(obj.teachers)),
'tutors': lambda filler, obj: \
', '.join(link_to(tutor.display_name, '../tutors/%d/edit' % tutor.id) \
'tutors': lambda filler, obj:
', '.join(link_to(tutor.display_name, '../tutors/%d/edit' % tutor.id)
for tutor in obj.tutors),
'_members': lambda filler, obj: \
', '.join(link_to(student.display_name, '../students/%d/edit' % student.id) \
'_members': lambda filler, obj:
', '.join(link_to(student.display_name, '../students/%d/edit' % student.id)
for student in obj._members),
'__base_widget_args__': {'sortList': [[6, 1], [5, 1]]},
}
Expand Down Expand Up @@ -116,11 +116,14 @@ class EventsCrudController(FilterCrudRestController):
'help_text': u'Password for enrolling. If empty and enroll is not None, all students can enroll.',
},
'_members': {
'help_text': u'These are only DIRECT members of this event. You might want to add users to lessons and/or teams instead.',
'help_text': u'These are only DIRECT members of this event. '
'You might want to add users to lessons and/or teams instead.',
},
},
'__field_validator_types__': {'_url': PlainText},
'__field_validators__': {'enroll': twc.validation.OneOfValidator(values=['event', 'lesson', 'lesson_team', 'team', 'team_new'])},
'__field_validators__': {
'enroll': twc.validation.OneOfValidator(values=['event', 'lesson', 'lesson_team', 'team', 'team_new']),
},
'__dropdown_field_names__': ['user_name', '_name', 'name', 'title'],
'__require_fields__': ['type', '_url'],
}
Expand All @@ -144,16 +147,16 @@ class LessonsCrudController(FilterCrudRestController):
'id', 'lesson_id', 'name',
('teams', 'team_id'), ('_members', 'member_id'),
],
# '__headers__': {'_students': 'Students'},
# '__headers__': {'_students': 'Students'},
'__xml_fields__': ['tutors', 'teams', '_members'],
'tutors': lambda filler, obj: \
', '.join(link_to(tutor.display_name, '../tutors/%d/edit' % tutor.id) \
'tutors': lambda filler, obj:
', '.join(link_to(tutor.display_name, '../tutors/%d/edit' % tutor.id)
for tutor in set(obj.tutors)),
'teams': lambda filler, obj: \
', '.join(link_to(team.name, '../teams/%d/edit' % team.id) \
'teams': lambda filler, obj:
', '.join(link_to(team.name, '../teams/%d/edit' % team.id)
for team in obj.teams),
'_members': lambda filler, obj: \
', '.join(link_to(student.display_name, '../students/%d/edit' % student.id) \
'_members': lambda filler, obj:
', '.join(link_to(student.display_name, '../students/%d/edit' % student.id)
for student in obj._members),
'__base_widget_args__': {'sortList': [[1, 0]]},
}
Expand All @@ -167,7 +170,8 @@ class LessonsCrudController(FilterCrudRestController):
'help_text': u'This id will be part of the url and has to be unique for the parent event',
},
'_members': {
'help_text': u'These are only DIRECT members of this lesson. You might want to add users to teams instead.',
'help_text': u'These are only DIRECT members of this lesson.'
'You might want to add users to teams instead.',
},
},
'__dropdown_field_names__': ['user_name', '_name', 'name', 'title'],
Expand Down
2 changes: 1 addition & 1 deletion sauce/controllers/crc/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class NewsItemController(FilterCrudRestController):
'__field_widget_args__': {
'event': {
'help_text': u'''
If an event is set, the NewsItem will be shown on the event page;
If an event is set, the NewsItem will be shown on the event page;
if no event is set, the NewsItem is shown on the news page''',
},
},
Expand Down
Loading

0 comments on commit b04e4b8

Please sign in to comment.