def form_valid(self, form): email = form.cleaned_data['email'] password = form.cleaned_data['password'] firstName = form.cleaned_data['firstName'] lastName = form.cleaned_data['lastName'] user = User.objects.create_user(email, email, password) user.first_name = firstName user.last_name = lastName if settings.EMAIL_VERIFICATION: user.is_active = False user.save() #login the user after creation user = authenticate(email=email, password=password) login(self.request, user) verificationCode = utility.generateRandomString(14) user.profile.verifyEmailCode = verificationCode emailService = EmailService() if emailService.sendRegistrationEmail(user, verificationCode): user.profile.save() return HttpResponseRedirect('/home/') return super(RegistrationView, self).form_valid(form)
def set_grid_tables_data(self, gridTablesData): session = self.session gridsData = ParticipatingSessionsContentGridsData() self.participatingSessionsContentGridsData = gridsData gridsData.displaySessionGrid = True gridsData.displayResponseGrid = True gridsData.sessionGridData = GridTableData(gridTablesData["sessionGridTable"]) gridsData.sessionGridData.tableId = generateRandomString() gridsData.sessionGridData.doesNotShowLegend = True # check to see if there is a response table, if so add it if "currentResponseGridTable" in gridTablesData: gridsData.responseGridData = GridTableData(gridTablesData["currentResponseGridTable"]) else: # if there is no response display a table with the data as seem in the session grid gridsData.responseGridData = GridTableData(gridTablesData["sessionGridTable"]) # the weights need to be duplicated in a new object as the list will be poped later on gridsData.responseGridData.weights = gridsData.sessionGridData.weights[:] gridsData.responseGridData.tableId = generateRandomString() # if the gridTablesData contains a previous response table add it if "previousResponseGrid" in gridTablesData: gridsData.previousResponseGridData = GridTableData(gridTablesData["previousResponseGrid"]) gridsData.previousResponseGridData.tableId = generateRandomString() gridsData.previousResponseGridData.doesNotShowLegend = True gridsData.displayPreviousResponseGrid = True # calculate how many participants there are in this session and how many have sent a response self.showNParticipantsAndResponses = True if session.state.is_alt_and_con_state(): gridsData.responseGridData.changeCornAlt = True gridsData.responseGridData.doesNotShowLegend = True elif session.state.is_ratings_weights_state(): gridsData.responseGridData.changeRatingsWeights = True gridsData.sessionGridData.showRatingWhileFalseChangeRatingsWeights = ( "previousResponseGrid" in gridTablesData ) try: self.responseGrid = ResponseGrid.objects.get_current(session, self.user) except ResponseGrid.DoesNotExist: self.responseGrid = None
def form_valid(self, form): email = form.cleaned_data['email'] user = User.objects.get(email=email) code = PassRecoverCode() code.email = email code.linkCode = generateRandomString(14) emailService = EmailService() if emailService.sendForgotPasswordEmail(user, code): code.save() return self.render_to_response(self.get_context_data(form=form, checkEmail=True)) else: # error in sending mail pass return super(ForgotPasswordView, self).form_valid(form)
def __init__(self, session=None): if session is not None: self.session = session sessionGrid = session.get_session_grid() grid_template_data = GridTableData(generateGridTable(sessionGrid)) grid_template_data.showRatingWhileFalseChangeRatingsWeights = session.state.name != SessionState.CHECK grid_template_data.tableId = generateRandomString() grid_template_data.usid = sessionGrid.usid self.tableData = grid_template_data self.participantTableData = ParticipantsData(session=session) self.iterations_with_results = session.get_iterations_with_results() if session.state.name == SessionState.CHECK: self.showRequestButtons = True self.showCloseSessionButton = True self.saveGridSession = True grid_template_data.changeRatingsWeights = True grid_template_data.changeCornAlt = True grid_template_data.checkForTableIsSave = True
def createCompositeGrid(self, userObj, gridName, rules, statuses): """ This function is a modificated version of 'createGrid' function. What is different is we don't have any numeric values here, just alternative names(combinations of valid rules), and also we are providing grid.usid beforehand """ if not None in (userObj, rules, statuses): gridObj = Grid.objects.create(user=userObj, grid_type=Grid.GridType.COMPOSITE_GRID) if gridName != None: gridObj.name = gridName gridObj.usid = generateRandomString(GRID_USID_KEY_LENGTH) gridObj.dateTime = datetime.utcnow().replace(tzinfo=utc) gridObj.save() for idx, rule in enumerate(rules): parser = CompositeParse(rule) compositions = parser.getCompositions() status = statuses[idx].lower() for composition in compositions: Composite.objects.create(compid=gridObj.usid, user=userObj, rule=composition, status=status) alternatives = [] rules = Composite.objects.filter(compid=gridObj.usid, status="valid") for r in rules: a = r.rule a = a.replace("u'", "") alternative = Alternatives.objects.create(grid=gridObj, name=str(a.replace("'", ""))) alternatives.append(alternative) concernValues = [['lc1', 'rc1'],['lc2', 'rc2'],['lc3', 'rc3']] concerns = [] for [left, right] in concernValues: concern = Concerns.objects.create(grid=gridObj, leftPole=left, rightPole=right) concerns.append(concern) for concern in concerns: for alternative in alternatives: Ratings.objects.create(concern=concern, alternative=alternative) return gridObj else: raise ValueError('One or more variables were None')