Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/brandhomepage #63

Merged
merged 2 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions backend/companies/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.auth import get_user_model


from .models import Brand, BrandRetailerRelation, Retailer, CompanyCode, Note
from .models import Brand, BrandRetailerRelation, Retailer, CompanyCode, Note, ShowRoom

User = get_user_model()
# Register your models here.
Expand Down Expand Up @@ -45,4 +45,11 @@ class BrandRetailerRelationAdmin(admin.ModelAdmin):
class NoteAdmin(admin.ModelAdmin):
list_display = ['company', 'creator','timestamp']
search_fields = ['company', 'creator']
ordering = ['id','timestamp']
ordering = ['id','timestamp']


@admin.register(ShowRoom)
class ShowRoomAdmin(admin.ModelAdmin):
list_display = ['brand', 'address','city','country']
search_fields = ['brand', 'address','city','country']
ordering = ['id']
16 changes: 12 additions & 4 deletions backend/companies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ class BrandRetailerRelation(models.Model):
class ShowRoom(models.Model):
brand = models.ForeignKey(Company, null=False, blank=False, on_delete=models.CASCADE, related_name="showrooms", verbose_name="Brand")

doorcode = models.CharField(max_length=32, null=True, blank=False, verbose_name="Door code")
floor = models.CharField(max_length=10, null=True, blank=False, verbose_name="Floor")
doorcode = models.CharField(max_length=10, null=True, blank=True, verbose_name="Door code")
floor = models.CharField(max_length=10, null=True, blank=True, verbose_name="Floor")

# Location info
address = models.CharField(max_length=100, null=False, blank=False, verbose_name="Address")
Expand All @@ -103,9 +103,17 @@ def __str__(self):

def clean(self):
cleaned_data = super().clean()
errors = {}
if self.brand.get_correct_model().company_type != Brand.company_type:
raise ValidationError("Company is not of type brand")

errors['brand'] = 'Company is not of type brand'
if self.doorcode and not self.doorcode.isnumeric():
errors['doorcode'] = "Door code is not numeric"
if self.date_range_start > self.date_range_end:
errors['date_range_start'] = 'Start date can not be after end date'
if self.hours_start > self.hours_end:
errors['hours_start'] = 'Start time can not be after end time'
if errors:
raise ValidationError(errors)

def is_current(self):
return self.brand.get_correct_model().current_showroom == self
2 changes: 1 addition & 1 deletion backend/companies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def get_object(self, pk):

def get(self, request, pk, format=None):
brand = self.get_object(pk)
serializer = SimpleBrandSerializer(brand) # Does not return the contacts of that company
serializer = BrandSerializer(brand) # Does not return the contacts of that company

appointments = Appointment.objects.filter(retailer__retailer=request.user.company, brands=brand)
appointments = SimpleAppointmentSerializer(appointments, many=True)
Expand Down
3 changes: 2 additions & 1 deletion backend/main/management/commands/myseed.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def populate(self):
seeder.add_entity(companies_models.Brand, 5, {
'name': lambda x: seeder.faker.word(),
})

companies = companies_models.Company.objects.all()

seeder.execute()
Expand All @@ -83,6 +83,7 @@ def populate(self):
random_logo = random.choice(logos)
image_path = (placeholder_logo_path / random_logo).resolve()
company.logo = ImageFile(open(image_path, mode='rb'), name=random_logo)

company.save()
for user in User.objects.all():
# Set random profile picture and company
Expand Down
77 changes: 77 additions & 0 deletions backend/main/management/commands/showroom_seed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# imports
import os
from pathlib import Path
import random
from time import timezone
from django_seed import Seed
from faker import Faker
from PIL import Image

from django.core.files.images import ImageFile
from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model
from django.contrib.auth import models as auth_models

from companies import models as companies_models
from appointments import models as appointments_models
# End: imports -----------------------------------------------------------------

# Settings:

User = get_user_model()


class Command(BaseCommand):

def add_arguments(self, parser):
parser.add_argument(
'--noinput',
'--no-input',
action='store_false',
dest='interactive',
help='Tells Django to NOT prompt the user for input of any kind.',
)

def confirmation(self):
answer = None
yes = ['yes', 'y']
no = ['no', 'n']
print('== This command will:')
print('\t 1. Attempt to seed all models')

print('\n== Are you sure? DOUBLE-CHECK that this is not production server ==')

while answer not in yes + no:
answer = input("Type 'y' or 'n': ").lower()

return answer in yes

def populate(self):
# Use after myseed
fake = Faker()
seeder = Seed.seeder()
seeder.faker.seed_instance()

total_showrooms=len(companies_models.Brand.objects.filter(showrooms=None))
if total_showrooms > 0:
seeder.add_entity(companies_models.ShowRoom, total_showrooms, {
'brand': lambda x: companies_models.Brand.objects.filter(showrooms=None).first()
})

seeder.execute()

for brand in companies_models.Brand.objects.filter(current_showroom=None):
brand.current_showroom = brand.showrooms.first()
brand.save()


def handle(self, *args, **options):

interactive = options['interactive']
if interactive:
if not self.confirmation():
print('== ABORT ==')
return
self.populate()

# End of handle
11 changes: 4 additions & 7 deletions frontend/src/components/AppointmentInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import { StyleSheet, View, TouchableOpacity, Text } from 'react-native'
import { theme } from '../core/theme'
import { transformNiceDate } from '../utils/date_management'
import LocationInfo from './LocationInfo'
import OutlinedButton from './OutlinedButton'
export default function AppointmentInfo({containerStyle, appointment}) {

Expand All @@ -11,16 +12,12 @@ export default function AppointmentInfo({containerStyle, appointment}) {
<Text>{appointment.start_time.slice(0,5)} - {appointment.end_time.slice(0,5)}</Text>
<Text>{transformNiceDate(appointment.date)}</Text>
</View>
{appointment.appointment_type === 'SR' &&
<LocationInfo item={appointment.brands[0].brand.current_showroom}/>
}
<View style={{marginTop:16}}>
<OutlinedButton style={{borderRadius:25, marginVertical:8}} labelStyle={{color:theme.colors.primary}} color={theme.colors.grey} mode="outlined">{appointment.address}</OutlinedButton>
{appointment.appointment_type === 'TR' && <OutlinedButton style={{borderRadius:25, marginVertical:8}} labelStyle={{color:theme.colors.primary}} color={theme.colors.grey} mode="outlined"> Pass </OutlinedButton> }
</View>
{appointment.appointment_type === 'SR' &&
<View style={[styles.row, {marginTop:16, justifyContent:'space-between', paddingHorizontal:32}]}>
<Text>Door Code: 952</Text>
<Text>Floor: Ground</Text>
</View>
}
</View>
)
}
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/components/LocationInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ import { transformNiceDate } from '../utils/date_management'
import OutlinedButton from './OutlinedButton'
export default function LocationInfo({containerStyle, item}) {

if (typeof item !== "undefined") {
return (
<View style={containerStyle}>
{(item.address != null && item.city != null) &&
<View style={{marginTop:16}}>
<OutlinedButton style={{borderRadius:25, marginVertical:8}} labelStyle={{color:theme.colors.primary}} color={theme.colors.grey} mode="outlined">{item.address} {item.city}</OutlinedButton>
</View>
}
<View style={[styles.row, {marginTop:16, justifyContent:'space-between', paddingHorizontal:32}]}>
{(item.doorcode != null && item.doorcode.length > 0) && <Text>Door Code: {item.doorcode}</Text> }
{(item.floor != null && item.floor.length > 0) && <Text>Floor: {item.floor}</Text> }
</View>
</View>
)
)
}
else {
return(<View></View>)
}
}
//TODO add check for door, address and floor
const styles = StyleSheet.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import CompanyLogo from '../../../components/CompanyLogo';
import CurrentUserContext from '../../../../Context';
import BackgroundAuth from '../../../components/BackgroundAuth';
import api from '../../../../api';
import LocationInfo from '../../../components/LocationInfo';


export default function ShowroomScreen({ route, navigation }) {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/screens/company/contact/ContactBrandScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export default function ContactBrandScreen({ route, navigation }) {
useEffect(() => {
api.get(`/companies/brand/${brand_id}/profile/`).then((response) => {
setBrand(response.data.brand)
console.log("-------------------------")
console.log(response.data.brand.current_showroom)
console.log("-------------------------")
setAppointments(response.data.appointments)
}).catch(function (error) {

Expand Down Expand Up @@ -84,7 +87,7 @@ export default function ContactBrandScreen({ route, navigation }) {
</BackHeader>
</View>
<Header style={{textAlign:'center'}}>{brand.name}</Header>
<LocationInfo item={brand}/>
<LocationInfo item={brand.current_showroom}/>
<View style={[styles.row, {marginTop:16}]}>
<OutlinedButton style={{flex:1, marginEnd:6}} labelStyle={{fontSize:14}}>Lookbook</OutlinedButton>
<OutlinedButton style={{flex:1, marginStart:6}} labelStyle={{fontSize:14}}>Line Sheet</OutlinedButton>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/screens/company/contact/NewContactBrand.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default function NewContactBrandScreen({ route, navigation }) {
setSuccessmodal(false);
api.get(`/companies/brand/${brand_id}/profile/`).then((response) => {
setBrand(response.data.brand)
console.log(response.data.brand.current_showroom)
setAppointments(response.data.appointments)
}).catch(function (error) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default function ScheduleContactBrandScreen({ route, navigation }) {
</BackHeader>
</View>
<HeaderWithSub header={brand.name} subheader={'Showroom Appointment'} />
<LocationInfo item={brand}/>
<LocationInfo item={brand.current_showroom}/>
<TeamSelect
containerStyle={{marginVertical:16}}
company={currentUser.company}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,24 @@ export default function SettingsShowroomCreate({ route, navigation }) {
if (error.response) {
// Request made and server responded
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
if (error.response.data.hasOwnProperty("address")) {
setAddress({value:address.value, error:error.response.data.address[0]})
}
if (error.response.data.hasOwnProperty("city")) {
setCity({value:city.value, error:error.response.data.city[0]})
}
if (error.response.data.hasOwnProperty("country")) {
setCountry({value:country.value, error:error.response.data.country[0]})
}
if (error.response.data.hasOwnProperty("doorcode")) {
setDoorCode({value:doorCode.value, error:error.response.data.doorcode[0]})
}
if (error.response.data.hasOwnProperty("start_hours")) {
setStartTime({value:startTime.value, error:error.response.data.start_hours[0]})
}
if (error.response.data.hasOwnProperty("date_range_start")) {
setStartDate({value:startDate.value, error:error.response.data.date_range_start[0]})
}
} else if (error.request) {
// The request was made but no response was received
console.log(error.request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,24 @@ export default function SettingsShowroomEdit({ route, navigation }) {
if (error.response) {
// Request made and server responded
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
if (error.response.data.hasOwnProperty("address")) {
setAddress({value:address.value, error:error.response.data.address[0]})
}
if (error.response.data.hasOwnProperty("city")) {
setCity({value:city.value, error:error.response.data.city[0]})
}
if (error.response.data.hasOwnProperty("country")) {
setCountry({value:country.value, error:error.response.data.country[0]})
}
if (error.response.data.hasOwnProperty("doorcode")) {
setDoorCode({value:doorCode.value, error:error.response.data.doorcode[0]})
}
if (error.response.data.hasOwnProperty("start_hours")) {
setStartTime({value:startTime.value, error:error.response.data.start_hours[0]})
}
if (error.response.data.hasOwnProperty("date_range_start")) {
setStartDate({value:startDate.value, error:error.response.data.date_range_start[0]})
}
} else if (error.request) {
// The request was made but no response was received
console.log(error.request);
Expand Down