diff --git a/src/gymkhana/settings.py b/src/gymkhana/settings.py index 30d52986..42e99e6f 100644 --- a/src/gymkhana/settings.py +++ b/src/gymkhana/settings.py @@ -93,6 +93,7 @@ STATICFILES_FINDERS = [ 'django.contrib.staticfiles.finders.FileSystemFinder', 'gymkhana.utils.VueFilesFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', ] STATIC_ROOT = os.path.join(BASE_DIR, config('STATIC_PATH', default='../staticfiles', cast=str)) diff --git a/src/gymkhana/urls.py b/src/gymkhana/urls.py index 85ca21ec..422c0706 100644 --- a/src/gymkhana/urls.py +++ b/src/gymkhana/urls.py @@ -23,7 +23,7 @@ from django.views.decorators.csrf import csrf_exempt from gymkhana.schema import PrivateGraphQLView, PublicGraphQLView -from gymkhana.views import FrontendUpdateView, VueView +from gymkhana.views import FrontendUpdateView, VueView, SocietyArchive from oauth.views import SessionView admin.site.site_title = 'Gymkhana Administration' @@ -36,10 +36,15 @@ url(r'^session/$', SessionView.as_view(), name='session'), url(r'^photologue/', include('photologue.urls', namespace='photologue')), url(r'^admin/', admin.site.urls), + url(r'^ckeditor/', include('ckeditor_uploader.urls')), url(r'^admin/frontend-upload/', user_passes_test(lambda u: u.is_superuser, login_url='admin:login')(FrontendUpdateView.as_view()), name='admin-frontend-upload'), + url(r'^admin/backup/', + user_passes_test(lambda u: u.is_superuser, login_url='admin:login')(SocietyArchive), + name='admin-backup'), path('', include('social_django.urls', namespace='social')), + url(r'^', include('main.urls')), ] urlpatterns += [ diff --git a/src/gymkhana/views.py b/src/gymkhana/views.py index 57dd6481..3152387e 100644 --- a/src/gymkhana/views.py +++ b/src/gymkhana/views.py @@ -9,6 +9,18 @@ from django.core.management import call_command from django.urls import reverse_lazy from django.views.generic import FormView, TemplateView +from main.models import Society, LegacyList +from django.shortcuts import render +from datetime import datetime + + +def SocietyArchive(request): + currentPORs = Society.objects.filter(year=datetime.now().year) + for currentPOR in currentPORs: + backupPOR = LegacyList() + backupPOR.archive(currentPOR) + currentPOR.assignUser() + return render(request, 'backup.html') class UploadForm(forms.Form): @@ -16,10 +28,12 @@ class UploadForm(forms.Form): def process(self): # Delete directory if present, then extract new archive + rmtree(join(settings.VUE_ROOT, 'dist'), ignore_errors=True) with tar_open(fileobj=self.cleaned_data['file'].file, mode='r:gz') as archive: archive.extractall(settings.VUE_ROOT) # Extract index.html to templates dir + archive.extract(archive.getmember('dist/index.html'), settings.TEMPLATES[0]['DIRS'][0]) archive.close() move(join(settings.VUE_ROOT, 'dist/static/js'), join(settings.VUE_ROOT, 'dist/js')) diff --git a/src/main/admin.py b/src/main/admin.py index e48cfe25..c9bba695 100644 --- a/src/main/admin.py +++ b/src/main/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin -from .models import Society, Club, SocialLink, Senate, SenateMembership, Activity, Contact +from .models import Society, Club, SocialLink, Senate, SenateMembership, Activity, Contact, LegacyList, FacultyAdvisor +from oauth.models import UserProfile class MembershipInline(admin.StackedInline): @@ -40,3 +41,6 @@ class ActivityAdmin(admin.ModelAdmin): admin.site.register(Senate, SenateAdmin) admin.site.register(Activity, ActivityAdmin) admin.site.register(main_models) +admin.site.register(LegacyList) +admin.site.register(UserProfile) +admin.site.register(FacultyAdvisor) diff --git a/src/main/models.py b/src/main/models.py index 78e2dd20..38538252 100644 --- a/src/main/models.py +++ b/src/main/models.py @@ -6,6 +6,7 @@ from ckeditor_uploader.fields import RichTextUploadingField from versatileimagefield.fields import VersatileImageField from photologue.models import Gallery +from django.shortcuts import get_object_or_404 YEAR_CHOICES = [] for r in range(2008, (datetime.datetime.now().year + 2)): @@ -69,6 +70,17 @@ def get_absolute_url(self): def __str__(self): return self.name + " - " + str(self.year) + def assignUser(self): + # Model + print('entered assignUser') + self.name = "To be updated" + self.secretary = get_object_or_404(UserProfile, roll='B00XX000') + self.joint_secretary = get_object_or_404(UserProfile, roll='B00XX000') + self.mentor = get_object_or_404(UserProfile, roll='B00XX000') + self.faculty_advisor = get_object_or_404(FacultyAdvisor, name='To be updated') + self.year = '0000' + self.save() + class Club(models.Model): # Choices @@ -262,3 +274,28 @@ def __str__(self): @classmethod def get_absolute_url(cls): return reverse('main:contact') + + +class LegacyList(models.Model): + # Validators + valid_year = RegexValidator(r'^[0-9]{4}$', message='Not a valid year!') + # Model + name = models.CharField(max_length=128) + secretary = models.ForeignKey(UserProfile, related_name='secy+', limit_choices_to={'user__is_staff': True}, + null=True, blank=True, on_delete=models.SET_NULL) + joint_secretary = models.ForeignKey(UserProfile, related_name='joint_secy+', + limit_choices_to={'user__is_staff': True}, null=True, blank=True, + on_delete=models.SET_NULL) + mentor = models.ForeignKey(UserProfile, related_name='smentor+', limit_choices_to={'user__is_staff': True}, + null=True, blank=True, on_delete=models.SET_NULL, default=None) + faculty_advisor = models.ForeignKey(FacultyAdvisor, blank=True, null=True, default=None, on_delete=models.SET_NULL) + year = models.CharField(max_length=4, choices=YEAR_CHOICES, validators=[valid_year]) + + def archive(self, object): + self.year = object.year + self.name = object.name + self.secretary = object.secretary + self.joint_secretary = object.joint_secretary + self.mentor = object.mentor + self.faculty_advisor = object.faculty_advisor + self.save() diff --git a/src/templates/admin/index.html b/src/templates/admin/index.html index 3f0fb3cd..0d1e39a7 100644 --- a/src/templates/admin/index.html +++ b/src/templates/admin/index.html @@ -2,7 +2,7 @@ {% block extrastyle %} {{ block.super }}