Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions proud-puffins/djangoProject/earlydating/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ class EarlydatingConfig(AppConfig):
name = 'earlydating'

def ready(self):
# Import is necessary for signals to work despite lint errors
import earlydating.signals
8 changes: 5 additions & 3 deletions proud-puffins/djangoProject/earlydating/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
from django.shortcuts import redirect


# To avoid double login/register if you are logged in
def unauthenticated_user(view_func):
"""To avoid logging in/registering again if the user logged in"""
@wraps(view_func)
def wrapper_func(request, *args, **kwargs):
# Redirect to their profile if authenticated
if request.user.is_authenticated:
return redirect('earlydating-yourprofile')
# Else authenticate user
else:
return view_func(request, *args, **kwargs)
return wrapper_func


# Restricting page access to specified user groups
def allowed_users(allowed_roles=[]):
"""Restricting page access to specified user groups"""
def decorator(view_func):
@wraps(view_func)
def wrapper_func(request, *args, **kwargs):
Expand All @@ -30,8 +32,8 @@ def wrapper_func(request, *args, **kwargs):
return decorator


# Restrict page access to other groups
def admin_only(view_func):
"""Restrict page access to only admins"""
@wraps(view_func)
def wrapper_function(request, *args, **kwargs):
group = None
Expand Down
10,400 changes: 4,800 additions & 5,600 deletions proud-puffins/djangoProject/earlydating/fixtures/profiles.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions proud-puffins/djangoProject/earlydating/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@


class CreateUserForm(UserCreationForm):
"""Registration/Sign-up Form"""
class Meta:
model = User
fields = ['username', 'first_name', 'last_name', 'email', 'password1', 'password2']


class UserUpdateForm(forms.ModelForm):
"""Form for editing information in User table fields"""
first_name = forms.CharField()
last_name = forms.CharField()
email = forms.EmailField()
Expand All @@ -21,6 +23,7 @@ class Meta:


class ProfileUpdateForm(forms.ModelForm):
"""Form for editing information in Profile table fields"""
class Meta:
model = Profile
fields = ['age', 'bio', 'img', 'sex', 'preference']
44 changes: 0 additions & 44 deletions proud-puffins/djangoProject/earlydating/migrations/0001_initial.py

This file was deleted.

11 changes: 9 additions & 2 deletions proud-puffins/djangoProject/earlydating/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


# Create your models here.

# Make email field necessary while signing up
User._meta.get_field('email')._unique = True
User._meta.get_field('email').blank = False
User._meta.get_field('email').null = False
Expand All @@ -20,13 +22,12 @@ class Profile(models.Model):
sex = models.CharField(max_length=10, null=True, blank=True, choices=Gender_Choices)
preference = models.CharField(max_length=10, null=True, blank=True, choices=Pref_Choices)
bio = models.TextField(default="")
upper_age = models.PositiveSmallIntegerField(null=True)
lower_age = models.PositiveSmallIntegerField(null=True)

def __str__(self):
return str(self.user)

def save(self, *args, **kwargs):
"""Saves imgloc whenever user updates their profile pic."""
if 'user_pixel' in self.img.path:
pass
else:
Expand All @@ -36,6 +37,12 @@ def save(self, *args, **kwargs):


class UserVote(models.Model):
"""Table that stores the votes/likes

user -> profile that is being voted
voter -> profile that votes
vote -> boolean field with default as False
"""
user = models.ForeignKey(User, on_delete=models.CASCADE)
voter = models.ForeignKey(User, related_name='given_vote', on_delete=models.CASCADE)
vote = models.BooleanField(default=False)
Expand Down
2 changes: 2 additions & 0 deletions proud-puffins/djangoProject/earlydating/puffin_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


def imageTrans(image):
"""Reduces image quality by resizing back and forth"""
try:
_, file_extension = os.path.splitext(image.name)
file_extension = file_extension.split(".")[-1]
Expand All @@ -31,6 +32,7 @@ def imageTrans(image):


def validate_file_size(value):
"""Raise error if file size exceed 10MB"""
filesize = value.size

if filesize > 10485760:
Expand Down
4 changes: 3 additions & 1 deletion proud-puffins/djangoProject/earlydating/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
from .models import Profile


# Listen to Users table and crete a new profile whenever new user is created
def create_profile(sender, instance, created, **kwargs):
"""Listen to Users table and create a new profile whenever a user is created"""
# If the user is created and not by loading a fixture
if created and not kwargs.get('raw', False):
try:
group = Group.objects.get(name='profile')
except Group.DoesNotExist:
group = Group.objects.create(name='profile')
# Add user to profile group and create profile object
instance.groups.add(group)
Profile.objects.create(user=instance)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ <h1 style="font-size:x-large">You Both Liked Eachother</h1>

{% for item in both_liked %}
<div class="grid-container">
<h3 style="font-weight: bold; font-size: large;"><a href="{% url 'earlydating-profile' item.user.id %}">{{ item.user.username }}</a></h3><br>
<img src="/media/{{ item.user.profile.img }}" height="250"><br>
<h2>{{item.user.profile.bio }}</h2>
<h3 style="font-weight: bold; font-size: large;"><a href="{% url 'earlydating-profile' item.pk %}">{{ item.username }}</a></h3><br>
<img src="/media/{{ item.profile.img }}" height="250"><br>
<h2>{{item.profile.bio }}</h2><br>
<h1> Chat With Me! {{item.email}}</h1>
</div>
{% endfor %}

<br><br><br>
{% empty %}
<img src="../static/images/puffin_none.gif"><br>
<h1>Keep fishing, plenty of fish in the sea.</h1>


{% endfor %}



{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ <h1>Your Likes</h1>
<p style="text-align: center;"><br>
<img src="/media/{{ item.user.profile.img }}" height="75px"; ><br>
<h1 >{{item.user.profile.bio}}</h1>
<h1 style="margin-top: 20px"> Chat With Me! {{item.user.email}}</h1>

</td>

Expand Down
Loading