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
2 changes: 1 addition & 1 deletion accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CustomUserAdmin(BaseUserAdmin):
'username', 'first_name', 'last_name',
'full_name', 'slack_display_name',
'current_lms_module', 'organisation',
'user_type', 'is_external')}),
'timezone', 'user_type', 'is_external')}),
('Permissions', {'fields': (
'is_active', 'is_staff', 'is_superuser',
'profile_is_public', 'email_is_public',
Expand Down
14 changes: 12 additions & 2 deletions accounts/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms
from django.contrib.auth import get_user_model

from .lists import LMS_MODULES_CHOICES
from .lists import LMS_MODULES_CHOICES, TIMEZONE_CHOICES
from .models import CustomUser


Expand All @@ -23,11 +23,15 @@ class SignupForm(forms.Form):
widget=forms.Select(choices=LMS_MODULES_CHOICES),
label="Where are you currently in the programme?"
)
timezone = forms.CharField(
widget=forms.Select(choices=TIMEZONE_CHOICES),
label="Timezone"
)

class Meta:
fields = (
'email', 'password1', 'password2', 'slack_display_name',
'current_lms_module',
'current_lms_module', 'timezone',
)
model = get_user_model()

Expand All @@ -37,6 +41,7 @@ def signup(self, request, user):
user.username = self.cleaned_data['email']
user.slack_display_name = self.cleaned_data['slack_display_name']
user.current_lms_module = self.cleaned_data['current_lms_module']
user.timezone = self.cleaned_data['timezone']
user.save()


Expand All @@ -59,6 +64,10 @@ class EditProfileForm(forms.ModelForm):
)
about = forms.CharField(widget=forms.Textarea(), required=False)
website_url = forms.CharField(required=False)
timezone = forms.CharField(
widget=forms.Select(choices=TIMEZONE_CHOICES),
required=True,
)

class Meta:
model = CustomUser
Expand All @@ -69,6 +78,7 @@ class Meta:
'slack_display_name',
'current_lms_module',
'website_url',
'timezone',
'profile_is_public',
'email_is_public',
)
4 changes: 4 additions & 0 deletions accounts/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
List of user types to be passed into dropdown of same name for each
user selection.
"""
import pytz

USER_TYPES_CHOICES = (
('', 'Select Post Category'),
('participant', 'Participant'),
Expand Down Expand Up @@ -33,3 +35,5 @@
('alumni', 'Alumni'),
('staff', 'Staff'),
)

TIMEZONE_CHOICES = [(tz, tz) for tz in pytz.all_timezones]
18 changes: 18 additions & 0 deletions accounts/migrations/0017_customuser_timezone.py

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db import models
from django.contrib.auth.models import AbstractUser

from .lists import LMS_MODULES_CHOICES
from .lists import LMS_MODULES_CHOICES, TIMEZONE_CHOICES
from teams.lists import LMS_LEVELS


Expand Down Expand Up @@ -97,6 +97,13 @@ class CustomUser(AbstractUser):
"registration link")
)

timezone = models.CharField(
max_length=255,
blank=False,
default='Europe/London',
choices=TIMEZONE_CHOICES,
)

class Meta:
verbose_name = 'User'
verbose_name_plural = 'Users'
Expand Down
2 changes: 2 additions & 0 deletions custom_slack_provider/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def populate_user(self,
email = data.get('email')
profile_image = data.get('profile_image')
about = data.get('about')
timezone = data.get('timezone')
user = sociallogin.user
user_username(user, username or '')
user_email(user, valid_email_or_none(email) or '')
Expand All @@ -57,6 +58,7 @@ def populate_user(self,
user_field(user, 'username', username)
user_field(user, 'profile_image', profile_image)
user_field(user, 'about', about)
user_field(user, 'timezone', timezone)
return user

def is_auto_signup_allowed(self, request, sociallogin):
Expand Down
4 changes: 3 additions & 1 deletion custom_slack_provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def extract_common_fields(self, data):
'slack_display_name': user.get('display_name'),
'email': user.get('email', None),
'profile_image': user.get('image_original'),
'about': user.get('title')}
'about': user.get('title'),
'timezone': user.get('timezone')
}

def get_default_scope(self):
return ['identify']
Expand Down
8 changes: 4 additions & 4 deletions custom_slack_provider/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def complete_login(self, request, app, token, **kwargs):
return self.get_provider().sociallogin_from_response(request,
extra_data)


def get_data(self, token):
# Verify the user first
resp = requests.get(
Expand All @@ -53,7 +52,7 @@ def get_data(self, token):
resp = resp.json()

if not resp.get('ok'):
raise OAuth2Error(f'UserInfo Exception: {user_info.get("error")}')
raise OAuth2Error(f'UserInfo Exception: {resp.get("error")}')

userid = resp.get('user', {}).get('id')
user_info = requests.get(
Expand All @@ -76,15 +75,16 @@ def get_data(self, token):
resp['user']['full_name'] = user_info.get('profile',
{}).get('real_name')
resp['user']['first_name'] = user_info.get('profile',
{}).get('first_name')
{}).get('first_name')
resp['user']['last_name'] = user_info.get('profile',
{}).get('last_name')
# This key is not present in the response if the user has not
# uploaded an image and the field cannot be None
resp['user']['image_original'] = (user_info.get(
'profile', {}).get('image_original') or '')
resp['user']['title'] = user_info.get('profile',
{}).get('title')
{}).get('title')
resp['user']['timezone'] = user_info.get('tz')
return resp


Expand Down
5 changes: 5 additions & 0 deletions profiles/templates/profiles/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
{{ user.human_readable_current_lms_module|title }}
</p>

<label for="latestModule">Timezone</label>
<p id="latestModule">
{{ user.timezone|title }}
</p>

<label for="website">Website</label>
<p id="website" class="profile-website-url">
{% if user.website_url %}
Expand Down
44 changes: 42 additions & 2 deletions static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,41 @@ form.distribute-teams-form, form.clear-teams-form {
border: none;
}

.team-menu-dropdown-container {
position: absolute;
top: 0;
right: 60px;
min-width: 150px;
}

.teams-dropdown {
transform: translate3d(-130px, 38px, 0) !important;
}

.black {
color: var(--black);
}

/* Team Calendar Page */
.table.calendar td {
text-align: center;
}

.table.calendar td.working {
color: #155724;
background-color: #d4edda;
border-color: #c3e6cb;
}

.table.calendar tr:hover {
border: 1px solid var(--black);
font-weight: 600;
}

.table.calendar tr:hover * {
background: var(--bg-grey);
}

/* Ensure teams in paginated view are centered at all times even when odd number of
teams persist in the view. */
.teams-row {
Expand Down Expand Up @@ -623,12 +658,17 @@ form.distribute-teams-form, form.clear-teams-form {
justify-content: center;
}

.dropdown-menu.judge-dropdown {
.dropdown-menu.judge-dropdown, .dropdown-menu.teams-dropdown {
width: 100%;
border: 3px solid var(--p-orange);
}

.dropdown-menu.judge-dropdown .dropdown-item:hover {
.dropdown-menu.teams-dropdown {
width: fit-content;
}

.dropdown-menu.judge-dropdown .dropdown-item:hover,
.dropdown-menu.teams-dropdown .dropdown-item:hover {
width: 100%;
background: var(--p-orange);
color: var(--white);
Expand Down
11 changes: 11 additions & 0 deletions teams/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from copy import deepcopy
from datetime import datetime
import math

import pytz

from .lists import LMS_LEVELS
from accounts.models import CustomUser
from hackathon.models import Hackathon, HackTeam
Expand Down Expand Up @@ -223,3 +226,11 @@ def update_team_participants(created_by_user, teams, hackathon_id):
hackathon = Hackathon.objects.get(id=hackathon_id)
create_new_team_and_add_participants(created_by_user, team_name,
team_members, hackathon)


def calculate_timezone_offset(timezone, timezone_offset):
""" Calculates the timezone offset between a timezone and a known
timezone offset """
tz = pytz.timezone(timezone)
offset = (datetime.now(tz).utcoffset().total_seconds()/60/60)
return offset - timezone_offset
4 changes: 2 additions & 2 deletions teams/templates/includes/create_slack_mpim.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
{% else %}
<form action="/teams/{{team.id}}/create_group_im/" method="POST">
{% csrf_token %}
<button class="btn btn-sm btn-ci">
<i class="fab fa-slack fa-lg ml-0 mr-2 mt-1 mb-1 p-orange"></i>
<button class="dropdown-item">
<i class="fab fa-slack fa-lg ml-0 mr-2 mt-1 mb-1 black"></i>
Create Group IM in Slack
</button>
</form>
Expand Down
17 changes: 16 additions & 1 deletion teams/templates/team.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h2>Team: <i>{{team}}</i>

<div class="row mb-2 mt-5 ml-4">
<div class="col">

<h3>About the team</h3>
{% if request.user in team.participants.all or request.user == team.mentor or request.user.user_type|is_types:authorised_types %}

Expand All @@ -66,7 +67,21 @@ <h3>About the team</h3>
{% endif %}
</p>
{% endif %}
{% include 'includes/create_slack_mpim.html' %}
<div class="team-menu-dropdown-container">
<div class="dropdown mb-2">
<button class="btn btn-ci dropdown-toggle form-control"
type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Team Actions
</button>
<div id="teams-dropdown" class="dropdown-menu teams-dropdown" aria-labelledby="dropdownMenuButton">
{% include 'includes/create_slack_mpim.html' %}
<a role="button" class="dropdown-item" href="{% url 'view_team_calendar' team_id=team.id %}">
<i class="far fa-calendar-alt mr-3"></i> View Team Calendar
</a>
</div>
</div>
</div>

{% if showcase %}
<div class="share-linkedin">
<script src="https://platform.linkedin.com/in.js" type="text/javascript">lang: en_US</script>
Expand Down
Loading