Commit 7da489e3 authored by Sander Høyland's avatar Sander Høyland
Browse files

PY-2019.3.3 <guffb@DESKTOP-F1O6115 Merge branch 'master'

parents c086f13d aebe02f3
from django import template
from apps.feed.models import Challange
register = template.Library()
@register.filter(name='alignChallange')
def alignChallange(value, pk):
if Challange.objects.filter(pk=pk).first().alignChallange.filter(user=value).first():
return True
from django import template
from apps.feed.models import Event
register = template.Library()
@register.filter(name='get_if_interested')
def get_if_interested(value, pk):
if Event.objects.filter(pk=pk).first().interested.filter(user=value).first():
return True
else:
return False
\ No newline at end of file
from django import template
from apps.feed.models import Post
register = template.Library()
@register.filter(name='get_if_liked')
def get_if_liked(value, pk):
if Post.objects.filter(pk=pk).first().liked.filter(user=value).first():
return True
else:
return False
\ No newline at end of file
from django import template
from apps.feed.models import Event
register = template.Library()
@register.filter(name='get_number_interested')
def get_number_interested(pk):
return Event.objects.filter(pk=pk).first().interested.all().count()
\ No newline at end of file
from django import template
from apps.feed.models import Post
register = template.Library()
@register.filter(name='get_number_likes')
def get_number_likes(pk):
return Post.objects.filter(pk=pk).first().like.all().count()
\ No newline at end of file
from django.shortcuts import render, redirect
from .forms import PostForm, ChallengeForm
from .forms import PostForm, ChallengeForm, EventForm
from django.utils import timezone
from apps.users.models import PrivatePerson, Company
from .models import Post
from .models import Post, Event, Challange
# Create your views here.
......@@ -19,9 +19,7 @@ def postpage(request):
return redirect('startpage')
else:
form = PostForm()
return render(request, 'postpage.html', {
'form': form
})
return render(request, 'postpage.html', {'form': form })
else:
if request.method == 'POST':
......@@ -41,4 +39,35 @@ def postpage(request):
def deletePost(request,pk):
post= Post.objects.filter(pk=pk).first()
post.delete()
return redirect('myprofile', request.user.pk)
\ No newline at end of file
return redirect('myprofile', request.user.pk)
def newevent(request):
if request.method == 'POST':
form = EventForm(request.POST)
form.instance.post_owner = request.user
form.instance.time = timezone.now()
if form.is_valid():
form.save()
return redirect('events')
else:
form = EventForm()
return render(request, 'newevent.html', {'form': form })
def interested(request, pk):
event = Event.objects.filter(pk=pk).first()
event.interested.add(request.user)
return redirect('events')
def like(request, pk):
post = Post.objects.filter(pk=pk).first()
post.like.add(request.user)
return redirect('startpage')
def alignChallange(request,pk):
challange = Challange.objects.filter(pk=pk).first()
privatePerson = PrivatePerson.objects.filter(user=request.user).first()
if privatePerson:
challange.alignChallange.add(privatePerson)
return redirect('challenges')
from django.shortcuts import render
from ..feed.models import Post
from django.contrib.auth.models import User
from apps.feed.models import Challange
from apps.users.models import PrivatePerson
from apps.feed.models import Challange, Event
from apps.users.models import PrivatePerson, Company
......@@ -19,9 +19,10 @@ def myprofile(request,pk):
user = User.objects.filter(pk = pk).first()
if PrivatePerson.objects.filter(user = user).first():
posts = Post.objects.filter(post_owner= user)
challenges = Challange.objects.filter()
else:
posts = Challange.objects.filter(post_owner= user)
return render(request, "myprofile.html",{'knitter':knitter, 'posts': posts})
posts = Challange.objects.filter(post_owner=user)
return render(request, "myprofile.html",{'knitter': knitter, 'posts': posts})
def challenges(request):
challengeposts = Challange.objects.all().order_by('time')
......@@ -30,3 +31,8 @@ def challenges(request):
def editprofile(request):
return render(request, "editprofile.html")
def events(request):
eventposts = Event.objects.all().order_by('time')
user = request.user
return render(request, "event.html",{'eventposts': eventposts, 'user':user})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment