-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from django import forms | ||
from django.contrib.auth.forms import UserCreationForm | ||
from django.contrib.auth.models import User | ||
|
||
from .models import Feedback, Link, Profile, Project | ||
|
||
|
||
class UserRegisterForm(UserCreationForm): | ||
email = forms.EmailField() | ||
# Add any additional fields for the profile here, if needed | ||
|
||
class Meta: | ||
model = User | ||
fields = ['username', 'email', 'password1', 'password2'] | ||
|
||
|
||
class UserUpdateForm(forms.ModelForm): | ||
email = forms.EmailField() | ||
|
||
class Meta: | ||
model = User | ||
fields = ['username', 'email'] | ||
|
||
|
||
class ProfileUpdateForm(forms.ModelForm): | ||
# Add fields for updating profile-specific information | ||
class Meta: | ||
model = Profile | ||
fields = [] # Specify the fields you want to include, e.g., [] | ||
|
||
|
||
class ProjectForm(forms.ModelForm): | ||
class Meta: | ||
model = Project | ||
fields = [ | ||
'name', | ||
'supervisors', | ||
] # Adjust according to your Project model fields | ||
|
||
|
||
class LinkForm(forms.ModelForm): | ||
class Meta: | ||
model = Link | ||
fields = [ | ||
'person_one', | ||
'person_two', | ||
'supervisor', | ||
'periodicity', | ||
'times', | ||
] | ||
widgets = { | ||
'person_one': forms.Select(attrs={'class': 'form-control'}), | ||
'person_two': forms.Select(attrs={'class': 'form-control'}), | ||
'supervisor': forms.Select(attrs={'class': 'form-control'}), | ||
'periodicity': forms.Select( | ||
choices=Link.PERIODICITY_CHOICES, | ||
attrs={'class': 'form-control'}, | ||
), | ||
'times': forms.NumberInput(attrs={'class': 'form-control'}), | ||
} | ||
|
||
|
||
class FeedbackForm(forms.ModelForm): | ||
class Meta: | ||
model = Feedback | ||
fields = ['content', 'link'] | ||
widgets = { | ||
'content': forms.Textarea( | ||
attrs={'class': 'form-control', 'rows': 3} | ||
), | ||
'link': forms.Select(attrs={'class': 'form-control'}), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from django.contrib.auth.models import User | ||
from django.db import models | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
|
||
class Profile(models.Model): | ||
user = models.OneToOneField(User, on_delete=models.CASCADE) | ||
projects = models.ManyToManyField('Project', related_name='participants') | ||
# Add any additional fields for your Person model here | ||
|
||
def __str__(self): | ||
return self.user.username | ||
|
||
|
||
class Project(models.Model): | ||
name = models.CharField(max_length=100) | ||
# Assuming you want to keep a relation to track project supervisors | ||
supervisors = models.ManyToManyField( | ||
User, related_name='supervised_projects' | ||
) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
class Link(models.Model): | ||
person_one = models.ForeignKey( | ||
User, on_delete=models.CASCADE, related_name='person_one_links' | ||
) | ||
person_two = models.ForeignKey( | ||
User, on_delete=models.CASCADE, related_name='person_two_links' | ||
) | ||
supervisor = models.ForeignKey( | ||
User, on_delete=models.CASCADE, related_name='supervised_links' | ||
) | ||
periodicity = models.CharField(max_length=50) | ||
times = models.IntegerField() | ||
|
||
def __str__(self): | ||
return f'{self.person_one.username} <-> {self.person_two.username}' | ||
|
||
|
||
class Feedback(models.Model): | ||
content = models.TextField() | ||
link = models.ForeignKey( | ||
Link, on_delete=models.CASCADE, related_name='feedback' | ||
) | ||
timestamp = models.DateTimeField(auto_now_add=True) | ||
|
||
def __str__(self): | ||
return ( | ||
f'Feedback from {self.link.person_one.username} to ' | ||
f'{self.link.person_two.username} on ' | ||
f'{self.timestamp.strftime("%Y-%m-%d %H:%M:%S")}' | ||
) | ||
|
||
|
||
@receiver(post_save, sender=User) | ||
def create_user_profile(sender, instance, created, **kwargs): | ||
if created: | ||
Profile.objects.create(user=instance) | ||
|
||
|
||
@receiver(post_save, sender=User) | ||
def save_user_profile(sender, instance, **kwargs): | ||
instance.profile.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
path('register/', views.user_register, name='register'), | ||
path('projects/', views.project_list, name='project_list'), | ||
path('project/create/', views.project_create, name='project_create'), | ||
path('link/create/', views.link_create, name='link_create'), | ||
path('feedback/create/', views.feedback_create, name='feedback_create'), | ||
# Add other paths as needed | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from django.contrib.auth.decorators import login_required | ||
from django.shortcuts import redirect, render | ||
|
||
from .forms import FeedbackForm, LinkForm, ProjectForm, UserRegistrationForm | ||
from .models import Project | ||
|
||
|
||
def user_register(request): | ||
if request.method == 'POST': | ||
user_form = UserRegistrationForm(request.POST) | ||
if user_form.is_valid(): | ||
# Create a new user object but avoid saving it yet | ||
new_user = user_form.save(commit=False) | ||
# Set the chosen password | ||
new_user.set_password(user_form.cleaned_data['password']) | ||
# Save the User object | ||
new_user.save() | ||
return render( | ||
request, | ||
'registration/register_done.html', | ||
{'new_user': new_user}, | ||
) | ||
else: | ||
user_form = UserRegistrationForm() | ||
return render( | ||
request, 'registration/register.html', {'user_form': user_form} | ||
) | ||
|
||
|
||
@login_required | ||
def project_list(request): | ||
projects = Project.objects.all() | ||
return render(request, 'project/list.html', {'projects': projects}) | ||
|
||
|
||
@login_required | ||
def project_create(request): | ||
if request.method == 'POST': | ||
form = ProjectForm(request.POST) | ||
if form.is_valid(): | ||
form.save() | ||
return redirect('project_list') | ||
else: | ||
form = ProjectForm() | ||
return render(request, 'project/create.html', {'form': form}) | ||
|
||
|
||
# Define similar views for Link and Feedback | ||
|
||
|
||
@login_required | ||
def link_create(request): | ||
if request.method == 'POST': | ||
form = LinkForm(request.POST) | ||
if form.is_valid(): | ||
form.save() | ||
return redirect('link_list') | ||
else: | ||
form = LinkForm() | ||
return render(request, 'link/create.html', {'form': form}) | ||
|
||
|
||
@login_required | ||
def feedback_create(request): | ||
if request.method == 'POST': | ||
form = FeedbackForm(request.POST) | ||
if form.is_valid(): | ||
form.save() | ||
return redirect('feedback_list') | ||
else: | ||
form = FeedbackForm() | ||
return render(request, 'feedback/create.html', {'form': form}) | ||
|
||
|
||
# Add views for listing Links and Feedbacks, and any other operations you need |