Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature - society archives #75

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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 src/gymkhana/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 6 additions & 1 deletion src/gymkhana/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 += [
Expand Down
14 changes: 14 additions & 0 deletions src/gymkhana/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,31 @@
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):
file = forms.FileField()

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'))
Expand Down
6 changes: 5 additions & 1 deletion src/main/admin.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
37 changes: 37 additions & 0 deletions src/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
3 changes: 2 additions & 1 deletion src/templates/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% block extrastyle %}
{{ block.super }}
<style>
a.upload-button {
.upload-button {
background-color: #79AEC8; /* Green */
border: none;
color: white;
Expand All @@ -19,5 +19,6 @@
{{ block.super }}
{% if request.user.is_superuser %}
<a class="upload-button" href="{% url 'admin-frontend-upload' %}">Frontend Update</a>
<a class="upload-button" href="{% url 'admin-backup' %}">Backup</a>
{% endif %}
{% endblock %}
6 changes: 6 additions & 0 deletions src/templates/backup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends 'admin/base_site.html' %}

{% block content %}
<p><b>Current Society Database has been archived.</b></p>
{% endblock %}