diff --git a/apps/member/views.py b/apps/member/views.py index 32b414a5..c214395d 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -186,7 +186,6 @@ class AliasView(LoginRequiredMixin,FormMixin,DetailView): alias = form.save(commit=False) alias.note = self.object.note alias.save() - alias.note.save() print(alias,alias.pk) return super().form_valid(form) @@ -202,7 +201,7 @@ class DeleteAliasView(LoginRequiredMixin, DeleteView): messages.error(self.request,str(e)) else: messages.success(self.request,_("Alias successfully deleted")) - return HttpResponseRedirect(get_success_url) + return HttpResponseRedirect(self.get_success_url()) def get_success_url(self): print(self.request) diff --git a/apps/note/forms.py b/apps/note/forms.py index d920b9aa..2998887b 100644 --- a/apps/note/forms.py +++ b/apps/note/forms.py @@ -12,8 +12,12 @@ class AliasForm(forms.ModelForm): class Meta: model = Alias fields = ("name",) - - + def __init__(self,*args,**kwargs): + super().__init__(*args,**kwargs) + self.fields["name"].label = False + self.fields["name"].widget.attrs={"placeholder":_('New Alias')} + + class TransactionTemplateForm(forms.ModelForm): class Meta: model = TransactionTemplate diff --git a/apps/note/models/notes.py b/apps/note/models/notes.py index 8ee83888..9e3c0a9e 100644 --- a/apps/note/models/notes.py +++ b/apps/note/models/notes.py @@ -227,12 +227,13 @@ class Alias(models.Model): try: sim_alias = Alias.objects.get(normalized_name=normalized_name) if self != sim_alias: - raise ValidationError(_('An alias with a similar name already exists:'), + raise ValidationError(_('An alias with a similar name already exists: {} '.format(sim_alias)), code="same_alias" ) except Alias.DoesNotExist: pass - + self.normalized_name = normalized_name + def delete(self, using=None, keep_parents=False): if self.name == str(self.note): raise ValidationError(_("You can't delete your main alias."), diff --git a/apps/note/tables.py b/apps/note/tables.py index 588c3745..20476cb6 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -32,8 +32,14 @@ class AliasTable(tables.Table): 'table table condensed table-striped table-hover' } model = Alias - fields = ('name','pk') + fields =('name',) template_name = 'django_tables2/bootstrap4.html' - delete = tables.LinkColumn('member:user_alias_delete', args=[A('pk')], attrs={ - 'a': {'class': 'btn btn-danger'} },text='delete',accessor='pk') + show_header = False + name = tables.Column(attrs={'td':{'class':'text-center'}}) + delete = tables.LinkColumn('member:user_alias_delete', + args=[A('pk')], + attrs={ + 'td': {'class':'col-sm-2'}, + 'a': {'class': 'btn btn-danger'} }, + text='delete',accessor='pk') diff --git a/templates/member/user_alias.html b/templates/member/user_alias.html index 4c6834d4..7d932adc 100644 --- a/templates/member/user_alias.html +++ b/templates/member/user_alias.html @@ -47,10 +47,10 @@
-
+ {% csrf_token %} {{ form |crispy }} -