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
......@@ -3,3 +3,9 @@ from django.apps import AppConfig
class UsersConfig(AppConfig):
name = 'apps.users'
class ProfilesConfig(AppConfig):
name = 'profiles'
......@@ -3,7 +3,6 @@ from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import PrivatePerson, Company
class UserRegisterForm(UserCreationForm):
email = forms.EmailField()
......@@ -13,11 +12,17 @@ class UserRegisterForm(UserCreationForm):
class EditPrivateProfile(UserChangeForm):
name = forms.CharField(required=False,widget=forms.Textarea(attrs={'rows':1,'cols':40}))
about = forms.CharField(required=False,widget=forms.Textarea(attrs={'rows':5,'cols':40}))
class Meta:
model= PrivatePerson
fields= ('name','profilePicture','about')
fields = ('name', 'profilePicture','about')
class EditCompanyProfile(UserChangeForm):
name = forms.CharField(required=False, widget=forms.Textarea(attrs={'rows': 1, 'cols': 40}))
about = forms.CharField(required=False, widget=forms.Textarea(attrs={'rows': 5, 'cols': 40}))
class Meta:
model = Company
fields = ('name','profilePicture','about')
# Generated by Django 3.0.3 on 2020-02-23 19:51
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0011_update_proxy_permissions'),
]
operations = [
migrations.CreateModel(
name='Knitter',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('about', models.CharField(blank=True, max_length=300, null=True)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
# Generated by Django 3.0.3 on 2020-02-23 20:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='knitter',
name='profilepicture',
field=models.ImageField(null=True, upload_to=''),
),
]
# Generated by Django 3.0.3 on 2020-02-24 19:11
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('users', '0002_knitter_profilepicture'),
]
operations = [
migrations.DeleteModel(
name='Knitter',
),
]
# Generated by Django 3.0.3 on 2020-02-27 10:46
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('users', '0003_delete_knitter'),
]
operations = [
migrations.CreateModel(
name='PrivatePerson',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('profilePicture', models.ImageField(blank=True, null=True, upload_to='')),
('about', models.TextField(blank=True, max_length=400, null=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Company',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('profilePicture', models.ImageField(blank=True, null=True, upload_to='')),
('about', models.TextField(blank=True, max_length=400, null=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
# Generated by Django 3.0.3 on 2020-03-02 11:53
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0004_company_privateperson'),
]
operations = [
migrations.CreateModel(
name='editCompanyProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField(blank=True, max_length=40, null=True)),
('profilePicture', models.ImageField(blank=True, null=True, upload_to='')),
('about', models.TextField(blank=True, max_length=400, null=True)),
],
),
migrations.CreateModel(
name='editPersonProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.TextField(blank=True, max_length=20, null=True)),
('last_name', models.TextField(blank=True, max_length=20, null=True)),
('profilePicture', models.ImageField(null=True, upload_to='')),
('about', models.TextField(blank=True, max_length=400, null=True)),
],
),
migrations.AddField(
model_name='company',
name='name',
field=models.TextField(blank=True, max_length=40, null=True),
),
migrations.AddField(
model_name='privateperson',
name='first_name',
field=models.TextField(blank=True, max_length=20, null=True),
),
migrations.AddField(
model_name='privateperson',
name='last_name',
field=models.TextField(blank=True, max_length=20, null=True),
),
]
# Generated by Django 3.0.3 on 2020-03-02 12:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0005_auto_20200302_1253'),
]
operations = [
migrations.CreateModel(
name='editProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField(blank=True, max_length=20, null=True)),
('profilePicture', models.ImageField(null=True, upload_to='')),
('about', models.TextField(blank=True, max_length=400, null=True)),
],
),
migrations.DeleteModel(
name='editCompanyProfile',
),
migrations.DeleteModel(
name='editPersonProfile',
),
migrations.RemoveField(
model_name='privateperson',
name='first_name',
),
migrations.RemoveField(
model_name='privateperson',
name='last_name',
),
migrations.AddField(
model_name='privateperson',
name='name',
field=models.TextField(blank=True, max_length=30, null=True),
),
migrations.AlterField(
model_name='company',
name='name',
field=models.TextField(blank=True, max_length=30, null=True),
),
]
# Generated by Django 3.0.3 on 2020-03-02 21:11
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('users', '0006_auto_20200302_1358'),
]
operations = [
migrations.DeleteModel(
name='editProfile',
),
]
# Generated by Django 3.0.3 on 2020-03-03 15:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0007_delete_editprofile'),
]
operations = [
migrations.AlterField(
model_name='company',
name='about',
field=models.TextField(blank=True, max_length=400, null=True, verbose_name='Skriv litt om bedriften'),
),
migrations.AlterField(
model_name='company',
name='name',
field=models.TextField(blank=True, max_length=30, null=True, verbose_name='Navn'),
),
migrations.AlterField(
model_name='company',
name='profilePicture',
field=models.ImageField(blank=True, null=True, upload_to='', verbose_name='Logo'),
),
migrations.AlterField(
model_name='privateperson',
name='about',
field=models.TextField(blank=True, max_length=400, null=True, verbose_name='Skriv litt om deg selv'),
),
migrations.AlterField(
model_name='privateperson',
name='name',
field=models.TextField(blank=True, max_length=30, null=True, verbose_name='Navn'),
),
migrations.AlterField(
model_name='privateperson',
name='profilePicture',
field=models.ImageField(blank=True, null=True, upload_to='', verbose_name='Profilbilde'),
),
]
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
# User= settings.AUTH_USER_MODEL
from django.http import request
class PrivatePerson(models.Model):
user = models.ForeignKey(User, on_delete= models.CASCADE, null= False)
name = models.TextField(null=True, blank=True, max_length=30, verbose_name='Navn')
profilePicture = models.ImageField(null=True, blank=True, verbose_name='Profilbilde')
about = models.TextField(null=True, blank=True, max_length=400, verbose_name='Skriv litt om deg selv')
name = models.TextField(null=True, blank=True, max_length=30)
profilePicture = models.ImageField(upload_to='static.img/', null=True, blank=True)
about = models.TextField(null=True, blank=True, max_length=400)
class Company(models.Model):
user = models.ForeignKey(User, on_delete= models.CASCADE, null=False)
name = models.TextField(null=True, blank=True, max_length=30, verbose_name='Navn')
profilePicture = models.ImageField(null=True, blank=True, verbose_name='Logo')
about = models.TextField(null=True, blank=True, max_length=400, verbose_name='Skriv litt om bedriften')
name = models.TextField(null=True, blank=True, max_length=30)
profilePicture = models.ImageField(upload_to='static.img/', null=True, blank=True)
about = models.TextField(null=True, blank=True, max_length=400)
from django.shortcuts import render, redirect
from django.contrib import messages
from .forms import UserRegisterForm, EditPrivateProfile, EditCompanyProfile
from django.contrib.auth import logout as django_logout
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
from .forms import UserRegisterForm
from django.contrib.auth import logout as django_logout, get_user_model
from .models import PrivatePerson, Company
from django.db.models import Q
from django.shortcuts import render, get_object_or_404, redirect
from ..staticpages.views import myprofile
from .forms import UserRegisterForm, EditPrivateProfile, EditCompanyProfile
from django.contrib.auth.models import User
from django.urls import reverse
from django.contrib.auth.forms import UserChangeForm
from apps.feed.models import Post
from apps.feed.models import Post, Challange
User = get_user_model()
USERS_PER_PAGE = 10
def logout(request):
django_logout(request)
......@@ -14,19 +23,17 @@ def logout(request):
def register(request):
print(request)
print("hoola")
if request.method == 'POST':
form = UserRegisterForm(request.POST)
is_company = request.POST.get('company')
if form.is_valid():
username = form.cleaned_data.get('username')
messages.success(request, f'Account created for {username}!')
user = form.save()
usero = form.save()
if(is_company):
company = Company.objects.create(user=user)
company = Company.objects.create(user=usero)
else:
privateperson = PrivatePerson.objects.create(user=user)
privateperson = PrivatePerson.objects.create(user=usero)
return redirect('login')
else:
form = UserRegisterForm()
......@@ -36,6 +43,35 @@ def register(request):
def redirect_to_index(request):
return redirect('startpage')
def search_users(request):
context = {}
query = ""
if 'q' in request.GET:
query = request.GET['q']
context['query'] = str(query)
users = get_blog_queryset(query)
page = request.GET.get('page', 1)
blog_posts_paginator = Paginator(users, USERS_PER_PAGE)
try:
users = blog_posts_paginator.page(page)
except PageNotAnInteger:
users = blog_posts_paginator.page(USERS_PER_PAGE)
except EmptyPage:
users = blog_posts_paginator.page(blog_posts_paginator.num_pages)
context = {'users': users}
return render(request, 'search_list.html', context)
def get_blog_queryset(query=None):
queryset = []
queries = query.split(" ")
for q in queries:
users = User.objects.filter(username__contains=q)
for user in users:
queryset.append(user)
return list(set(queryset))
def view_profile(request,pk=None):
if pk:
......@@ -44,31 +80,40 @@ def view_profile(request,pk=None):
user = request.user
posts = Post.objects.filter(post_owner= user)
is_privateperson = False
challenges = []
if PrivatePerson.objects.filter(user=user).first():
profile = PrivatePerson.objects.filter(user=user).first()
is_privateperson = True
challenges = Challange.objects.filter(alignChallange__id__exact=profile.id)
return render(request, 'myprofile.html',{'profile':profile,'posts':posts, 'is_privatperson': is_privateperson, 'challenges':challenges})
else:
profile = Company.objects.filter(user=user).first()
return render(request, 'myprofile.html',{'profile':profile,'posts':posts})
return render(request, 'companyprofile.html',{'profile':profile,'posts':posts, 'challenges':challenges})
def editprofile(request):
if PrivatePerson.objects.filter(user=request.user).first():
if request.method == 'POST':
privateperson = PrivatePerson.objects.filter(user = request.user).first()
form = EditPrivateProfile(request.POST, instance=privateperson)
form = EditPrivateProfile(request.POST, request.FILES, instance=privateperson)
if form.is_valid():
form.save()
return redirect('myprofile', request.user.pk)
else:
form = EditPrivateProfile(instance=request.user)
return render(request, 'editprofile.html', {'form': form})
privateperson = PrivatePerson.objects.filter(user=request.user).first()
form = EditPrivateProfile(instance=privateperson)
is_privateperson = True
return render(request, 'editprofile.html', {'form': form, 'is_privateperson':is_privateperson})
else:
if request.method == 'POST':
company = Company.objects.filter(user = request.user).first()
form = EditCompanyProfile(request.POST, instance= company)
form = EditCompanyProfile(request.POST, request.FILES, instance= company)
if form.is_valid():
form.save()
return redirect('myprofile', request.user.pk)
else:
form = EditCompanyProfile(instance=request.user)
return render(request, 'editprofile.html', {'form': form})
company = Company.objects.filter(user=request.user).first()
form = EditCompanyProfile(instance= company)
is_privateperson = False
return render(request, 'editprofile.html', {'form': form, 'is_privateperson':is_privateperson})
......@@ -42,7 +42,7 @@ INSTALLED_APPS = [
'apps.staticpages',
'apps.feed',
'apps.users.apps.UsersConfig',
'crispy_forms',
'crispy_forms'
]
MIDDLEWARE = [
......@@ -84,12 +84,16 @@ WSGI_APPLICATION = 'rodTraa.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.mysql',
'NAME': 'sandereh_PU_prosjektdatabase',
'USER': 'sandereh_demo',
'PASSWORD': 'password',
'HOST': 'mysql.stud.ntnu.no',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
......@@ -137,3 +141,9 @@ STATICFILES_DIRS = [
MEDIA_ROOT = 'uploads/'
MEDIA_URL = '/uploads/'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'rodtraa.58@gmail.com'
EMAIL_HOST_PASSWORD = 'Gruppe58'
\ No newline at end of file
......@@ -13,6 +13,7 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('startpage/', include('startpage.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
......@@ -20,9 +21,11 @@ from django.conf.urls.static import static
from . import settings
from apps.staticpages.views import index, startpage, myprofile
from apps.users import views as user_views
from apps.staticpages.views import challenges
from apps.feed.views import postpage, deletePost
from apps.staticpages.views import challenges, events
from apps.feed.views import postpage, deletePost, newevent, interested, like, alignChallange
from apps.users.views import editprofile
from django.contrib.auth import views as auth_views
urlpatterns = [
path('admin/', admin.site.urls),
......@@ -30,13 +33,29 @@ urlpatterns = [
path('', index, name='index'),
path('startpage/', startpage, name='startpage'),
path('myprofile/<int:pk>/', user_views.view_profile, name='myprofile'),
path('companyprofile/<int:pk>/', user_views.view_profile, name='companyprofile'),
path('accounts/', include('django.contrib.auth.urls'), name="login"),
path('accounts/profile/', user_views.redirect_to_index, name="profile"),
path('logout/', user_views.logout, name="logout"),
path('challenges/', challenges, name="challenges"),
path('list/', user_views.search_users, name="search_results"),
path('postpage/', postpage, name= "postpage"),
path('editprofile/', editprofile, name = "editprofile"),
path('deletePost/<int:pk>', deletePost, name = "deletepost")
path('deletePost/<int:pk>', deletePost, name = "deletepost"),
path('events/', events, name="events"),
path('newevent/', newevent, name="newevent"),
path('interested/<int:pk>/', interested, name="interested"),
path('like/<int:pk>/', like, name="like"),
path('alignChallange/<int:pk>/', alignChallange, name="alignChallange"),
path('password-reset/',
auth_views.PasswordResetView.as_view(template_name='password_reset.html'),
name="password_reset"),
path('password-reset/done/',
auth_views.PasswordResetDoneView.as_view(template_name='password_reset_done.html'),
name="password_reset_done"),
path('password-reset-confirm/<uidb64>/<token>/',
auth_views.PasswordResetConfirmView.as_view(template_name='password_reset_confirm.html'),
name="password_reset_confirm"),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
.navbar-nav > li{
padding-left:30px;
padding-right:30px;