コード例 #1
0
 def from_db(slug, preview=False, author=None):
     mydef = None
     if not preview:
         for action, definition, sharing, id in config.get_rows(
                 "select action, definition, sharing, id from ws_sheets " +
                 "WHERE problem = %s AND action != 'preview' ORDER BY ID DESC LIMIT 1;",
             [slug]):
             if action == 'delete': return None
             if sharing == 'draft': return None
             mydef = definition
     else:
         for definition, id in config.get_rows(
                 "select definition, id from ws_sheets " +
                 "WHERE problem = %s AND author = %s AND action = 'preview' ORDER BY ID DESC LIMIT 1;",
             [slug, author]):
             mydef = definition
     if mydef != None:
         mymap = json.loads(definition)
         json_fields = [
             'choices', 'verboten', 'imports', 'dependencies',
             'cppflags_add', 'cppflags_remove'
         ]
         if mymap['lang'] in ['C++', 'C++func']:
             json_fields += ['tests']
         for x in json_fields:
             if x in mymap:
                 mymap[x] = json.loads(mymap[x])
         return Websheet(mymap, slug)
     return None
コード例 #2
0
 def definition(slug, username):
     for definition, sharing, author, action in config.get_rows(
             "select definition, sharing, author, action from ws_sheets " +
             "WHERE problem = %s AND action != 'preview' ORDER BY ID DESC LIMIT 1;",
         [slug]):
         if action == 'delete': continue
         if not sharing.startswith('open') and author != username:
             continue  # closed-source
         if sharing == 'open-nosol' and author != username and not authinfo[
                 'is_super']:
             definition = json.loads(definition)
             if 'choices' in definition:
                 definition['choices'] = json.dumps(
                     [[x[0], None]
                      for x in json.loads(definition['choices'])])
             if 'answer' in definition:
                 definition['answer'] = 'REDACTED'
             if 'source_code' in definition:
                 bits = definition['source_code'].split(r'\[')
                 for i in range(1, len(bits)):
                     if r'\show:' in bits[i]:
                         p = bits[i].index(r'\show:')
                     elif ']\\' in bits[i]:
                         p = bits[i].index(']\\')
                     bits[i] = ('\nREDACTED\n' if '\n' in bits[i][:p] else
                                ' REDACTED ') + bits[i][p:]
                 definition['source_code'] = r'\['.join(bits)
             definition = json.dumps(definition)
         return definition
     internal_error('Whoa, where did that row go?')
コード例 #3
0
ファイル: edit.py プロジェクト: Manomama7/websheets
 def definition(slug, username):
     for definition, sharing, author, action in config.get_rows(
         "select definition, sharing, author, action from ws_sheets "
         + "WHERE problem = %s AND action != 'preview' ORDER BY ID DESC LIMIT 1;",
         [slug],
     ):
         if action == "delete":
             continue
         if not sharing.startswith("open") and author != username:
             continue  # closed-source
         if sharing == "open-nosol" and author != username and not authinfo["is_super"]:
             definition = json.loads(definition)
             if "choices" in definition:
                 definition["choices"] = json.dumps([[x[0], None] for x in json.loads(definition["choices"])])
             if "answer" in definition:
                 definition["answer"] = "REDACTED"
             if "source_code" in definition:
                 bits = definition["source_code"].split(r"\[")
                 for i in range(1, len(bits)):
                     if r"\show:" in bits[i]:
                         p = bits[i].index(r"\show:")
                     elif "]\\" in bits[i]:
                         p = bits[i].index("]\\")
                     bits[i] = ("\nREDACTED\n" if "\n" in bits[i][:p] else " REDACTED ") + bits[i][p:]
                 definition["source_code"] = r"\[".join(bits)
             definition = json.dumps(definition)
         return definition
     internal_error("Whoa, where did that row go?")
コード例 #4
0
ファイル: Websheet.py プロジェクト: Adamawa/websheets
 def from_db(slug, preview = False, author = None):
     mydef = None
     if not preview:
         for action, definition, sharing, id in config.get_rows(
             "select action, definition, sharing, id from ws_sheets " +
             "WHERE problem = %s AND action != 'preview' ORDER BY ID DESC LIMIT 1;", [slug]):
             if action == 'delete': return None
             if sharing == 'draft': return None
             mydef = definition
     else:            
         for definition, id in config.get_rows(
             "select definition, id from ws_sheets " +
             "WHERE problem = %s AND author = %s AND action = 'preview' ORDER BY ID DESC LIMIT 1;", [slug, author]):
             mydef = definition
     if mydef != None:
         mymap = json.loads(definition)
         json_fields = ['choices', 'verboten', 'imports', 'dependencies', 'cppflags_add', 'cppflags_remove']
         if mymap['lang'] in ['C++', 'C++func']:
             json_fields += ['tests']
         for x in json_fields:
             if x in mymap:
                 mymap[x] = json.loads(mymap[x])
         return Websheet(mymap, slug)
     return None
コード例 #5
0
ファイル: Websheet.py プロジェクト: Adamawa/websheets
    def list_exercises_in(directory = ""):
        result = []
        prefix = '' if directory=='' else directory+'/'

        for problem, action, sharing in config.get_rows(
            """SELECT o1.problem, o1.action, o1.sharing FROM ws_sheets o1
            INNER JOIN (SELECT problem, MAX(id) AS id FROM ws_sheets WHERE 
            action != 'preview' AND problem LIKE %s AND problem NOT LIKE %s
            GROUP BY problem) o2
            ON (o1.problem = o2.problem AND o1.id = o2.id);""", [prefix+'%', prefix+'%/%']):
            if action == 'delete': continue
            if sharing == 'draft' or sharing == 'hidden': continue
            result += [problem[len(prefix):]]

        result.sort()
        return result
コード例 #6
0
ファイル: Websheet.py プロジェクト: leilavc/websheets
    def list_exercises_in(directory = ""):
        result = []
        prefix = '' if directory=='' else directory+'/'

        for problem, action, sharing in config.get_rows(
            """SELECT o1.problem, o1.action, o1.sharing FROM ws_sheets o1
            INNER JOIN (SELECT problem, MAX(id) AS id FROM ws_sheets WHERE 
            action != 'preview' AND problem LIKE %s AND problem NOT LIKE %s
            GROUP BY problem) o2
            ON (o1.problem = o2.problem AND o1.id = o2.id);""", [prefix+'%', prefix+'%/%']):
            if action == 'delete': continue
            if sharing == 'draft' or sharing == 'hidden': continue
            result += [problem[len(prefix):]]

        result.sort()
        return result
コード例 #7
0
ファイル: Websheet.py プロジェクト: Adamawa/websheets
    def list_subgroups_in(directory = ""):
        result = set()
        prefix = '' if directory=='' else directory+'/'

        
        for problem, action, sharing in config.get_rows(
            """SELECT o1.problem, o1.action, o1.sharing FROM ws_sheets o1
            INNER JOIN (SELECT problem, MAX(id) AS id FROM ws_sheets WHERE
            action != 'preview' AND problem LIKE %s
            GROUP BY problem) o2
            ON (o1.problem = o2.problem AND o1.id = o2.id);""", [prefix+'%/%']):
            if action == 'delete': continue
            if sharing == 'draft' or sharing == 'hidden': continue
            result |= {prefix+problem[len(prefix):].split('/')[0]}

        result = list(result)
        result.sort()
        return result
コード例 #8
0
    def list_subgroups_in(directory=""):
        result = set()
        prefix = '' if directory == '' else directory + '/'

        for problem, action, sharing in config.get_rows(
                """SELECT o1.problem, o1.action, o1.sharing FROM ws_sheets o1
            INNER JOIN (SELECT problem, MAX(id) AS id FROM ws_sheets WHERE
            action != 'preview' AND problem LIKE %s
            GROUP BY problem) o2
            ON (o1.problem = o2.problem AND o1.id = o2.id);""",
            [prefix + '%/%']):
            if action == 'delete': continue
            if sharing == 'draft' or sharing == 'hidden': continue
            result |= {prefix + problem[len(prefix):].split('/')[0]}

        result = list(result)
        result.sort()
        return result
コード例 #9
0
ファイル: edit.py プロジェクト: daveagp/websheets
  def list_problems(username):
    result = []

    for problem, action, sharing, author in config.get_rows(
      """SELECT o1.problem, o1.action, o1.sharing, o1.author FROM ws_sheets o1
      INNER JOIN (SELECT problem, MAX(id) AS id FROM ws_sheets WHERE action != 'preview' GROUP BY problem) o2
      ON (o1.problem = o2.problem AND o1.id = o2.id);"""):
      if action == 'delete': continue
      if author != username:
        if sharing == 'draft' or sharing == 'hidden': continue
      result.append([problem, author != username, sharing, author])
    #saner sort, files before folders
    for x in result:
      tmp = x[0].split('/')
      x[0] = [tmp[:-1], tmp[-1]]
    result.sort()
#    print(result)
    for x in result: x[0] = '/'.join(x[0][0]+[x[0][1]])
    return result
コード例 #10
0
  def list_problems(username):
    result = []

    for problem, action, sharing, author in config.get_rows(
      """SELECT o1.problem, o1.action, o1.sharing, o1.author FROM ws_sheets o1
      INNER JOIN (SELECT problem, MAX(id) AS id FROM ws_sheets WHERE action != 'preview' GROUP BY problem) o2
      ON (o1.problem = o2.problem AND o1.id = o2.id);"""):
      if action == 'delete': continue
      if author != username:
        if sharing == 'draft' or sharing == 'hidden': continue
      result.append([problem, author != username, sharing, author])
    #saner sort, files before folders
    for x in result:
      tmp = x[0].split('/')
      x[0] = [tmp[:-1], tmp[-1]]
    result.sort()
#    print(result)
    for x in result: x[0] = '/'.join(x[0][0]+[x[0][1]])
    return result
コード例 #11
0
ファイル: edit.py プロジェクト: daveagp/websheets
 def definition(slug, username):
   for definition, sharing, author, action in config.get_rows(
     "select definition, sharing, author, action from ws_sheets " +
     "WHERE problem = %s AND action != 'preview' ORDER BY ID DESC LIMIT 1;", [slug]):
     if action == 'delete': continue
     if not sharing.startswith('open') and author != username: continue # closed-source
     if sharing=='open-nosol' and author != username and not authinfo['is_super']:
       definition = json.loads(definition)
       if 'choices' in definition:
         definition['choices'] = json.dumps([[x[0], None] for x in json.loads(definition['choices'])])
       if 'answer' in definition:
         definition['answer'] = 'REDACTED'
       if 'source_code' in definition:
         bits = definition['source_code'].split(r'\[')
         for i in range(1, len(bits)):
           if r'\show:' in bits[i]:
             p = bits[i].index(r'\show:')
           elif ']\\' in bits[i]:
             p = bits[i].index(']\\')
           bits[i] = ('\nREDACTED\n' if '\n' in bits[i][:p] else ' REDACTED ') + bits[i][p:]
         definition['source_code'] = r'\['.join(bits)
       definition = json.dumps(definition)
     return definition
   internal_error('Whoa, where did that row go?')
コード例 #12
0
import config

#~ authinfo = {}  
#~ authinfo['username'] = "******"


result = {}
for (student,) in config.get_rows(
  "select user from ws_settings ;"):  
  #~ +  "WHERE value = %s AND keyname = 'instructor';", [authinfo['username']]):
  stuinfo = {}
  for (passed, time, problem) in config.get_rows(
    "SELECT passed, time, problem from ws_history where user = %s order by id asc;", [student]):
    if (problem not in stuinfo): prev = (False, 0)
    else: prev = stuinfo[problem]
    if not prev[0]: # if not yet passed
      if passed==1:
        curr = (True, prev[1]+1, time.strftime('%Y-%m-%d %H:%M:%S'))
      else:
        curr = (False, prev[1]+1)
      stuinfo[problem] = curr
  result[student] = stuinfo

from pprint import pprint
pprint(result)

import json
#json.dumps( result )
コード例 #13
0
ファイル: edit.py プロジェクト: daveagp/websheets
 def get_setting(user, key):
   for (value,) in config.get_rows(
     "select value from ws_settings " +
     "WHERE user = %s AND keyname = %s;", [user, key]):
     return value
コード例 #14
0
ファイル: edit.py プロジェクト: daveagp/websheets
          definition= definition(problem, authinfo['username']), author=myowner)

  if action == 'listmine':
    done(problems = list_problems(authinfo['username']))

  if action == 'settings':
    if 'instructor' in request:
      set_setting(authinfo['username'], 'instructor', request['instructor'])
    inst = get_setting(authinfo['username'], 'instructor')
    if inst is None: inst = ""
    done(success=True, settings={"instructor":inst})
    
  if action == 'showgrades':
    result = {}
    for (student,) in config.get_rows(
      "select user from ws_settings " +
      "WHERE value = %s AND keyname = 'instructor';", [authinfo['username']]):
      stuinfo = {}
      for (passed, time, problem) in config.get_rows(
        "SELECT passed, time, problem from ws_history where user = %s order by id asc;", [student]):
        if (problem not in stuinfo): prev = (False, 0)
        else: prev = stuinfo[problem]
        if not prev[0]: # if not yet passed
          if passed==1:
            curr = (True, prev[1]+1, time.strftime('%Y-%m-%d %H:%M:%S'))
          else:
            curr = (False, prev[1]+1)
          stuinfo[problem] = curr
      result[student] = stuinfo
    done(success=True, grades=result)
    
コード例 #15
0
 def get_setting(user, key):
   for (value,) in config.get_rows(
     "select value from ws_settings " +
     "WHERE user = %s AND keyname = %s;", [user, key]):
     return value
コード例 #16
0
          definition= definition(problem, authinfo['username']), author=myowner)

  if action == 'listmine':
    done(problems = list_problems(authinfo['username']))

  if action == 'settings':
    if 'instructor' in request:
      set_setting(authinfo['username'], 'instructor', request['instructor'])
    inst = get_setting(authinfo['username'], 'instructor')
    if inst is None: inst = ""
    done(success=True, settings={"instructor":inst})
    
  if action == 'showgrades':
    result = {}
    for (student,) in config.get_rows(
      "select user from ws_settings " +
      "WHERE value = %s AND keyname = 'instructor';", [authinfo['username']]):
      stuinfo = {}
      for (passed, time, problem) in config.get_rows(
        "SELECT passed, time, problem from ws_history where user = %s order by id asc;", [student]):
        if (problem not in stuinfo): prev = (False, 0)
        else: prev = stuinfo[problem]
        if not prev[0]: # if not yet passed
          if passed==1:
            curr = (True, prev[1]+1, time.strftime('%Y-%m-%d %H:%M:%S'))
          else:
            curr = (False, prev[1]+1)
          stuinfo[problem] = curr
      result[student] = stuinfo
    done(success=True, grades=result)