-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #400 from alllexxx1/feature_branch
[#392] Add settings section for a user
- Loading branch information
Showing
13 changed files
with
543 additions
and
411 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
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,19 @@ | ||
# Generated by Django 4.2.11 on 2024-03-20 21:07 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("custom_auth", "0005_alter_siteuser_groups"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="siteuser", | ||
name="github_token", | ||
field=models.CharField( | ||
blank=True, max_length=100, null=True, verbose_name="GitHub token" | ||
), | ||
), | ||
] |
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
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
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 |
---|---|---|
|
@@ -21,5 +21,6 @@ | |
pull_requests, | ||
repositories, | ||
repository, | ||
user_settings, | ||
webhook, | ||
) |
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
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,52 @@ | ||
from django.contrib import messages | ||
from django.shortcuts import redirect | ||
from django.urls import reverse_lazy | ||
from django.utils.translation import gettext_lazy as _ | ||
from django.views.generic import TemplateView | ||
|
||
from auth.forms import UserTokenForm | ||
from contributors.views.mixins import ( | ||
AuthRequiredMixin, | ||
PermissionRequiredMixin, | ||
) | ||
|
||
|
||
class ChangeTokenView( | ||
AuthRequiredMixin, | ||
PermissionRequiredMixin, | ||
TemplateView, | ||
): | ||
"""Changing user git_hub token page view.""" | ||
|
||
template_name = 'user_settings.html' | ||
not_auth_msg = _('Please log in with your GitHub') | ||
no_permission_msg = ( | ||
_("You haven't got permission to access this section") | ||
) | ||
redirect_url = reverse_lazy('contributors:home') | ||
|
||
def get_context_data(self, **kwargs): | ||
"""Add additional context for the settings.""" | ||
context = super().get_context_data(**kwargs) | ||
context['user'] = self.request.user | ||
return context | ||
|
||
def post(self, request, *args, **kwargs): | ||
"""Handle form submission.""" | ||
form = UserTokenForm(request.POST) | ||
if form.is_valid(): | ||
user = request.user | ||
github_token = form.cleaned_data['github_token'] | ||
user.github_token = github_token | ||
user.save() | ||
messages.success(request, _('GitHub token changed successfully')) | ||
return redirect(reverse_lazy( | ||
'contributors:user_settings', | ||
kwargs={'slug': kwargs.get('slug')}, | ||
)) | ||
|
||
messages.error(request, _('An error occurred. Please try again')) | ||
return redirect(reverse_lazy( | ||
'contributors:user_settings', | ||
kwargs={'slug': kwargs.get('slug')}, | ||
)) |
Binary file not shown.
Oops, something went wrong.