def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if not form.is_valid(): return render(request, 'member/signup.html', {'form': form}) else: username = form.cleaned_data.get('username') email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') User.objects.create_user(username=username, password=password, email=email) user = authenticate(username=username, password=password) login(request, user) try: profile = user.profile except Profile.DoesNotExist: profile = Profile(user=user) profile.save() user.save() welcome_post = u'{0} has joined the network.'.format(user.username) feed = Feed(user=user, post=welcome_post) feed.save() return redirect('/') else: return render(request, 'member/signup.html', {'form': SignUpForm()})
def profile(request, username): user = request.user page_user = get_object_or_404(User, username=username) all_feeds = Feed.get_feeds().filter(user=page_user) paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id print user, page_user return render(request, 'member/profile.html', { 'page_user': page_user, 'user': user, 'feeds': feeds, 'from_feed': from_feed, 'page': 1 })
def profile(request, username): user = request.user page_user = get_object_or_404(User, username=username) all_feeds = Feed.get_feeds().filter(user=page_user) paginator = Paginator(all_feeds, FEEDS_NUM_PAGES) feeds = paginator.page(1) from_feed = -1 if feeds: from_feed = feeds[0].id print user, page_user return render( request, 'member/profile.html', { 'page_user': page_user, 'user': user, 'feeds': feeds, 'from_feed': from_feed, 'page': 1 })
def home(request): """ Home page view """ users = len(User.objects.filter(is_active=True)) articles = len(Article.objects.all()) feeds_no = len(Feed.get_feeds()) events_upcoming = 10 events_old = 100 today = timezone.now() past = today + datetime.timedelta(days=-30) print past, today posts = Feed.objects.filter(date__range=[past, today])[:4]#.order_by('-likes')[:4] print 'psots', posts return render(request, 'home.html', { 'users_no':users, 'articles_no':articles, 'feeds_no':feeds_no, 'events_up':events_upcoming, 'events_old':events_old, 'posts': posts, })
def home(request): """ Home page view """ users = len(User.objects.filter(is_active=True)) articles = len(Article.objects.all()) feeds_no = len(Feed.get_feeds()) events_upcoming = 10 events_old = 100 today = timezone.now() past = today + datetime.timedelta(days=-30) print past, today posts = Feed.objects.filter( date__range=[past, today])[:4] #.order_by('-likes')[:4] print 'psots', posts return render( request, 'home.html', { 'users_no': users, 'articles_no': articles, 'feeds_no': feeds_no, 'events_up': events_upcoming, 'events_old': events_old, 'posts': posts, })