moved the link target pref into a library prefs only table
parent
cdf7b26d70
commit
91e2d41b67
|
@ -8,6 +8,14 @@ from django.db import models
|
|||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Adding model 'Libpref'
|
||||
db.create_table('core_libpref', (
|
||||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
|
||||
('user', self.gf('django.db.models.fields.related.OneToOneField')(related_name='libpref', unique=True, to=orm['auth.User'])),
|
||||
('marc_link_target', self.gf('django.db.models.fields.CharField')(default='UNGLUE', max_length=6)),
|
||||
))
|
||||
db.send_create_signal('core', ['Libpref'])
|
||||
|
||||
# Adding model 'MARCRecord'
|
||||
db.create_table('core_marcrecord', (
|
||||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
|
||||
|
@ -18,19 +26,14 @@ class Migration(SchemaMigration):
|
|||
))
|
||||
db.send_create_signal('core', ['MARCRecord'])
|
||||
|
||||
# Adding field 'UserProfile.marc_link_target'
|
||||
db.add_column('core_userprofile', 'marc_link_target',
|
||||
self.gf('django.db.models.fields.CharField')(default='DIRECT', max_length=6),
|
||||
keep_default=False)
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Deleting model 'Libpref'
|
||||
db.delete_table('core_libpref')
|
||||
|
||||
# Deleting model 'MARCRecord'
|
||||
db.delete_table('core_marcrecord')
|
||||
|
||||
# Deleting field 'UserProfile.marc_link_target'
|
||||
db.delete_column('core_userprofile', 'marc_link_target')
|
||||
|
||||
|
||||
models = {
|
||||
'auth.group': {
|
||||
|
@ -169,6 +172,12 @@ class Migration(SchemaMigration):
|
|||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
|
||||
},
|
||||
'core.libpref': {
|
||||
'Meta': {'object_name': 'Libpref'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'marc_link_target': ('django.db.models.fields.CharField', [], {'default': "'UNGLUE'", 'max_length': '6'}),
|
||||
'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'libpref'", 'unique': 'True', 'to': "orm['auth.User']"})
|
||||
},
|
||||
'core.marcrecord': {
|
||||
'Meta': {'object_name': 'MARCRecord'},
|
||||
'edition': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'MARCrecords'", 'null': 'True', 'to': "orm['core.Edition']"}),
|
||||
|
@ -243,7 +252,6 @@ class Migration(SchemaMigration):
|
|||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'kindle_email': ('django.db.models.fields.EmailField', [], {'max_length': '254', 'blank': 'True'}),
|
||||
'librarything_id': ('django.db.models.fields.CharField', [], {'max_length': '31', 'blank': 'True'}),
|
||||
'marc_link_target': ('django.db.models.fields.CharField', [], {'default': "'DIRECT'", 'max_length': '6'}),
|
||||
'pic_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
|
||||
'tagline': ('django.db.models.fields.CharField', [], {'max_length': '140', 'blank': 'True'}),
|
||||
'twitter_id': ('django.db.models.fields.CharField', [], {'max_length': '15', 'blank': 'True'}),
|
|
@ -1144,6 +1144,15 @@ pledger2.instance=None
|
|||
ANONYMOUS_AVATAR = '/static/images/header/avatar.png'
|
||||
(NO_AVATAR, GRAVATAR, TWITTER, FACEBOOK) = (0, 1, 2, 3)
|
||||
|
||||
class Libpref(models.Model):
|
||||
user = models.OneToOneField(User, related_name='libpref')
|
||||
marc_link_target = models.CharField(
|
||||
max_length=6,
|
||||
default = 'UNGLUE',
|
||||
choices = settings.MARC_CHOICES,
|
||||
verbose_name="MARC record link targets"
|
||||
)
|
||||
|
||||
|
||||
class UserProfile(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
@ -1156,12 +1165,6 @@ class UserProfile(models.Model):
|
|||
librarything_id = models.CharField(max_length=31, blank=True)
|
||||
badges = models.ManyToManyField('Badge', related_name='holders')
|
||||
kindle_email = models.EmailField(max_length=254, blank=True)
|
||||
marc_link_target = models.CharField(
|
||||
max_length=6,
|
||||
default = 'DIRECT',
|
||||
choices = settings.MARC_CHOICES,
|
||||
verbose_name="MARC record link targets"
|
||||
)
|
||||
|
||||
goodreads_user_id = models.CharField(max_length=32, null=True, blank=True)
|
||||
goodreads_user_name = models.CharField(max_length=200, null=True, blank=True)
|
||||
|
|
|
@ -41,6 +41,7 @@ from regluit.core.models import (
|
|||
PledgeExtra,
|
||||
Work,
|
||||
Press,
|
||||
Libpref,
|
||||
TWITTER,
|
||||
FACEBOOK,
|
||||
GRAVATAR
|
||||
|
@ -592,5 +593,5 @@ class MARCUngluifyForm(forms.Form):
|
|||
|
||||
class MARCFormatForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = UserProfile
|
||||
model = Libpref
|
||||
fields = ('marc_link_target',)
|
||||
|
|
|
@ -93,7 +93,7 @@ ul.local li {
|
|||
</form>
|
||||
</div>
|
||||
{% else %}
|
||||
<p>Sorry; we don't have any records meeting your needs at this time. There may be records available if you change your download preferences (below).</p>
|
||||
<p>Sorry; we don't have any records meeting your needs at this time. </p>
|
||||
{% endif %}
|
||||
|
||||
<hr>
|
||||
|
@ -101,7 +101,7 @@ ul.local li {
|
|||
<div>
|
||||
<p>Your preference for the links in the 856 field is:</p>
|
||||
<ul class="local">
|
||||
<li>{{ request.user.profile.get_marc_link_target_display }}</li>
|
||||
<li>{{ libpref.get_marc_link_target_display }}</li>
|
||||
</ul>
|
||||
|
||||
<p>The options are:</p>
|
||||
|
|
|
@ -20,9 +20,10 @@
|
|||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
Back to <a href="{% url marc %}">record download page</a><br /><br />
|
||||
|
||||
Your current MARC record link target preference is:<br />
|
||||
{{ request.user.profile.get_marc_link_target_display }}
|
||||
{{ libpref.get_marc_link_target_display }}
|
||||
<form method="post" action="{% url marc_config %}">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
|
|
|
@ -2611,16 +2611,19 @@ def send_to_kindle_graceful(request, message):
|
|||
)
|
||||
|
||||
def marc(request):
|
||||
link_target = 'UNGLUE'
|
||||
libpref = {'marc_link_target': settings.MARC_CHOICES[1]}
|
||||
try:
|
||||
link_target = request.user.profile.marc_link_target
|
||||
except AttributeError:
|
||||
# set default for anonymous users
|
||||
link_target = 'UNGLUE'
|
||||
libpref = request.user.libpref
|
||||
link_target = libpref.marc_link_target
|
||||
except:
|
||||
if not request.user.is_anonymous():
|
||||
libpref = models.Libpref(user=request.user)
|
||||
records = models.MARCRecord.objects.filter(link_target=link_target)
|
||||
return render(
|
||||
request,
|
||||
'marc.html',
|
||||
{'records': records, 'MARC_CHOICES': settings.MARC_CHOICES}
|
||||
{'records': records, 'MARC_CHOICES': settings.MARC_CHOICES, 'libpref' : libpref }
|
||||
)
|
||||
|
||||
class MARCUngluifyView(FormView):
|
||||
|
@ -2656,9 +2659,12 @@ class MARCConfigView(FormView):
|
|||
|
||||
def form_valid(self, form):
|
||||
marc_link_target = form.cleaned_data['marc_link_target']
|
||||
profile = self.request.user.profile
|
||||
profile.marc_link_target = marc_link_target
|
||||
profile.save()
|
||||
try:
|
||||
libpref = self.request.user.libpref
|
||||
except:
|
||||
libpref = models.Libpref(user=self.request.user)
|
||||
libpref.marc_link_target = marc_link_target
|
||||
libpref.save()
|
||||
messages.success(
|
||||
self.request,
|
||||
"Your preferences have been changed."
|
||||
|
|
Loading…
Reference in New Issue