def save_draft(request): d = models.DraftApplication() d.user = request.user form_keys = set(dict(forms.ApplicationForm().fields).keys()) valid_keys = set([field.name for field in models.Application()._meta.get_fields()]) d.save_dict(dict((k, v) for k, v in request.POST.items() if k in valid_keys.intersection(form_keys) and v)) d.save() return JsonResponse({'saved': True})
def get_context_data(self, **kwargs): context = super(HackerDashboard, self).get_context_data(**kwargs) try: draft = models.DraftApplication.objects.get(user=self.request.user) form = forms.ApplicationForm(instance=models.Application(**draft.get_dict())) except: form = forms.ApplicationForm() context.update({'form': form}) try: application = models.Application.objects.get(user=self.request.user) deadline = get_deadline(application) context.update({'invite_timeleft': deadline - timezone.now()}) except: # We ignore this as we are okay if the user has not created an application yet pass return context