Beispiel #1
0
 def create_settings(self):
     settings = (
         (SiteSettingKey.ENABLE_COMMENTS, 'True'),
         (SiteSettingKey.ENABLE_REGISTRATION, 'True'),
         (SiteSettingKey.ENABLE_UPLOADS, 'True'),
     )
     for k, v in settings: SiteSetting.set_val(k, v, self.user)
Beispiel #2
0
    def test_account_register_view_post_invalid(self):
        SiteSetting.set_val(SiteSettingKey.ENABLE_REGISTRATION, 'True', self.user)

        self.client.logout()
        response = self.client.post(reverse('account.register'), {
            'username': '******',
            'password1': '1234',
            'password2': '5678',
        })
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'account/account-register.html')
Beispiel #3
0
 def test_staff_view_post(self):
     announcement = 'This is an important announcement update!'
     response = self.client.post(reverse('staff.site.settings'), {
         'announcement': announcement,
     })
     self.assertRedirects(response, reverse('staff.site.settings'))
     self.assertEqual(SiteSetting.get_val(SiteSettingKey.ANNOUNCEMENT), announcement)
Beispiel #4
0
    def test_account_register_view_post_disabled(self):
        SiteSetting.set_val(SiteSettingKey.ENABLE_REGISTRATION, 'False', self.user)
        challenge, response = settings.get_challenge()()
        store = CaptchaStore.objects.create(challenge=challenge, response=response)

        self.client.logout()
        response = self.client.post(reverse('account.register'), {
            'username': '******',
            'password1': 'password',
            'password2': 'password',
            'next': reverse('tag.list.author'),
            'captcha_0': store.hashkey,
            'captcha_1': store.response,
        })

        self.assertRedirects(response, reverse('account.register'))
Beispiel #5
0
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,
    }
Beispiel #6
0
    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)
Beispiel #7
0
    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,
        })
Beispiel #8
0
    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)
Beispiel #9
0
    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})
Beispiel #10
0
    def test_site_setting_form(self):
        SiteSetting.set_val(SiteSettingKey.ANNOUNCEMENT, 'This is a sample announcement', self.user)
        SiteSetting.set_val(SiteSettingKey.ENABLE_COMMENTS, 'True', self.user)
        SiteSetting.set_val(SiteSettingKey.ENABLE_UPLOADS, 'False', self.user)

        form = SiteSettingForm()
        self.assertEqual(form.fields['announcement'].initial, 'This is a sample announcement')
        self.assertEqual(form.fields['enable_comments'].initial, True)
        self.assertEqual(form.fields['enable_uploads'].initial, False)
Beispiel #11
0
 def test_upload_list_view_post_disabled(self):
     SiteSetting.set_val(SiteSettingKey.ENABLE_UPLOADS, 'False', self.user)
     response = self.client.post(reverse('upload.list'))
     self.assertRedirects(response, reverse('upload.list'))
Beispiel #12
0
 def save(self, user):
     for key in SiteSettingKey.choices_dict.keys():
         self.save_setting(key, user)
     SiteSetting.clear_cache()
Beispiel #13
0
 def save_setting(self, key, user):
     val = self.cleaned_data.get(key.lower())
     SiteSetting.set_val(key, val, user)
Beispiel #14
0
 def initialize_data(self):
     settings_dict = SiteSetting.as_dict()
     for k, v in settings_dict.items():
         self.fields[k.lower()].initial = v
Beispiel #15
0
    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()})