def ParseError(msg, request, status=400): caltitle = request.POST.get("title", '') callocation = request.POST.get("location", '') shiftinput = request.POST.get("roster", None) if not caltitle: caltitle = request.GET.get("title", '') if not callocation: callocation = request.GET.get("location", '') dbroster = Roster( event_title=caltitle, event_location=callocation, raw_roster=shiftinput, method='site', created=dtnow(), success=False, error=msg ) if request.POST.get('bm', False): dbroster.method = 'bookmarklet' dbroster.version = request.POST.get('v', '_none_') dbroster.save() return JSONError(msg, status)
def parse(request): if not request.POST: return JSONError('Method must be POST') bookmarklet = request.POST.get('bm', False) raw = request.POST.get('roster', False) if not raw: return ParseError('Roster not specified', request) title = request.POST.get("title", "") location = request.POST.get("location", "") sat_regex_str = r'(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s{1,5}(\d{2}),?\s{1,5}(2\d{3})' matched_sat = re.findall(sat_regex_str, raw) if len(matched_sat) != 1: return ParseError('Could not determine dates for the roster. Make sure you copy from "Schedule begins" onwards', request) try: sat, roster, hours = parse_roster(raw) hours = hours.seconds / 60.0 / 60.0 dump = {'sat': sat, 'roster': roster} except Exception: return ParseError('Unexpected error interpreting the roster.', request) if len(roster) < 1: return ParseError('Found no shifts.', request) accesstoken = makeAccessCode(10) method = 'bookmarklet' if bookmarklet else 'site' dbroster = Roster( token=accesstoken, event_title=limit(title, 100), event_location=limit(location, 100), method=method, created=dtnow(), success=True, dump=pickle.dumps(dump), ) dbroster.save() json_response = { "status": "success", "hours": hours, "accesstoken": accesstoken, "bookmarklet": bookmarklet, } return HttpResponse(json.dumps(json_response), content_type='application/json; charset=utf8')
if not teams: teams = Team.objects.filter(universe=universe) shuffle(list(teams)) draft_preference = {} nbr_positions = 0 for team in teams: try: r = Roster.objects.get(universe=universe, year=current_year, team=team) except: r = Roster(universe=universe, year=current_year, team=team) r.save() draft_preference[team] = deepcopy(json.loads(team.draft_position_order)) draft_preference[team] = determine_draft_needs(draft_preference[team], r) if nbr_positions < len(draft_preference[team]): nbr_positions=len(draft_preference[team]) draft_order=[] for i in xrange(nbr_positions): for team in teams: try: draft_order.append((team, draft_preference[team][i])) except: pass for pick_team, pick_position in draft_order: players = Player.objects.filter(universe=universe, position=pick_position, retired=False,