def form_valid(self, form): try: pos=self.add_logger(form.cleaned_data) self.success_url='/net/added/{}'.format(pos.pk) except IntegrityError as e: raise ValidationError(e) return FormView.form_valid(self, form)
def form_valid(self, form): csv_file = form.cleaned_data.get("csv_file") df = pandas.read_excel(csv_file) df.dropna(how="all", inplace=True) for i in range(len(df)): try: exam_name = df['quiz'][i] q_category = df['category'][i] q_subcategory = df['sub_category'][i] exam, crt = Exam.objects.get_or_create(name=exam_name, exam_type=Exam.EXAM) q_text = df['content'][i] q_explanation = df['explanation'][i] correct_answer_text = df['correct'][i] wrong_1 = df['answer1'][i] wrong_2 = df['answer2'][i] wrong_3 = df['answer3'][i] if q_text != "n" and correct_answer_text != "n" and str(q_text) != "nan" and q_text != " ": q, crt = Question.objects.get_or_create(exam=exam, text=q_text) if crt: q.explanation = q_explanation q.text = q_text q.category = q_category q.subcategory = q_subcategory q.save() Answer.objects.create(question=q, text=correct_answer_text, correct=True) Answer.objects.create(question=q, text=wrong_1) Answer.objects.create(question=q, text=wrong_2) Answer.objects.create(question=q, text=wrong_3) except: print("Skip row") messages.info(self.request, "your exam data imported successfully.") return FormView.form_valid(self, form)
def form_valid(self, form): response = FormView.form_valid(self, form) # After successful login, save dict of user data given by data server # API into JWT cookie. Also save session id of session from data # server, for use when making requests to data server via Rabbit. # Note UI server and admin server have different secrets and domains. jwt_val = jwt.encode( { "user": form.user, "session": form.session_cookie.value }, settings.COOKIE_SECRET, ) expires = datetime.fromtimestamp(form.session_cookie.expires)\ .strftime('%a, %d %b %Y %H:%M:%S') kwargs = { 'value': jwt_val, 'expires': expires, 'secure': settings.SESSION_COOKIE_SECURE, 'httponly': True, 'domain': cookie_domain(), } response.set_cookie("alice", **kwargs) return response
def form_valid(self, form): """Create operation with optional splits.""" self.form = form date = form.cleaned_data['date'] if form.cleaned_data['splits'] == 1: models.Operation.objects.create( account=form.cleaned_data['account'], transaction=form.cleaned_data['transaction'], date=date, amount=form.cleaned_data['amount'], description=form.cleaned_data['description'], ) else: splits = split_amount( form.cleaned_data['amount'], form.cleaned_data['splits']) for position, amount in enumerate(splits): description = u'{desc} ({total}/{splits}, part {pos})'.format( desc=form.cleaned_data['description'], pos=position + 1, splits=form.cleaned_data['splits'], total=form.cleaned_data['amount']) models.Operation.objects.create( account=form.cleaned_data['account'], transaction=form.cleaned_data['transaction'], date=date + relativedelta(months=position), amount=amount, description=description, ) return FormView.form_valid(self, form)
def form_valid(self, form): # Create signature instance in local DB. SignatureType = django_anysign.get_signature_type_model() Signature = django_anysign.get_signature_model() Signer = django_anysign.get_signer_model() signature_type, created = SignatureType.objects.get_or_create( signature_backend_code='dummysign') signature = Signature.objects.create(signature_type=signature_type) Signer.objects.create(signature=signature) logger.debug( '[django_anysign_demo] Signature ID={id} created in local DB' .format(id=signature.id)) # Register signature in backend's DB. signature.signature_backend.create_signature(signature) # Remember the signature object for later use (:meth:`get_success_url`) self.signature = signature # Handle the form as always. return FormView.form_valid(self, form)
def form_valid(self, form): user = self.request.user recipe = get_object_or_404(Recipe, pk=self.kwargs['recipe_pk']) score = form.cleaned_data['score'] comment = form.cleaned_data['comment'] try: obj = RecipeComment.objects.get( user=user, recipe=recipe, ) obj.score = form.cleaned_data['score'] obj.comment = form.cleaned_data['comment'] except RecipeComment.DoesNotExist: obj = RecipeComment.objects.create( recipe=recipe, comment=comment, score=score, user=user, ) obj.save() return FormView.form_valid(self, form)
def form_valid(self, form): from os import path csv_file = form.cleaned_data.get("csv_file") df = pandas.read_excel(csv_file) df.dropna(how="all", inplace=True) for i in range(len(df)): try: presentation_name = df['presentation_name'][i] topic = df['topic'][i] slide = df['slide'][i] slide = slide.replace("-", "_") space_slide = slide.replace(" ", "_") presentation, crt = Presentation.objects.get_or_create( elearning=presentation_name, topic=topic, slide=space_slide) except: print("Skip row") messages.info(self.request, "your presentation data imported successfully.") return FormView.form_valid(self, form)
def form_valid(self, form): csv_file = form.cleaned_data.get("csv_file") from os import path df = pandas.read_excel(csv_file) df.dropna(how="all", inplace=True) for i in range(len(df)): try: data = { 'username': df['username'][i], 'surname': df['surname'][i], 'email': df['email'][i], 'name': df['username'][i], 'manager': df['Manager'][i], 'member_type': df['Member type'][i], } user, crt = User.objects.get_or_create(**data) user.set_password(df['password'][i]) user.save() except: print("Skip row") messages.info(self.request, "your user data imported successfully.") return FormView.form_valid(self, form)
def form_valid(self, form): """ If form is valid, create on data server """ self.win = form.create() return FormView.form_valid(self, form)
def form_valid(self, form): if not self.sample: form.save() return FormView.form_valid(self, form)
def form_valid(self, form): form.add_vote() return FormView.form_valid(self, form)
def form_valid(self, form): """ If form is valid, update on data server """ form.update(self.kwargs['win_id']) return FormView.form_valid(self, form)
def form_valid(self, form): retval_redir = self._form_valid_redirect(form) retval = FormView.form_valid(self, form) if retval_redir is not None: return retval_redir return retval
def form_valid(self, form): with transaction.atomic(): form.save() from django.contrib.auth import update_session_auth_hash update_session_auth_hash(self.request, form.user) return FormView.form_valid(self, form)
def form_valid(self, form): form.save() messages.info(self.request, "Your information has been updated") return FormView.form_valid(self, form)
def form_valid(self, form): form.save() return FormView.form_valid(self, form)
def form_valid(self, form): self._profile = form.register_tenant() return FormView.form_valid(self, form)
def form_valid(self, form): login(self.request, form.user) response = FormView.form_valid(self, form) response.set_cookie("alice", form.user.token) return response
def form_valid(self, form): SMSNotification.objects.filter( phone=form.cleaned_data["phone"]).delete() return FormView.form_valid(self, form)
def form_valid(self, form): customer = form.save() if "utm_source" in self.request.session: source = self.request.session["utm_source"] else: source = "internal" self.order = Order.objects.create(num=id_gen(), customer=customer, source=source) travels = self.request.session["travels"] for travel in travels: for traveller in travel["go"]["travellers"]: ticket = Ticket.objects.create( num=id_gen(), order=self.order, traveller_first_name=traveller["first_name"], traveller_last_name=traveller["last_name"], departure_stop=Stop.objects.get( id=travel["go"]["timeslots"][0]["stop_id"]), arrival_stop=Stop.objects.get( id=travel["go"]["timeslots"][-1]["stop_id"]), departure_hour=datetime.strptime( travel["go"]["timeslots"][0]["hour"], "%H:%M").time(), arrival_hour=datetime.strptime( travel["go"]["timeslots"][-1]["hour"], "%H:%M").time(), date=datetime.strptime(travel["go"]['departure_date'], "%d/%m/%y"), price=travel["go"]['travel_unit_price'], ) for service in travel["go"]["services"]: try: seat = traveller["seats"][service["service_slug"]] except: seat = None Connection.objects.create( ticket=ticket, service=Service.objects.get( slug=service["service_slug"]), from_stop=Stop.objects.get(name=service["stops"][0]), to_stop=Stop.objects.get(name=service["stops"][1]), seat=seat) if "return" in travel and travel["return"]: for traveller in travel["return"]["travellers"]: ticket = Ticket.objects.create( num=id_gen(), order=self.order, traveller_first_name=traveller["first_name"], traveller_last_name=traveller["last_name"], departure_stop=Stop.objects.get( id=travel["return"]["timeslots"][0]["stop_id"]), arrival_stop=Stop.objects.get( id=travel["return"]["timeslots"][-1]["stop_id"]), departure_hour=datetime.strptime( travel["return"]["timeslots"][0]["hour"], "%H:%M").time(), arrival_hour=datetime.strptime( travel["return"]["timeslots"][-1]["hour"], "%H:%M").time(), date=datetime.strptime( travel["return"]['departure_date'], "%d/%m/%y"), price=travel["return"]['travel_unit_price'], ) for service in travel["return"]["services"]: try: seat = traveller["seats"][service["service_slug"]] except: seat = None Connection.objects.create( ticket=ticket, service=Service.objects.get( slug=service["service_slug"]), from_stop=Stop.objects.get( name=service["stops"][0]), to_stop=Stop.objects.get(name=service["stops"][1]), seat=seat) return FormView.form_valid(self, form)
def form_valid(self, form): from os import path csv_file = form.cleaned_data.get("csv_file") df = pandas.read_excel(csv_file) df.dropna(how="all", inplace=True) check_dict = {} session_list = [] check_dict2 = {} session_list2 = [] previous_session = 0 previous_elearning = 0 for i in range(len(df)): try: if df['quiz'][i] in check_dict.keys(): check_dict[df['quiz'][i]] = session_list else: session_list.clear() check_dict.clear() check_dict[df['quiz'][i]] = session_list if df['quiz'][i] in check_dict2.keys(): check_dict2[df['quiz'][i]] = session_list2 else: session_list2.clear() check_dict2.clear() check_dict2[df['quiz'][i]] = session_list2 exam_name = df['quiz'][i] q_category = df['category'][i] q_subcategory = df['sub_category'][i] q_figure = df['figure'][i] slide = q_figure.replace("-", "_") space_slide = slide.replace(" ", "_") #elearning object creating.... if df['session'][i] in check_dict[df['quiz'][i]]: # session already exist elearn = ELearning.objects.get(id=previous_elearning,name=exam_name, exam_type="elearning") else: try: elearn = ELearning.objects.filter(name=exam_name, exam_type="elearning").order_by('-id')[0] except: elearn = ELearning.objects.create(name=exam_name, exam_type="elearning") previous_elearning = elearn.id session_list.append(df['session'][i]) # session_id_list.append() q_text = df['content'][i] q_explanation = df['explanation'][i] correct_answer_text = df['correct'][i] wrong_1 = df['answer1'][i] wrong_2 = df['answer2'][i] wrong_3 = df['answer3'][i] #slides object creating.... slide_path = os.path.join(MEDIA_ROOT, space_slide) if path.exists(slide_path): slide_obj,crt = Slide.objects.get_or_create(elearning=elearn, image=space_slide) #Questions object creating.... if q_text != "n" and correct_answer_text!= "n" and str(q_text)!= "nan" and q_text!= " ": q, crt = Question.objects.get_or_create(exam=elearn, text=q_text) if crt: q.explanation = q_explanation q.text = q_text q.category = q_category q.subcategory = q_subcategory q.save() #Answer object creating.... Answer.objects.get_or_create(question=q, text=correct_answer_text, correct=True) Answer.objects.get_or_create(question=q, text=wrong_1) Answer.objects.get_or_create(question=q, text=wrong_2) Answer.objects.get_or_create(question=q, text=wrong_3) try: slides = Slide.objects.filter(id=slide_obj.id) slides = list(slides) except: print("Skip slide") slides = [] if q_text != "n" and correct_answer_text != "n" and str(q_text) != "nan" and q_text != " ": question = Question.objects.filter(exam=elearn,id=q.id) question = list(question) # elearning object creating.... if df['session'][i] in check_dict2[df['quiz'][i]]: # session already exist elearn_session = ELearningSession.objects.get(id=previous_session,elearning=elearn) else: elearn_session = ELearningSession.objects.filter(elearning=elearn,number=df['session'][i]).order_by("-id") if len(elearn_session) == 0: # complete new_session start elearn_session = ELearningSession.objects.create(elearning=elearn,number=df['session'][i]) else: previous_session = elearn_session[0].id + 1 #new session start here elearn_session,crt = ELearningSession.objects.get_or_create(id=previous_session,elearning=elearn,number=df['session'][i]) elearn_session.save() previous_slides_list = list(elearn_session.slides.all()) previous_slides_list += slides if q_text != "n" and correct_answer_text != "n" and str(q_text) != "nan" and q_text != " ": previous_questions = list(elearn_session.questions.all()) previous_questions += question elearn_session.questions.add(*previous_questions) elearn_session.slides.add(*previous_slides_list) previous_session = elearn_session.id session_list2.append(df['session'][i]) except: print("Skip row") messages.info(self.request, "your elearning data imported successfully.") return FormView.form_valid(self, form)