예제 #1
0
class Product(models.Model):
    DELETED = '0'
    AVAILABLE = '1'
    SOLD = '2'

    STATUS_CHOICES = (
        (DELETED, "Deleted"),
        (AVAILABLE, "Available"),
        (SOLD, "Sold"),
    )

    name = models.CharField(max_length=100)
    description = models.TextField()
    price = models.DecimalField(max_digits=10, decimal_places=2)
    location = PlacesField()
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    #seller = models.ForeignKey(User, on_delete=models.CASCADE, related_name="store_owner")
    store = models.ForeignKey(Store, on_delete=models.CASCADE)
    is_draft = models.BooleanField(default=False)
    #stock_on_hand = models.PositiveIntegerField(default=1)
    status = models.CharField(
        max_length=2,
        choices=STATUS_CHOICES,
        default=AVAILABLE,
    )
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.name
예제 #2
0
class RoutePoint(models.Model):
    name = models.CharField(max_length=50)
    location = PlacesField()
    route = models.ForeignKey(Route, on_delete=models.CASCADE)

    def __str__(self):
        return self.name
예제 #3
0
class ResourcePost(models.Model):
    title = models.CharField(max_length=100)
    description = models.TextField()
    quantity = models.PositiveIntegerField(validators=[MinValueValidator(1)])
    dropoff_time_1 = models.DateTimeField(default=timezone.now)
    dropoff_time_2 = models.DateTimeField(blank=True, null=True)
    dropoff_time_3 = models.DateTimeField(blank=True, null=True)
    date_created = models.DateTimeField(default=timezone.now)
    donor = models.ForeignKey(User, on_delete=models.CASCADE)
    dropoff_location = PlacesField(blank=True, null=True)
    resource_category = models.CharField(max_length=100,
                                         choices=RESROUCE_CATEGORY_CHOICES)
    image = models.ImageField(default="donation-pics/default.jpg",
                              upload_to="donation-pics",
                              blank=True)
    status = models.CharField(max_length=100,
                              choices=STATUS_CHOICES,
                              default="AVAILABLE")

    # Dunder (abbr. for Double Under)/Magic str method
    # define how the object is printed
    def __str__(self):
        return self.title

    # Reverse would return the full url as a string and
    # let the view redirect for us
    def get_absolute_url(self):
        # return the path of the specific post
        return reverse("donation:donation-detail", kwargs={"pk": self.pk})

    def save(self, *args, **kwargs):
        if not self.dropoff_location and self.donor.donorprofile.dropoff_location:
            self.dropoff_location = self.donor.donorprofile.dropoff_location
        super().save(*args, **kwargs)
예제 #4
0
class Place(models.Model):
    location = PlacesField(blank=True)

    def __unicode__(self):
        return self.location.place

    def __str__(self):
        return self.__unicode__()
예제 #5
0
class ResourcesRequest(models.Model):
    title = models.CharField(max_length=256)
    description = models.TextField(null=True, blank=False, max_length=1500)
    contact = models.CharField(max_length=256)
    location = PlacesField()
    resolved = models.BooleanField(default=False)
    priority = models.IntegerField(choices=PRIORITY)
    creation_time = models.DateTimeField(auto_now_add=True)
    tags = models.ManyToManyField(CategoryTags)
예제 #6
0
class ResourcesPost(models.Model):
    link = models.URLField(null=True, blank=True)
    last_update_on = models.DateTimeField(default=timezone.now)
    created_on = models.DateTimeField(auto_now_add=True)
    location = PlacesField()
    title = models.CharField(max_length=256, null=True, blank=True)
    description = models.TextField(null=True, blank=True, max_length=1500)
    contacts = models.TextField(null=True, blank=True)
    available = models.BooleanField(default=True)
    tags = models.ManyToManyField(CategoryTags)
예제 #7
0
class DonorProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    dropoff_location = PlacesField(blank=True, null=True)
    donation_count = models.IntegerField(default=0, blank=False)
    complaint_count = models.IntegerField(default=0, blank=False)

    def get_absolute_url(self):
        return reverse("register:donor-profile",
                       kwargs={"username": self.user})

    def __str__(self):
        return "%s" % (self.user)
예제 #8
0
class Venue(models.Model):
    venue_name = models.CharField(max_length=50)
    venue_seat_capacity = models.IntegerField()
    location = PlacesField(blank=True, null=True)
    venue_latitude = models.DecimalField(
        max_digits=9, decimal_places=6, blank=True, null=True)
    venue_longitude = models.DecimalField(
        max_digits=9, decimal_places=6, blank=True, null=True)
    venue_latitude_str = models.CharField(max_length=50, blank=True, null=True)
    venue_longitude_str = models.CharField(
        max_length=50, blank=True, null=True)

    def clean(self):
        self.venue_latitude_str = self.location.latitude
        self.venue_longitude_str = self.location.longitude

    def __unicode__(self):
        return self.venue_name
예제 #9
0
class post(models.Model):
    title = models.CharField(max_length=200, blank=False)
    message = models.TextField()
    location = PlacesField()
    address = models.TextField(blank=True)
    active_post = models.BooleanField(default=True)
    author = models.ForeignKey(settings.AUTH_USER_MODEL,
                               on_delete=models.CASCADE)
    datesub = models.DateTimeField(_('date published'), auto_now_add=True)
    claims = models.ManyToManyField(settings.AUTH_USER_MODEL,
                                    related_name='getclaims',
                                    blank=True)
    reports = models.ManyToManyField(settings.AUTH_USER_MODEL,
                                     related_name='getreports',
                                     blank=True)
    volunteers = models.ManyToManyField(settings.AUTH_USER_MODEL,
                                        related_name='assignvolunteer',
                                        blank=True)
    timelimit = models.DateTimeField(blank=True, null=True)
    datelim = models.DateField(default='2018-11-11')
    timelim = models.TimeField(default='08:34:20')

    def __str__(self):
        return self.title

    @property
    def get_volunteer(self):
        return self.volunteers.all()

    @property
    def get_claims(self):
        return self.claims.all()

    @property
    def get_reports(self):
        return self.reports.all()

    @property
    def is_act(self):
        return self.active_post
예제 #10
0
class Event(models.Model):
    title_text = models.CharField("Event Name", max_length=255)
    # location_text = models.CharField("Location", max_length=100)
    date = models.DateField(default=datetime.date.today)
    time = models.TimeField(default = '14:30',help_text="Enter in 24 hour format (eg - 2:45 or 16:45)")
    category_text = models.CharField("Category", max_length=255,default = 'Uncategorized')
    description_text = models.CharField("Description", max_length=200)
    organizer = models.ForeignKey(User, default = 1, on_delete=models.CASCADE,related_name='organizer')
    location=PlacesField()
    # rsvp= models.ManyToManyField(User, related_name='rsvp', blank=True )
    rsvps = models.ManyToManyField(User, related_name='rsvps') #blank=True )

    def rsvp_total(self):
        return self.rsvps.count()

    def rsvps_list(self):
        return self.rsvps
    def rsvps_list_all(self):
        return self.rsvps.all()
    
    def __str__(self):
        return self.title_text
    """"
예제 #11
0
class MyLocationModel(models.Model):
    location = PlacesField()
예제 #12
0
class MatrimonyProfile(BaseModel):
    """Model representing matrimonial profile of a candidate"""

    profile_id = models.CharField(max_length=15, blank=True, unique=True)
    registration_date = models.DateTimeField(default=timezone.now, blank=True)
    name = models.CharField(
        max_length=200,
        verbose_name=_("Name"),
    )
    spiritual_name = models.CharField(max_length=200,
                                      default="",
                                      blank=True,
                                      verbose_name=_("Spiritual name"))
    contact_person_name = models.CharField(
        max_length=200, verbose_name=_("Contact person name"), default="")
    profile_created_by = models.CharField(max_length=2,
                                          choices=PROFILE_CREATED_BY_CHOICES,
                                          default="SE")
    gender = models.CharField(
        max_length=1,
        choices=GENDER_CHOICES,
    )
    status = models.CharField(max_length=2,
                              choices=PROFILE_STATUS_CHOICES,
                              blank=True,
                              default="00")
    marital_status = models.CharField(
        max_length=3,
        choices=MARITAL_STATUS,
        null=True,
    )
    children_count = models.PositiveIntegerField(choices=CHILDREN_COUNT,
                                                 default=0,
                                                 blank=True,
                                                 null=True)
    ethnic_origin = models.ForeignKey(
        Nationality,
        on_delete=models.SET_NULL,
        null=True,
        related_name="ethnic_origin",
        blank=True,
    )

    photos = models.ManyToManyField("photologue.Photo",
                                    through="Photo",
                                    blank=True)
    photos_visible_to_all_matches = models.BooleanField(
        default=True,
        blank=True,
        null=True,
        help_text=
        "By default, your photos will be visible to all suggested matches. If you uncheck this option, your photos will only be visible to matches you have accepted.",
    )

    # Contact details
    email = models.EmailField(null=True, unique=True, verbose_name=_("Email"))
    phone = models.CharField(max_length=17,
                             unique=True,
                             verbose_name=_("Phone number"))

    # Spiritual details
    rounds_chanting = models.PositiveIntegerField(
        verbose_name=_("Rounds"),
        help_text="How many rounds are you chanting?",
        default=0,
    )
    spiritual_status = models.CharField(
        max_length=2,
        help_text="Enter spiritual status (e.g. Aspiring, Shelter etc.)",
        choices=SPIRITUAL_STATUS_CHOICES,
        verbose_name=_("Spiritual Status"),
        blank=True,
    )
    spiritual_master = models.ForeignKey("Guru",
                                         on_delete=models.SET_NULL,
                                         null=True,
                                         blank=True)

    # Birth details
    dob = models.DateField(
        verbose_name=_("Date of birth"),
        null=True,
    )
    tob = models.TimeField(
        help_text="Enter time HH:MM:SS in 24hr format",
        verbose_name=_("Birth Time"),
        null=True,
        blank=True,
    )
    birth_city = models.CharField(
        max_length=200,
        verbose_name=_("City of birth"),
        help_text="Birth village/town/city (auto populated from map)",
        null=True,
        blank=True,
    )
    birth_state = models.CharField(
        max_length=200,
        verbose_name=_("State of birth"),
        help_text=_("Auto populated from map"),
        null=True,
        blank=True,
    )
    birth_country = models.ForeignKey(
        "Country",
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name="birthCountry",
        verbose_name=_("Country of birth"),
    )
    birth_place = PlacesField(null=True, blank=True)
    gotra = models.ForeignKey(Gotra,
                              on_delete=models.SET_NULL,
                              blank=True,
                              null=True)

    # Current location details
    current_place = PlacesField(null=True, blank=True)
    current_city = models.CharField(
        max_length=200,
        verbose_name=_("City"),
        help_text="Current village/town/city (auto populated from map)",
        null=True,
        blank=True,
    )
    current_state = models.CharField(
        max_length=200,
        verbose_name=_("State"),
        help_text=_("Auto populated from map"),
        null=True,
        blank=True,
    )
    current_country = models.ForeignKey(
        "Country",
        on_delete=models.SET_NULL,
        null=True,
        related_name="currentCountry",
        verbose_name=_("Country"),
        blank=True,
    )
    nationality = models.ForeignKey(
        Nationality,
        on_delete=models.SET_NULL,
        blank=True,
        null=True,
    )

    # Language details
    mother_tongue = models.ForeignKey("Language",
                                      on_delete=models.SET_NULL,
                                      null=True,
                                      blank=True)
    languages_known = models.ManyToManyField(
        "Language",
        help_text="Languages you know",
        related_name="languages_known",
        blank=True,
    )
    languages_read_write = models.ManyToManyField(
        "Language",
        verbose_name="Languages you can read and write",
        related_name="languages_read_write",
        blank=True,
    )

    # Physical appearance
    height = models.DecimalField(
        max_digits=5,
        decimal_places=2,
        help_text="Height in cms",
        null=True,
        blank=True,
    )
    complexion = models.CharField(
        max_length=3,
        help_text="Enter your complexion",
        choices=COMPLEXION_CHOICES,
        null=True,
        blank=True,
    )
    body_type = models.CharField(
        max_length=3,
        choices=BODY_TYPE,
        null=True,
        blank=True,
    )
    weight = models.DecimalField(
        max_digits=5,
        decimal_places=2,
        help_text="Weight in kgs",
        null=True,
        blank=True,
    )
    color_of_eyes = models.CharField(
        max_length=3,
        choices=COLOR_OF_EYES,
        null=True,
        blank=True,
    )
    hair_color = models.CharField(
        max_length=3,
        choices=HAIR_COLOR,
        null=True,
        blank=True,
    )

    # Personality
    personality = models.TextField(max_length=1500,
                                   verbose_name="Describe yourself",
                                   null=True,
                                   blank=True)
    recreational_activities = models.CharField(
        max_length=250,
        verbose_name="List your favorite recreational activities",
        null=True,
        blank=True,
    )
    devotional_services = models.CharField(
        max_length=250,
        verbose_name="List your favorite devotional service",
        null=True,
        blank=True,
    )

    # Professional details
    education = models.ManyToManyField(
        "Education",
        blank=True,
        help_text="HS, Graduate etc.",
    )
    education_details = models.TextField(
        max_length=100,
        null=True,
        verbose_name="Education in Detail",
        blank=True,
    )
    institution = models.CharField(
        max_length=75,
        blank=True,
        null=True,
        verbose_name="College/Institution",
        help_text="Enter College/Institution Name",
    )
    employed_in = models.CharField(
        max_length=3,
        null=True,
        choices=EMPLOYED_IN_CHOICES,
        blank=True,
    )
    occupations = models.ManyToManyField(
        "Occupation",
        blank=True,
        help_text="Doctor, Engineer, Entrepreneur etc.",
    )
    occupation_details = models.TextField(
        max_length=100,
        null=True,
        verbose_name="Occupation in Detail",
        blank=True,
    )
    organization = models.CharField(
        max_length=75,
        null=True,
        help_text="Enter Organization Name",
        blank=True,
    )
    annual_income = MoneyField(max_digits=20,
                               decimal_places=2,
                               null=True,
                               default_currency="INR",
                               blank=True)
    annual_income_in_base_currency = MoneyField(
        max_digits=20,
        decimal_places=2,
        null=True,
        blank=True,
        default_currency="INR",
        verbose_name=_("Annual income in {}".format(settings.BASE_CURRENCY)),
    )

    # Religion/Caste details
    religion = models.ForeignKey(Religion,
                                 on_delete=models.SET_NULL,
                                 null=True,
                                 blank=True)
    caste = models.ForeignKey(Caste,
                              on_delete=models.SET_NULL,
                              null=True,
                              blank=True)
    caste_other = models.CharField(max_length=50,
                                   verbose_name="Other caste",
                                   blank=True,
                                   default="")
    subcaste = models.ForeignKey(Subcaste,
                                 on_delete=models.SET_NULL,
                                 null=True,
                                 blank=True)
    subcaste_other = models.CharField(max_length=50,
                                      verbose_name="Other subcaste",
                                      blank=True,
                                      default="")

    # Family details
    are_parents_devotees = models.CharField(
        max_length=2,
        choices=ARE_PARENTS_DEV,
        null=True,
        blank=True,
        verbose_name="Are your parents devotees?",
    )
    family_values = models.CharField(
        max_length=4,
        choices=FAMILY_VALUE_CHOICES,
        null=True,
        blank=True,
    )
    family_type = models.CharField(
        max_length=3,
        choices=FAMILY_TYPE_CHOICES,
        null=True,
        blank=True,
    )
    family_status = models.CharField(
        max_length=2,
        choices=FAMILY_STATUS_CHOICES,
        null=True,
        blank=True,
    )
    father_status = models.CharField(
        max_length=3,
        choices=FATHER_STATUS_CHOICES,
        null=True,
        blank=True,
    )
    mother_status = models.CharField(
        max_length=3,
        choices=MOTHER_STATUS_CHOICES,
        null=True,
        blank=True,
    )
    brothers = models.PositiveIntegerField(null=True,
                                           blank=True,
                                           verbose_name="No. of Brothers",
                                           default=0)
    sisters = models.PositiveIntegerField(null=True,
                                          blank=True,
                                          verbose_name="No. of Sisters",
                                          default=0)
    brothers_married = models.PositiveIntegerField(null=True,
                                                   blank=True,
                                                   default=0)
    sisters_married = models.PositiveIntegerField(null=True,
                                                  blank=True,
                                                  default=0)
    family_location = models.CharField(
        max_length=10,
        choices=FAMILY_LOCATION_CHOICES,
        null=True,
        blank=True,
    )
    family_origin = models.CharField(
        max_length=50,
        blank=True,
        null=True,
        help_text="Ancestral origin or father's birth place",
        verbose_name="Ancestral/Family Origin",
    )
    religious_background = models.CharField(
        max_length=100,
        blank=True,
        null=True,
        help_text="Religious background of the family",
    )
    family_details = models.TextField(
        max_length=200,
        blank=True,
        null=True,
    )

    # Medical details
    want_children = models.CharField(
        max_length=2,
        choices=Y_N_MAYB,
        verbose_name="Do you want Children",
        null=True,
        blank=True,
    )
    medical_history = models.TextField(max_length=250, null=True, blank=True)

    matches = models.ManyToManyField("self",
                                     through="Match",
                                     blank=True,
                                     symmetrical=False)

    user = models.OneToOneField(
        User,
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name="matrimony_profile",
    )

    # Staff users
    assignee = models.ForeignKey(
        User,
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name="assigned_profiles",
    )
    comments = GenericRelation("Comment")

    @property
    def get_languages_known(self):
        if self.languages_known is not None:
            return ", ".join(p.name for p in self.languages_known.all())
        else:
            return None

    @property
    def get_languages_read_write(self):
        if self.languages_read_write is not None:
            return ", ".join(p.name for p in self.languages_read_write.all())
        else:
            return None

    @property
    def education_text(self):
        return ", ".join([item.name for item in self.education.all()])

    @property
    def occupations_text(self):
        return ", ".join([item.name for item in self.occupations.all()])

    @property
    def primary_image(self):
        primary_img = self.get_primary_image_obj()
        if not primary_img:
            return ""
        return format_html('<img src ="{}" style="width:90px; \
            height: 90px"/>'.format(primary_img.photo.image.url))

    @property
    def primary_image_url(self):
        primary_img = self.get_primary_image_obj()
        if not primary_img:
            return ""
        return primary_img.photo.image.url

    @property
    def primary_image_thumbnail_url(self):
        primary_img = self.get_primary_image_obj()
        if not primary_img:
            return ""
        return primary_img.photo.get_thumbnail_url()

    def get_primary_image_obj(self):
        objs = self.photo_set.filter(primary=True)
        return objs[0] if objs else None

    @property
    def age(self):
        if self.dob:
            return int(
                (datetime.datetime.now().date() - self.dob).days / 365.25)

    @property
    def matches(self):
        return (self.female_matches.all()
                if self.gender == "M" else self.male_matches.all())

    @property
    def matching_profiles(self):
        matches = []
        if self.gender == "M":
            for m in self.female_matches.all():
                matches.append((
                    m.id,
                    m.female,
                    m.show_female_photos,
                    m.female_response,
                    m.male_response,
                ))
        else:
            for m in self.male_matches.all():
                matches.append((
                    m.id,
                    m.male,
                    m.show_male_photos,
                    m.male_response,
                    m.female_response,
                ))
        return matches

    @property
    def mentor(self):
        return self.mentors.all()[0]

    @property
    def expectations(self):
        return self.expectations.all()[0]

    @property
    def matching_profiles_url(self):
        from urllib.parse import urlencode, quote_plus

        querystr = urlencode({
            "q-l": "on",
            "q": self.expectations.djangoql_query_str
        })
        return "{}matrimony/{}/?{}".format(
            reverse("admin:index"), "female" if self.gender == "M" else "male",
            querystr)

    def __str__(self):
        return self.name

    class Meta:
        db_table = "matrimony_profiles"

        ordering = ["-registration_date"]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._original_annual_income = self.annual_income

    def set_status(self, status_text):
        d = {v: k for k, v in PROFILE_STATUS_CHOICES}
        self.status = d.get(status_text)

    def save(self, *args, **kwargs):
        if self.id is None:
            self.profile_id = self.generate_profile_id()
        if self.annual_income and (
                self.id is None
                or self._original_annual_income != self.annual_income):
            self.annual_income_in_base_currency = convert_money(
                self.annual_income, settings.BASE_CURRENCY)

        super().save(*args, **kwargs)
        _, created = MatrimonyProfileStats.objects.get_or_create(profile=self)
        _, created = Expectation.objects.get_or_create(profile=self)

    def send_batch_matches_email(self):
        body = self.get_batch_matches_email_body()
        subject = _("Matches for you")
        mail.send(
            self.email,
            subject=_("Suggested matches"),
            html_message=body,
            headers={"Reply-to": settings.EMAIL_CONTACT},
        )

    def get_batch_matches_email_body(self):
        return loader.get_template("matrimony/emails/matches.html").render(
            {"matches": self.matching_profiles})

    def generate_profile_id(self):
        digest = (md5(
            f"{self.name}-{self.gender}-{self.phone}-{self.email}-{self.dob}-{self.phone}"
            .encode("utf-8")).hexdigest()[:7].upper())
        return f"{settings.PROFILE_ID_PREFIX}{digest}"

    def update_stats(self):
        _, created = MatrimonyProfileStats.objects.get_or_create(profile=self)
        matches_suggested = (
            matches_accepted
        ) = matches_rejected = matches_accepted_by = matches_rejected_by = 0
        self_response_field_name = ("male_response" if self.gender == "M" else
                                    "female_response")
        response_field_name = ("female_response"
                               if self.gender == "M" else "male_response")
        for m in self.matches:
            matches_suggested += 1
            matches_accepted += (1 if getattr(m, self_response_field_name)
                                 == "ACP" else 0)
            matches_rejected += (1 if getattr(m, self_response_field_name)
                                 == "REJ" else 0)
            matches_accepted_by += 1 if getattr(
                m, response_field_name) == "ACP" else 0
            matches_rejected_by += 1 if getattr(
                m, response_field_name) == "REJ" else 0
        self.stats.matches_suggested = matches_suggested
        self.stats.matches_accepted = matches_accepted
        self.stats.matches_rejected = matches_rejected
        self.stats.matches_accepted_by = matches_accepted_by
        self.stats.matches_rejected_by = matches_rejected_by
        self.stats.save()

    def create_user(self):
        user, created = User.objects.get_or_create(
            username=self.email,
            email=self.email,
            is_matrimony_candidate=True,
        )
        if created:
            self.user = user
            self.save()
            self.send_profile_import_email()
            user.send_confirmation_email()

        if self.name != user.name:
            user.name = self.name
            user.save()

        return user

    def send_profile_import_email(self):
        site = Site.objects.get_current()
        msg = loader.get_template(
            "matrimony/emails/profile_import.txt").render({
                "current_site":
                site,
                "password_reset_link":
                build_absolute_url(reverse("account_reset_password")),
                "contact_email":
                settings.EMAIL_CONTACT,
            })
        mail.send(
            self.email,
            subject=_("Matrimony profile created"),
            html_message=msg,
            headers={"Reply-to": settings.EMAIL_CONTACT},
        )
예제 #13
0
class Area(models.Model):
    location = PlacesField()