def site_settings(request): SITE_SETTINGS = SiteSetting.as_dict() announcement = SITE_SETTINGS.get(SiteSettingKey.ANNOUNCEMENT) if announcement: messages.info(request, announcement) return { 'SITE_SETTINGS': SITE_SETTINGS, }
def post(self, request): if not SiteSetting.as_dict().get(SiteSettingKey.ENABLE_UPLOADS): return redirect('upload.list') if self.get_upload_slots_used() > request.user.upload_limit: messages.error(request, _('You have reached your limit of {} uploads within the past 24 hours.').format(request.user.upload_limit)) return redirect('upload.list') manga = Manga() manga.save(updated_by=request.user) return redirect('manga.edit.images', id=manga.id, slug=manga.slug)
def get(self, request): if not SiteSetting.as_dict().get(SiteSettingKey.ENABLE_UPLOADS): messages.warning(request, _('Uploading at Fufufuu has been disabled.')) manga_list = Manga.objects.filter(created_by=request.user).order_by('-created_on') manga_list = paginate(manga_list, self.page_size, request.GET.get('p')) upload_slots_used = min(self.get_upload_slots_used(), request.user.upload_limit) return self.render_to_response({ 'manga_list': manga_list, 'upload_slots_used': upload_slots_used, })
def test_site_setting_form_save(self): form = SiteSettingForm(data={ 'announcement': 'This is a sample announcement', 'enable_comments': 'on', }) self.assertTrue(form.is_valid()) form.save(self.user) settings_dict = SiteSetting.as_dict() self.assertEqual(settings_dict.get(SiteSettingKey.ANNOUNCEMENT), 'This is a sample announcement') self.assertEqual(settings_dict.get(SiteSettingKey.ENABLE_COMMENTS), True) self.assertEqual(settings_dict.get(SiteSettingKey.ENABLE_UPLOADS), False)
def post(self, request): if not SiteSetting.as_dict().get(SiteSettingKey.ENABLE_REGISTRATION): return redirect('account.register') form = AccountRegisterForm(data=request.POST) if form.is_valid(): user = form.save() login(request, user) next = request.POST.get('next', reverse('manga.list')) return redirect(next) return self.render_to_response({'form': form})
def initialize_data(self): settings_dict = SiteSetting.as_dict() for k, v in settings_dict.items(): self.fields[k.lower()].initial = v
def get(self, request): if not SiteSetting.as_dict().get(SiteSettingKey.ENABLE_REGISTRATION): messages.warning(request, _('Account registration at Fufufuu has been disabled.')) return self.render_to_response({'form': AccountRegisterForm()})