tum %!s(int64=4) %!d(string=hace) años
padre
commit
a9313dd8ef

+ 17 - 3
app/fruit/forms.py

1
 from django.forms.models import inlineformset_factory, modelform_factory, modelformset_factory
1
 from django.forms.models import inlineformset_factory, modelform_factory, modelformset_factory
2
 from django import forms
2
 from django import forms
3
-from .models import Store, Product, Photo, ProductSKU, Sale, Inbox, Vendor, VendorOrder, VendorProduct
3
+from .models import Store, Product, Photo, ProductSKU, Sale, Inbox, Vendor, VendorOrder, VendorProduct, Profile
4
 from django.forms import ModelForm
4
 from django.forms import ModelForm
5
 from django_google_maps import widgets as map_widgets
5
 from django_google_maps import widgets as map_widgets
6
 from django_google_maps import fields as map_fields
6
 from django_google_maps import fields as map_fields
24
     widgets = GeneralWidgets,
24
     widgets = GeneralWidgets,
25
     )
25
     )
26
 
26
 
27
+
28
+ProfileForm = modelform_factory(
29
+    Profile,
30
+    fields=("bio", "location", "facebook", "line_id", "tel", ),
31
+    widgets = GeneralWidgets,
32
+    )
33
+
34
+UserForm = modelform_factory(
35
+    User,
36
+    fields=("first_name", "last_name"),
37
+    widgets = GeneralWidgets,
38
+    )
39
+
27
 ProductSKUForm = modelform_factory(
40
 ProductSKUForm = modelform_factory(
28
     ProductSKU,
41
     ProductSKU,
29
     fields="__all__",
42
     fields="__all__",
113
 
126
 
114
 
127
 
115
 class SignUpForm(UserCreationForm):
128
 class SignUpForm(UserCreationForm):
116
-    email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')
129
+    #email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')
130
+    roles = forms.ChoiceField(choices = (("seller", "Seller"), ("buyer", "Buyer")))
117
 
131
 
118
     class Meta:
132
     class Meta:
119
         model = User
133
         model = User
120
-        fields = ('username', 'email', 'password1', 'password2', )
134
+        fields = ('username', 'email', 'password1', 'password2', 'roles', )
121
 
135
 
122
 
136
 

+ 18 - 0
app/fruit/migrations/0030_profile_roles.py

1
+# Generated by Django 3.2.6 on 2021-08-16 05:59
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('fruit', '0029_auto_20210815_1415'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AddField(
14
+            model_name='profile',
15
+            name='roles',
16
+            field=models.CharField(choices=[('seller', 'Seller'), ('buyer', 'Buyer')], default='seller', max_length=30),
17
+        ),
18
+    ]

+ 28 - 0
app/fruit/migrations/0031_auto_20210816_1519.py

1
+# Generated by Django 3.2.6 on 2021-08-16 08:19
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('fruit', '0030_profile_roles'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AddField(
14
+            model_name='profile',
15
+            name='facebook',
16
+            field=models.CharField(max_length=200, null=True),
17
+        ),
18
+        migrations.AddField(
19
+            model_name='profile',
20
+            name='line_id',
21
+            field=models.CharField(max_length=100, null=True),
22
+        ),
23
+        migrations.AddField(
24
+            model_name='profile',
25
+            name='tel',
26
+            field=models.CharField(max_length=100, null=True),
27
+        ),
28
+    ]

+ 9 - 0
app/fruit/models.py

279
     user = models.OneToOneField(User, on_delete=models.CASCADE)
279
     user = models.OneToOneField(User, on_delete=models.CASCADE)
280
     bio = models.TextField(max_length=500, blank=True)
280
     bio = models.TextField(max_length=500, blank=True)
281
     location = models.CharField(max_length=30, blank=True)
281
     location = models.CharField(max_length=30, blank=True)
282
+    roles = models.CharField(
283
+        max_length=30,
284
+        choices=(("seller", "Seller"), ("buyer", "Buyer"),),
285
+        default="seller",
286
+    )
287
+    tel = models.CharField(max_length=100, null=True, blank=False)
288
+    line_id = models.CharField(max_length=100, null=True, blank=False)
289
+    facebook = models.CharField(max_length=200, null=True, blank=False)
290
+
282
     birth_date = models.DateField(null=True, blank=True)
291
     birth_date = models.DateField(null=True, blank=True)
283
 
292
 
284
 @receiver(post_save, sender=User)
293
 @receiver(post_save, sender=User)

+ 2 - 1
app/fruit/templates/fruit/mystore.html

18
 <hr> -->
18
 <hr> -->
19
 <div class="d-flex align-items-start">
19
 <div class="d-flex align-items-start">
20
   <div class="nav flex-column nav-pills me-3 col-md-3 col-lg-2" id="v-pills-tab" role="tablist" aria-orientation="vertical">
20
   <div class="nav flex-column nav-pills me-3 col-md-3 col-lg-2" id="v-pills-tab" role="tablist" aria-orientation="vertical">
21
-      <a class="nav-link {{ mystore|yesno:"active," }}" id="v-pills-home-tab"  href="{% url "fruit:mystore" %}" type="button" role="tab" aria-controls="v-pills-home" aria-selected="true">Info</a>
21
+      <a class="nav-link {{ profile|yesno:"active," }}" id="v-pills-profile-tab"  href="{% url "fruit:profile" %}" type="button" role="tab" aria-controls="v-pills-home" aria-selected="true">Profile</a>
22
+      <a class="nav-link {{ mystore|yesno:"active," }}" id="v-pills-home-tab"  href="{% url "fruit:mystore" %}" type="button" role="tab" aria-controls="v-pills-home" aria-selected="true">Store Info</a>
22
       <a class="nav-link {{ product|yesno:"active," }}" id="v-pills-profile-tab"  href="{% url "fruit:product_index" %}" type="button" role="tab" aria-controls="v-pills-profile" aria-selected="false">Products</a>
23
       <a class="nav-link {{ product|yesno:"active," }}" id="v-pills-profile-tab"  href="{% url "fruit:product_index" %}" type="button" role="tab" aria-controls="v-pills-profile" aria-selected="false">Products</a>
23
     <a class="nav-link" id="v-pills-messages-tab" href="{% url "fruit:inbox_index" %}" type="button" role="tab" aria-controls="v-pills-messages" aria-selected="false">Inbox</a>
24
     <a class="nav-link" id="v-pills-messages-tab" href="{% url "fruit:inbox_index" %}" type="button" role="tab" aria-controls="v-pills-messages" aria-selected="false">Inbox</a>
24
     <a class="nav-link {{ sale_active|yesno:"active," }}" id="v-pills-settings-tab" href="{% url "fruit:sale_index" %}"  type="button" role="tab" aria-controls="v-pills-settings" aria-selected="false">Saled Items</a>
25
     <a class="nav-link {{ sale_active|yesno:"active," }}" id="v-pills-settings-tab" href="{% url "fruit:sale_index" %}"  type="button" role="tab" aria-controls="v-pills-settings" aria-selected="false">Saled Items</a>

+ 30 - 0
app/fruit/templates/fruit/profile.html

1
+{% extends "fruit/mystore.html" %}
2
+{% load static %}
3
+{% load crispy_forms_tags %}
4
+
5
+{% block header %}
6
+{{ form1.media }}
7
+{{ form2.media }}
8
+{% endblock %}
9
+
10
+{% block store_main %}
11
+<form  method="post">
12
+    {% csrf_token %}
13
+    <dl>
14
+        <dt>Email:</dt>
15
+        <dd>
16
+            {{ user.email }}</dd>
17
+        <dt>User name:</dt>
18
+        <dd>
19
+            {{ user.username }}</dd>
20
+        <dt>Role</td>
21
+        <dd>
22
+            {{ user.profile.get_roles_display }}</dd>
23
+    </dl>
24
+    {{ form1 | crispy }}
25
+    {{ form2 | crispy }}
26
+    <br>
27
+    <input type='submit' class='btn btn-primary' name='updateProfile' value="Update" />
28
+
29
+</form>
30
+{% endblock %}

+ 1 - 0
app/fruit/urls.py

6
 urlpatterns = [
6
 urlpatterns = [
7
     path('', views.index, name='index'),
7
     path('', views.index, name='index'),
8
     path('mystore', views.mystore, name='mystore'),
8
     path('mystore', views.mystore, name='mystore'),
9
+    path('profile', views.profile, name='profile'),
9
     path('products/create', views.create_product, name='product_create'),
10
     path('products/create', views.create_product, name='product_create'),
10
     path('products/<pk>/sku/create', views.create_sku, name='create_sku'),
11
     path('products/<pk>/sku/create', views.create_sku, name='create_sku'),
11
     path('sku/<pk>', views.edit_sku, name='edit_sku'),
12
     path('sku/<pk>', views.edit_sku, name='edit_sku'),

+ 33 - 2
app/fruit/views.py

2
 from django.shortcuts import render, redirect
2
 from django.shortcuts import render, redirect
3
 # Create your views here.
3
 # Create your views here.
4
 from django.contrib.auth import login, authenticate
4
 from django.contrib.auth import login, authenticate
5
-from django.contrib.auth.forms import UserCreationForm
5
+from django.contrib.auth.forms import UserCreationForm, UserChangeForm
6
 from django.urls import reverse
6
 from django.urls import reverse
7
 from django.contrib.auth.decorators import login_required
7
 from django.contrib.auth.decorators import login_required
8
 
8
 
9
 from fruit.models import Store, Product, Photo, ProductSKU, Sale, Inbox, Vendor, VendorProduct
9
 from fruit.models import Store, Product, Photo, ProductSKU, Sale, Inbox, Vendor, VendorProduct
10
 
10
 
11
-from .forms import StoreForm, ProductForm, InboxForm, SaleForm,  PhotoFormSet,VendorFilter,  InlinePhotoFormset, ProductSKUForm, ProductFilter, SaleFilter, InboxFilter, VendorForm, VendorOrderForm, VendorOrderFilter, VendorOrder, InlineVendorProductFormset, VendorProductForm, SignUpForm
11
+from .forms import StoreForm, ProductForm, InboxForm, SaleForm,  PhotoFormSet,VendorFilter,  InlinePhotoFormset, ProductSKUForm, ProductFilter, SaleFilter, InboxFilter, VendorForm, VendorOrderForm, VendorOrderFilter, VendorOrder, InlineVendorProductFormset, VendorProductForm, SignUpForm, ProfileForm, UserForm
12
 from django.contrib import messages
12
 from django.contrib import messages
13
 from django.core.paginator import Paginator
13
 from django.core.paginator import Paginator
14
 
14
 
486
             user = form.save(commit=False)
486
             user = form.save(commit=False)
487
             user.is_active = False
487
             user.is_active = False
488
             user.save()
488
             user.save()
489
+            user.profile.roles = form.cleaned_data['roles']
490
+            user.profile.save()
489
             current_site = "https://localhost:8000"
491
             current_site = "https://localhost:8000"
490
             subject = 'Activate Your MySite Account'
492
             subject = 'Activate Your MySite Account'
491
             message = render_to_string('fruit/account_activation_email.html', {
493
             message = render_to_string('fruit/account_activation_email.html', {
519
 
521
 
520
 def account_activation_sent(request):
522
 def account_activation_sent(request):
521
     return render(request, "fruit/account_activation_sent.html")
523
     return render(request, "fruit/account_activation_sent.html")
524
+
525
+
526
+@login_required
527
+def profile(request):
528
+    form1 = UserForm(instance = request.user)
529
+    user = request.user
530
+    form2 = ProfileForm(instance = request.user.profile)
531
+    if request.method == "POST":
532
+        form1 = UserForm(request.POST, instance=request.user)
533
+        form2 = ProfileForm(request.POST, instance=request.user.profile)
534
+        if form1.is_valid() and form2.is_valid():
535
+            form1.save()
536
+            form2.save()
537
+            '''
538
+            print(instances)
539
+            for s in instances:
540
+                s.product = instance1
541
+                s.save()
542
+            '''
543
+            messages.success(request, "Profile Save")
544
+            return redirect("fruit:profile")
545
+        else:
546
+            print("Invalid ")
547
+            if form1.errors:
548
+                messages.error(request, form1.errors)
549
+            if form2.errors:
550
+                messages.error(request, form2.errors)
551
+
552
+    return render(request, 'fruit/profile.html', {'form1': form1, 'form2': form2, 'user': user, 'profile': True} )

BIN
app/shaqfindbed/__pycache__/settings.cpython-39.pyc


+ 1 - 1
app/shaqfindbed/settings.py

77
 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
77
 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
78
 EMAIL_HOST = 'smtp.gmail.com'
78
 EMAIL_HOST = 'smtp.gmail.com'
79
 EMAIL_HOST_USER = 'tech@simplico.net'
79
 EMAIL_HOST_USER = 'tech@simplico.net'
80
-EMAIL_HOST_PASSWORD = 'SteveJobs1984'
80
+EMAIL_HOST_PASSWORD = 'Tum 1984 2527'
81
 EMAIL_PORT = 587
81
 EMAIL_PORT = 587
82
 EMAIL_USE_TLS = True
82
 EMAIL_USE_TLS = True
83
 DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
83
 DEFAULT_FROM_EMAIL = EMAIL_HOST_USER