def register(request): context = {} #import ipdb; ipdb.set_trace() if request.method == 'POST': try: name = request.POST.get("username") email = request.POST.get("email") password1 = request.POST.get("password1") password2 = request.POST.get("password2") if password2 == password1: user = User.objects.create_user(username=name, password=password1, email=email) user_info = UserProfile(user=user, name=name, email=email) user_info.save() user_profile_info = UserProfileInfo(userlink=user_info) user_profile_info.save() user_followers_info = Followers(user=user_info) user_followers_info.save() user_comment_info = Comment(user=user_profile_info) user_comment_info.save() user_cat_info = CategoryFollowers(user=user_info) user_cat_info.save() user_like_info = CardLikes(user=user_info) user_like_info.save() user__jour_info = Journal(user=user_info) user__jour_info.save() name = request.POST.get("username") password = request.POST.get("password1") user = auth.authenticate(username=name, password=password) if request.user.is_authenticated(): context = {"status": "One user already logged in"} context['user'] = request.user.username context.update(csrf(request)) return render_to_response("login.html", context) else: if user is not None: if user.is_active: auth.login(request, user) context = { 'success': True, 'message': 'User Profile Created Successfully. Please tell us something about yourself.' } context.update(csrf(request)) return HttpResponseRedirect("/users/userdetailsentry/%s/" % request.user) except: context = { 'success': False, 'message': "user Profile can't be saved. please SignUp again" } context.update(csrf(request)) return render_to_response("login.html", context) context.update(csrf(request)) return render_to_response('login.html', context)
def setUp(self) -> None: super(TestJournalFilter, self).setUp() jr = Journal(student=self.students[0], program=self.programs[0], value=self.value) jr.save()
def checkin(request): """ Returns a view that renders the checkin page and form """ if request.method == 'POST': # Check if journal entry exists journal = Journal.objects.filter(entry_date=timezone.now().date(), user_id=request.user.id) if not journal: journal = Journal(entry_date=timezone.now().date(), user_id=request.user, checkin_status=1) journal.save() journal = Journal.objects.filter(entry_date=timezone.now().date(), user_id=request.user.id) # !! Code needed to set checkin_status=1 if journal exists !! form = CheckinForm(request.POST) if form.is_valid(): obj = form.save(commit=False) obj.journal_id = journal[0] obj.save() # messages.success(request, 'Check-in complete nice work!') return redirect('accounts:profile') else: # Add instance for edit checkin form = CheckinForm() context = { 'title': 'Profile', 'form': form, # 'subscribe_form': subscribe_form, } return render(request, 'checkin.html', context)
def test_not_valid_program(self): try: j = Journal(student=self.students[0], program=self.programs[1], value=self.value) j.save() except ValidationError: self.assert_(True) else: self.assert_(False)
def test_valid_record(self): try: j = Journal(student=self.students[0], program=self.programs[0], value=self.value) j.save() except Exception as ex: self.assert_(False, ex) else: self.assert_(True)
def create(self, validated_data): """ Create a new journal. """ name = validated_data.get('name') date = validated_data.get('date') user = User.objects.get(email=validated_data.get('user')) journal = Journal(name=name, date=date, user=user) journal.save() return journal
def make_test_journal(**kwargs): try: update_xsl_files() journal = Journal(**kwargs) journal.save() update_settings(journal, management_command=False) except IntegrityError: pass return journal
def test_changes_kid_state(self): kid = Kid(photo='nfjngsdlkfngds', name='vasya', birthday=datetime(2010, 1, 1).date(), grade=1) kid.save() journal = Journal(kid=kid, timestamp=timezone.now(), direction='IN', relative='M') journal.save() assert kid.is_studying
def setUp(self): self.student = User.objects.create_student( email=user.email, password=user.password, first_name=user.first_name, second_name=user.second_name, last_name=user.last_name) self.teacher = User.objects.create_teacher( email=teacher.email, password=teacher.password, first_name=teacher.first_name, second_name=teacher.second_name, last_name=teacher.last_name) self.program = Program(name=program.name) self.program.save() self.journal = Journal(student=self.student, program=self.program, value=3) self.journal.save() token, created = Token.objects.get_or_create(user=self.teacher) self.http_authorization = 'Token {}'.format(token)
def save_profile(backend, response, user=None, *args, **kwargs): import ipdb ipdb.set_trace() if backend.name == 'facebook': if not UserProfile.objects.filter(user=user).exists(): profile = User.objects.get(username=user) email = response.get('email') uname = str(profile) user_info = UserProfile(user=profile, name=uname, email=email) user_info.save() user_profile_info = UserProfileInfo(userlink=user_info) user_profile_info.save() user_followers_info = Followers(user=user_info) user_followers_info.save() user_comment_info = Comment(user=user_profile_info) user_comment_info.save() user_cat_info = CategoryFollowers(user=user_info) user_cat_info.save() user_like_info = CardLikes(user=user_info) user_like_info.save() user__jour_info = Journal(user=user_info) user__jour_info.save() elif backend.name == "google-oauth2": if not UserProfile.objects.filter(user=user).exists(): profile = User.objects.get(username=user) email = response.get('emails') email = email[0].get('value') uname = str(profile) user_info = UserProfile(user=profile, name=uname, email=email) user_info.save() user_profile_info = UserProfileInfo(userlink=user_info) user_profile_info.save() user_followers_info = Followers(user=user_info) user_followers_info.save() user_comment_info = Comment(user=user_profile_info) user_comment_info.save() user_cat_info = CategoryFollowers(user=user_info) user_cat_info.save() user_like_info = CardLikes(user=user_info) user_like_info.save() user__jour_info = Journal(user=user_info) user__jour_info.save()
def addentry(request): page_data = {"add_journal_form": add_journal} if request.method == 'POST': add_journal_form = add_journal(request.POST) if (add_journal_form.is_valid()): desc = add_journal_form.cleaned_data["Description"] ent = add_journal_form.cleaned_data["Entry"] journal = Journal() journal.Username = request.user journal.Description = desc journal.Entry = ent journal.save() page_data = fillpagedata(request.user) return render(request, 'journal/journal.html', {"dat": page_data}) return render(request, 'journal/addentry.html', context=page_data)
class TestJournalViews(APITestCase): """Test Authorization views""" def setUp(self): self.student = User.objects.create_student( email=user.email, password=user.password, first_name=user.first_name, second_name=user.second_name, last_name=user.last_name) self.teacher = User.objects.create_teacher( email=teacher.email, password=teacher.password, first_name=teacher.first_name, second_name=teacher.second_name, last_name=teacher.last_name) self.program = Program(name=program.name) self.program.save() self.journal = Journal(student=self.student, program=self.program, value=3) self.journal.save() token, created = Token.objects.get_or_create(user=self.teacher) self.http_authorization = 'Token {}'.format(token) def test_create_program(self): test = {'name': program2.name} url = reverse('api:journal:list-create-program') response = self.client.post(url, data=test, HTTP_AUTHORIZATION=self.http_authorization) self.assertEqual(response.status_code, status.HTTP_201_CREATED) def test_list_program(self): url = reverse('api:journal:list-create-program') response = self.client.get(url, HTTP_AUTHORIZATION=self.http_authorization) self.assertEqual(response.status_code, status.HTTP_200_OK) def test_update_program(self): test = {'name': 'Updated name'} url = reverse('api:journal:retrieve-update-program', args=[self.program.id]) response = self.client.patch( url, data=test, HTTP_AUTHORIZATION=self.http_authorization) self.assertEqual(response.status_code, status.HTTP_200_OK) def test_retrieve_program(self): url = reverse('api:journal:retrieve-update-program', args=[self.program.id]) response = self.client.get(url, HTTP_AUTHORIZATION=self.http_authorization) self.assertEqual(response.status_code, status.HTTP_200_OK) def test_create_journal(self): test = { 'student': self.student.id, 'program': self.program.id, 'value': 2 } url = reverse('api:journal:list-create-journal') response = self.client.post(url, data=test, HTTP_AUTHORIZATION=self.http_authorization) self.assertEqual(response.status_code, status.HTTP_201_CREATED) def test_list_journal(self): url = reverse('api:journal:list-create-journal') response = self.client.get(url, HTTP_AUTHORIZATION=self.http_authorization) self.assertEqual(response.status_code, status.HTTP_200_OK) def test_update_journal(self): test = {'value': 4} url = reverse('api:journal:retrieve-update-journal', args=[self.journal.id]) response = self.client.patch( url, data=test, HTTP_AUTHORIZATION=self.http_authorization) self.assertEqual(response.status_code, status.HTTP_200_OK) def test_retrieve_journal(self): url = reverse('api:journal:retrieve-update-journal', args=[self.journal.id]) response = self.client.get(url, HTTP_AUTHORIZATION=self.http_authorization) self.assertEqual(response.status_code, status.HTTP_200_OK)