diff --git a/codershq/challenge/admin.py b/codershq/challenge/admin.py index 5ac8d0be..bcee2f1c 100644 --- a/codershq/challenge/admin.py +++ b/codershq/challenge/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin - +from django.http import HttpResponse from codershq.challenge.models import Challenge admin.site.register(Challenge) diff --git a/codershq/challenge/models.py b/codershq/challenge/models.py index 93682d92..06a9db59 100644 --- a/codershq/challenge/models.py +++ b/codershq/challenge/models.py @@ -7,7 +7,6 @@ from codershq.users.models import User - class Challenge(models.Model): """Main challenge model""" diff --git a/codershq/dashboard/models.py b/codershq/dashboard/models.py new file mode 100644 index 00000000..e69de29b diff --git a/codershq/portfolio/admin.py b/codershq/portfolio/admin.py index 846f6b40..e69de29b 100644 --- a/codershq/portfolio/admin.py +++ b/codershq/portfolio/admin.py @@ -1 +0,0 @@ -# Register your models here. diff --git a/codershq/portfolio/models.py b/codershq/portfolio/models.py index 6b202199..e69de29b 100644 --- a/codershq/portfolio/models.py +++ b/codershq/portfolio/models.py @@ -1 +0,0 @@ -# Create your models here. diff --git a/codershq/static/images/favicon.svg b/codershq/static/images/favicon.svg index 25180256..b022ddb9 100644 --- a/codershq/static/images/favicon.svg +++ b/codershq/static/images/favicon.svg @@ -1 +1 @@ - + \ No newline at end of file diff --git a/codershq/users/admin.py b/codershq/users/admin.py index be60fdcf..5e38bd4d 100644 --- a/codershq/users/admin.py +++ b/codershq/users/admin.py @@ -1,16 +1,18 @@ +from os import path from django.contrib import admin from django.contrib.auth import admin as auth_admin from django.contrib.auth import get_user_model from django.utils.translation import gettext_lazy as _ - +from django.http import HttpResponse from codershq.users.forms import UserChangeForm, UserCreationForm +import csv User = get_user_model() - @admin.register(User) class UserAdmin(auth_admin.UserAdmin): + actions = ['export', ] form = UserChangeForm add_form = UserCreationForm fieldsets = ( @@ -33,3 +35,30 @@ class UserAdmin(auth_admin.UserAdmin): ) list_display = ["username", "name", "is_superuser"] search_fields = ["name"] + + + def export(self,request,queryset): + meta = self.model._meta + + # field names to be exported + # use [field.name for field in meta.fields] to import all the data of specific user + # here it only uploads the name and email + fieldnames = ["username","email"] + + response = HttpResponse(content_type='text/csv') + + # name of the file + response['Content-Disposition'] = 'attachment; filename="UsersData.csv"' + + # initialize the writer to write the responses in csv + writer = csv.writer(response) + + writer.writerow(fieldnames) #heading in csv files + + # write each data in the csv file + for obj in queryset: + row = writer.writerow([getattr(obj, field) for field in fieldnames]) + + return response + # short description of the of action name + export.short_description ="Export to csv" diff --git a/codershq/users/models.py b/codershq/users/models.py index 6775d155..e8112e1a 100644 --- a/codershq/users/models.py +++ b/codershq/users/models.py @@ -92,3 +92,4 @@ class UserTrophyType(models.Model): class UserTrophyRecord(models.Model): trophy_type = models.ForeignKey(UserTrophyType, on_delete=models.PROTECT) user = models.ForeignKey(User, on_delete=models.CASCADE) + diff --git a/compose/local/django/tempCodeRunnerFile.shellscript b/compose/local/django/tempCodeRunnerFile.shellscript new file mode 100644 index 00000000..0a6d64fd --- /dev/null +++ b/compose/local/django/tempCodeRunnerFile.shellscript @@ -0,0 +1 @@ +python manage.py runserver_plus 0.0.0.0:8000 \ No newline at end of file diff --git a/config/settings/base.py b/config/settings/base.py index 486cc4b8..249e56cd 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -4,6 +4,8 @@ from pathlib import Path import environ +import os + ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent.parent # codershq/ @@ -178,7 +180,7 @@ # https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND "BACKEND": "django.template.backends.django.DjangoTemplates", # https://docs.djangoproject.com/en/dev/ref/settings/#dirs - "DIRS": [str(APPS_DIR / "templates")], + "DIRS": [str(APPS_DIR / "templates"),], #os.path.join(APPS_DIR, "users/templates"),], # https://docs.djangoproject.com/en/dev/ref/settings/#app-dirs "APP_DIRS": False, "OPTIONS": { diff --git a/config/settings/local.py b/config/settings/local.py index 8484f911..5ffef4a5 100644 --- a/config/settings/local.py +++ b/config/settings/local.py @@ -11,7 +11,7 @@ default="LOXGprvKQt8D1LFcAHxTpeUNpvFQwXcEfbBpAaxqYXXaWbRsCY98415cwiQOJOAm", ) # https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts -ALLOWED_HOSTS = ["*"] +ALLOWED_HOSTS = ['localhost', '127.0.0.1', '[::1]'] GITHUB_TOKEN = env.str("GITHUB_TOKEN", "") # CACHES