Example #1
0
 def post(self, request, *args, **kwargs):
     try:
         postParameters = json.loads(request.raw_post_data)
         username = postParameters["username"]
         password = postParameters["password"]
         firstname = postParameters["firstname"]
         lastname = postParameters["lastname"]
         emailid = postParameters["emailid"]
         
         # Check all fields for validity
         validator = Validator()
         valid = True
         message = None
         
         if validator.hasSpace(username):
             valid = False
             message = "Invalid username. Spaces not allowed."
         elif not validator.isNotEmpty(firstname):
             valid = False
             message = "Firstname is empty."
         elif not validator.validateEmail(emailid):
             valid = False
             message = "Invalid email address."
         elif not validator.validatePassword(password):
             valid = False
             message = "Password must be at least 6 characters long."
         
         if not valid:
             response = {'success': False, 'message': message}
             return HttpResponse(json.dumps(response))
         
         user, iscreated = User.objects.get_or_create(username=username, defaults={'first_name': firstname, 'last_name': lastname, 'email': emailid})
         if not iscreated:
             response = {'success': False, 'message': 'Username already exists.'}
             return HttpResponse(json.dumps(response))
         else:
             user.set_password(password)
             user.save()
             response = {'success': True, 'message': 'User account created.'}
             return HttpResponse(json.dumps(response))
     except:
         response = {'success': False, 'message': 'Error creating user account.'}
     return HttpResponse(json.dumps(response))
Example #2
0
    def post(self):
        
        from utils import Validator

        #XXX: need to add user interface

        write = self.response.out.write

        #XXX: needs validation!

        input = {
         "title": self.request.get("title"),
         "comment": self.request.get("comment"),
         "code": self.request.get("code"),
         "type": self.request.get("type"),
        }

        val = Validator(input)

        if not val.is_valid():
            write(Site(self, self.user_status_values).get_content(issues=val.get_issues(),vars=val.get_vars())) 
            return

        #getting only the first 8 characters of uuid:
        self.db.paste.uid = str(uuid.uuid4())[:8]
        self.db.paste.name = self.user_status_values['user']
        self.db.paste.title = val.get_var("title")
        self.db.paste.comment = val.get_var("comment")
        self.db.paste.code = val.get_var("code")
        self.db.paste.type = val.get_var("type")
        self.db.paste.put()

        #Updating Type Statistics
        self.db.aux= db.GqlQuery("SELECT * FROM Stats WHERE type = :1",val.get_var("type")).fetch(1)

        if self.db.aux:
            for stat in self.db.aux:
                stat.number = stat.number+1
        else:
            stat = Stats(type=val.get_var("type"),number=1)

        stat.put()

        self.response.headers['Content-Type'] = 'text/html'
        write(Site(self, self.user_status_values).get_content(uid=self.db.paste.uid))
Example #3
0
 def get_validator(self):
     res = Validator(['game_db_id', 'move'])
     return res
Example #4
0
 def get_validator(self):
     res = Validator(["id", "challenge_id"])
     return res
 def get_validator(self):
     res = Validator(['id', 'challenger_id', 'title', 'settings'])
     return res
 def get_validator(self):
     res = Validator(['code'])
     return res
 def get_validator(self):
     res = Validator(['id', 'token', 'game_id', 'index'])
     return res
Example #8
0
 def get_validator(self):
     res = Validator(['game_id'])
     return res
Example #9
0
 def get_validator(self):
     res = Validator(['users', 'title', 'settings', 'result'])
     return res
Example #10
0
 def get_validator(self):
     res = Validator(['id', 'token', 'picture_id'])
     return res
Example #11
0
 def get_validator(self):
     res = Validator(['id', 'token', 'amount'])
     return res
Example #12
0
 def get_validator(self):
     res = Validator(['id', 'token', 'size', "narde", "backgammon"])
     return res
Example #13
0
 def get_validator(self):
     res = Validator(['login', 'password'])
     return res
Example #14
0
 def get_validator(self):
     res = Validator(['index', 'best_move', 'variations'])
     return res
Example #15
0
 def get_validator(self):
     res = Validator(['id', 'token', 'index', 'chunk'])
     return res
Example #16
0
 def get_validator(self):
     res = Validator(['max', 'game', 'settings'])
     return res
Example #17
0
 def get_validator(self):
     res = Validator(['id', 'token', 'index', 'server_id', 'size'])
     return res
Example #18
0
 def get_validator(self):
     res = Validator(['id', 'receiver', 'message'])
     return res
 def get_validator(self):
     res = Validator(
         ['id', 'token', 'game_id', 'users', 'title', 'settings'])
     return res
Example #20
0
 def get_validator(self):
     res = Validator([])
     return res
Example #21
0
 def get_validator(self):
     res = Validator(['id', 'token', 'user_id'])
     return res
Example #22
0
    logger = None

timer = time.time()
start = timer

trainer = Trainer(
    model,
    optimizer,
    loss_fn=loss_fn,
    accu_fn='dice',
    load_checkpoint=args.checkpoint,
    logger=logger,
)

validator = Validator(
    trainer.model,
    threshold=config['output_threshold'],
)

if args.validate_only:
    validator.run(data_gen['valid'])
    logger.close()
    print('Total:', time.time() - start)
    exit(0)

checkpoint_dir = args.checkpoint_dir
if checkpoint_dir:
    os.makedirs(checkpoint_dir, exist_ok=True)

# early stopper
if config['early_stopping_epochs'] > 1:
    early_stopper = EarlyStopper(config['early_stopping_epochs'])
Example #23
0
 def get_validator(self):
     res = Validator(['id', 'token', 'new_rank'])
     return res