diff --git a/core/models.py b/core/models.py index 5bf95ff4..4d93ade1 100755 --- a/core/models.py +++ b/core/models.py @@ -1159,7 +1159,8 @@ class UserProfile(models.Model): marc_format = models.CharField( max_length=6, default = 'DIRECT', - choices = settings.MARC_CHOICES + choices = settings.MARC_CHOICES, + verbose_name="MARC record link targets" ) goodreads_user_id = models.CharField(max_length=32, null=True, blank=True) @@ -1170,7 +1171,7 @@ class UserProfile(models.Model): avatar_source = models.PositiveSmallIntegerField(null = True, default = GRAVATAR, choices=((NO_AVATAR,'No Avatar, Please'),(GRAVATAR,'Gravatar'),(TWITTER,'Twitter'),(FACEBOOK,'Facebook'))) - + def __unicode__(self): return self.user.username diff --git a/frontend/forms.py b/frontend/forms.py index 60dd926d..942974be 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -588,4 +588,9 @@ class MARCUngluifyForm(forms.Form): break if not ebooks: raise forms.ValidationError('Please add at least one unglued ebook link to THIS EDITION through the work or admin page before creating a MARC record.') - return self.cleaned_data \ No newline at end of file + return self.cleaned_data + +class MARCFormatForm(forms.ModelForm): + class Meta: + model = UserProfile + fields = ('marc_format',) diff --git a/frontend/templates/email_change/base.html b/frontend/templates/email_change/base.html index 5d2bfffd..e2112ec4 100644 --- a/frontend/templates/email_change/base.html +++ b/frontend/templates/email_change/base.html @@ -12,7 +12,7 @@
  • ... or manage your pledges and payment info?
  • ... or change your username?
  • ... or manage your contact preferences?
  • -
  • ... or add or change a Send-to-Kindle email??
  • +
  • ... or add or change a Send-to-Kindle email?
  • {% endblock %} \ No newline at end of file diff --git a/frontend/templates/manage_account.html b/frontend/templates/manage_account.html index 3cf1e2f0..3c2d7838 100644 --- a/frontend/templates/manage_account.html +++ b/frontend/templates/manage_account.html @@ -109,7 +109,8 @@ $j(document).ready(function(){
  • Want to change your password?
  • ... or manage your contact preferences?
  • ... or change your email address?
  • -
  • ... or change your username ?
  • +
  • ... or change your username?
  • +
  • ... or change your MARC record preferences?
  • ... or add or change a Send-to-Kindle email?
  • {% endblock %} diff --git a/frontend/templates/marc_config.html b/frontend/templates/marc_config.html new file mode 100644 index 00000000..b7eba4fa --- /dev/null +++ b/frontend/templates/marc_config.html @@ -0,0 +1,32 @@ +{% extends "email_change/base.html" %} + +{% block extra_extra_head %} +{{ block.super }} + +{% endblock %} + +{% block title %}Change your MARC record preferences{% endblock %} + +{% block ce_content %} +{% if messages %} + +{% endif %} + +Your current MARC record link target preference is:
    +{{ request.user.profile.get_marc_format_display }} +
    + {% csrf_token %} + {{ form }} +
    + +
    +{% endblock %} \ No newline at end of file diff --git a/frontend/urls.py b/frontend/urls.py index 2319e301..eb1e56bb 100644 --- a/frontend/urls.py +++ b/frontend/urls.py @@ -34,7 +34,8 @@ from regluit.frontend.views import ( kindle_config, send_to_kindle, send_to_kindle_graceful, - MARCUngluifyView + MARCUngluifyView, + MARCConfigView ) urlpatterns = patterns( @@ -134,6 +135,7 @@ urlpatterns = patterns( url(r"^send_to_kindle/result/(?P\d)/$", "send_to_kindle_graceful", name="send_to_kindle_graceful"), url(r"^marc/$", "marc", name="marc"), url(r"^marc/ungluify/$", login_required(MARCUngluifyView.as_view()), name="MARCUngluify"), + url(r"^accounts/edit/marc_config/$", login_required(MARCConfigView.as_view()), name="marc_config"), ) if settings.DEBUG: diff --git a/frontend/views.py b/frontend/views.py index 31aead83..cf8292d1 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -104,7 +104,8 @@ from regluit.frontend.forms import ( AuthForm, PressForm, KindleEmailForm, - MARCUngluifyForm + MARCUngluifyForm, + MARCFormatForm ) from regluit.payment import baseprocessor, stripelib @@ -2640,4 +2641,24 @@ class MARCUngluifyView(FormView): self.request, "Sorry, couldn't parse that file." ) - return super(MARCUngluifyView,self).form_valid(form) \ No newline at end of file + return super(MARCUngluifyView,self).form_valid(form) + +class MARCConfigView(FormView): + template_name = 'marc_config.html' + form_class = MARCFormatForm + success_url = reverse_lazy('marc') + + def form_valid(self, form): + marc_format = form.cleaned_data['marc_format'] + profile = self.request.user.profile + profile.marc_format = marc_format + profile.save() + messages.success( + self.request, + "Your preferences have been changed." + ) + if reverse('marc_config', args=[]) in self.request.META['HTTP_REFERER']: + return HttpResponseRedirect(reverse('marc_config', args=[])) + else: + return super(MARCConfigView, self).form_valid(form) +